money fixed margin
Info
The money fixed margin is a Expert Advisor for MetaTrader 5 that an example for calculating the lot value with a fixed margin level. that is, if you specify 10%, a position with the margin equal to 10% of free margin will be opened.
Usage
This tool is typically used for automated trading on major forex pairs and gold.
Platform
This Expert Advisor works exclusively on MetaTrader 5 (both build 600+ and newer versions).
Setup
Place the downloaded file in MQL5/Experts folder via File ? Open Data Folder in MetaTrader 5.
How to Install and Use money fixed margin
1. Installation: Open the "File" menu, select "Open Data Folder," navigate to MQL/Experts, paste your file, and restart the terminal.
2. Activation: Drag the EA from the Navigator onto a chart, ensure "Allow live trading" is checked in the Common tab, and verify the AutoTrading button is green.
3. Optimization: Right-click your chart, choose "Expert List," click "Properties" to adjust inputs, and save your preferred setup as a set file for future use.
4. Maintenance: Regularly check the "Experts" tab in the terminal window to monitor trade logs and potential execution errors.
Frequently Asked Questions
Q: Why is my EA not opening trades? A: Check the "AutoTrading" button, ensure "Allow live trading" is enabled, and verify your broker allows automated trading on your account type.
Q: Can I run multiple EAs on one chart? A: No, each chart can only host one active EA; however, you can open multiple charts for different currency pairs to run several EAs.
Q: What does the "smiley face" icon mean? A: A smiley face in the top-right corner of the chart indicates the EA is successfully running; a frowny face means it is disabled.
What this tool does
an example for calculating the lot value with a fixed margin level.
Typical Use Case
This Expert Advisor excels in automated trading and technical analysis on MetaTrader 5.
Compatible Platform & Setup
This Expert Advisor works on MetaTrader 5. Place the file in the MQL5/Experts folder and restart the terminal.
Description & Settings
Related: EA Money Management Strategy - another powerful expert for MetaTrader 5 traders.
an example for calculating the lot value with a fixed margin level. that is, if you specify 10%, a position with the margin equal to 10% of free margin will be opened.
Also recommended: money fixed risk - similar expert with strong performance on MetaTrader 5.
input parameters:stoploss (in pips) — the stop loss level
% risk — margin for a position as % of free margin
the following loop is implemented to simulate trading:
initial value count=-21 is set to "warm up" the strategy tester. then the remainder after devision of count by 980 (this number was chosen randomly) is calculated. it means that every 980 ticks lot calculation cycle is started, in which lot is calculated taking into account the risks per trade.
the lot calculation cycle depending on risk per trade (calculation for the buy position):
step one //--- getting lot size for open long position (cmoneyfixedmargin) double sl=0.0; double check_open_long_lot=0.0; //--- variant #1: stoploss=0.0 sl=0.0; check_open_long_lot=m_money.checkopenlong(m_symbol.ask(),sl); print("sl=0.0", ", checkopenlong: ",doubletostring(check_open_long_lot,2), ", balance: ", doubletostring(m_account.balance(),2), ", equity: ", doubletostring(m_account.equity(),2), ", freemargin: ", doubletostring(m_account.freemargin(),2)); //--- variant #2: stoploss!=0.0 sl=m_symbol.bid()-extstoploss; check_open_long_lot=m_money.checkopenlong(m_symbol.ask(),sl); print("sl=",doubletostring(sl,m_symbol.digits()), ", checkopenlong: ",doubletostring(check_open_long_lot,2), ", balance: ", doubletostring(m_account.balance(),2), ", equity: ", doubletostring(m_account.equity(),2), ", freemargin: ", doubletostring(m_account.freemargin(),2)); if(check_open_long_lot==0.0) return;
then the calculated lot value for a buy position taking into account stoploss is received to the check_open_long_lot variable using the method of the class:
double check_open_long_lot=m_money.checkopenlong(m_symbol.ask(),m_symbol.bid()-extstoploss);
the following parameters are printed to the experts journal: stoploss, calculated lot value in accordance with the risk per trade, trade account balance at the time of calculation, margin at the moment of calculation.
if the calculation returns "0.0", exit:
if(check_open_long_lot==0.0) return;
step two
then we receive the lot value of the buy position for which we have sufficient funds; the value is received to the chek_volime_lot variable using the checkvolume method of the class. the following parameters are passed here: m_symbol.name() — symbol name, check_open_long_lot — position volume we want to open (this parameter was calculated earlier):
//--- check volume before ordersend to avoid "not enough money" error (ctrade) double chek_volime_lot=m_trade.checkvolume(m_symbol.name(),check_open_long_lot,m_symbol.ask(),order_type_buy);
step three
if the checkvolume method returns a value other than "0.0", then we check the condition: do we have enough money to open a position with the lot calculated in accordance with the risk.
if(chek_volime_lot!=0.0) if(chek_volime_lot>=check_open_long_lot) m_trade.buy(chek_volime_lot,null,m_symbol.ask(),m_symbol.bid()-extstoploss,m_symbol.bid()+extstoploss); else print("cmoneyfixedrisk lot = ",doubletostring(check_open_long_lot,2), ", ctrade lot = ",doubletostring(chek_volime_lot,2));
if we have enough money, open the position, if not — the lot value calculated in accordance with the risk per trade (doubletostring(check_open_long_lot,2)) and the lot value for wich we have enough funds (doubletostring(chek_volime_lot,2)) are printed to the experts journal.
an example of opening a buy position with 10% of free margin:
the following was printed to journal:
money fixed margin (eurusd,m1) 2016.11.28 00:03:24 sl=0.0, checkopenlong: 0.28, balance: 3000.00, equity: 3000.00, freemargin: 3000.00money fixed margin (eurusd,m1) 2016.11.28 00:03:24 sl=1.05792, checkopenlong: 0.28, balance: 3000.00, equity: 3000.00, freemargin: 3000.00trade 2016.11.28 00:03:31 instant buy 0.28 eurusd at 1.06076 sl: 1.05792 tp: 1.06292 (1.06042 / 1.06076 / 1.06042)trades 2016.11.28 00:03:31 deal #2 buy 0.28 eurusd at 1.06076 done (based on order #2)trade 2016.11.28 00:03:31 deal performed [#2 buy 0.28 eurusd at 1.06076]trade 2016.11.28 00:03:31 order performed buy 0.28 at 1.06076 [#2 buy 0.28 eurusd at 1.06076]money fixed margin (eurusd,m1) 2016.11.28 00:03:31 ctrade::ordersend: instant buy 0.28 eurusd at 1.06076 sl: 1.05792 tp: 1.06292 [done at 1.06076]
note that when calculating the lot depending on the risk of free margin, stoploss does not matter.
You may also like: money rain - excellent alternative for expert users on MetaTrader 5.
Source Code
/
.......
⚠ Limitations & Risk Warning
- This tool is provided for educational and testing purposes only.
- Past performance does not guarantee future results.
- Trading involves substantial risk of loss. Use on a demo account first.
- Results may vary depending on market conditions, broker, and settings.
- We recommend thorough backtesting and forward testing before using with real funds.