Currency Fixed Margin - MetaTrader 5 Expert | MT5 EA Download - MetaTrader 5 Resources

Example of calculating lot size with fixed margin level. That is, if you specify 10%, the position will be opened with a margin equal to 10% of the available margin.
Input parameters:
Implement the following loop to simulate trading:
Initial value count = - 21 is set to "warm up" the strategy tester. Then the remainder after division is calculated through 980 (this number is randomly selected). This means that every 980 pips the lot calculation period starts where the lot calculation takes into account the risk of each trade.
The lot calculation period depends on the risk of each trade (calculation of buy positions):
Then, the calculated lot size of the long position (taking into account the stop loss) will be received to check the open long position variable using the method of checking the open long position CMoney fixed margin class:
The following parameters will be printed to the expert's log: stop loss, lot size calculated based on risk per trade, trading account balance at the time of calculation, margin at the time of calculation.
If the calculation returns "0.0", exit:
Then we receive the lot size of the long position for which we have sufficient funds; this value is received into the chek_volime_lot variable of the TradeNet class using the CheckVolume method. The following parameters are passed here: m_symbol.Name() — symbol name, check open long lot size — the amount of the position we want to open (this parameter was calculated before):
If the value returned by the CheckVolume method is not "0.0", then we check the condition: whether we have enough funds to open the position, the lot size is calculated according to the risk.
If we have sufficient funds, a position is opened, if not - the lot value calculated based on the risk of each trade ( double to string (check_volime_lot, 2 ) ) and the lot value for which we have sufficient funds ( double to string (chek_volime_lot, 2 ) ) are printed to the expert journal.
Example of opening a buy position with 10% available margin:

The following is printed to the journal:
Please note that stop loss is not important when calculating lot size based on available margin risk.
Attachment download
📎 money_fixed_margin.mq5 (10.22 KB)
Source: MQL5 #17282
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •