How to Calculate Risk per Trade in MQL5


I want to calculate my risk per trade relative to account balance (for example only risk 2% of balance per trade). Of course the stop loss is relative, lets imagine the Stop Loss variable will be changing and will use ATR for calculation.

I have the expert ready but I need help with this code.

So far, I have found 2 ways (but I don’t know how to use it).

  1. This link have a code that seems correct, bu I’m not sure how to call the function an use it on my robot. . I already saved in the include folder and use the #include. Also called the function GetLotSize(lotsize) but says "incorrect parameters).

( )

  1. I know there is a .mqh file in include/experts/money/MoneyFixedRisk.mqh, this seems to do the calculation bu I’m not sure how to use it.

If you have other idea on how to calculate this for MQL5 or know how to use this codes, please let me know, it’s killing me at the moment.

I use dynamic lots size , based on how much pips want to risk.

lot size = ammount ballance to risk / pips to risk

I’m not sure what you mean. But my Stop Loss is dinamic also, it changes depending on the ATR and a factor. So it changes, but not so much. For example on one trade can be 50 pips and the next 65 and 15 trades from that one maybe 90 pips. Because is changes in the pips, and also each pip have a different cost if for example use one lot, I need to check the cost per pip and also the stop loss, all this in order to risk for example, always 1% of the balance.

Do you know how I can use “Expert\Money\MoneyFixedRisk.mqh” file?

That works on the MQl file I do in generate function, but i don’t understand how to use it on my own robots.