Maximum Percentage of Equity Risk:
This code allows you to set a maximum percentage of equity risk.
It checks if asked buy/sell lots are fitting the risk. If not, lots are automatically adjusted to fit the risk that was set.
Author: Remi PASSANELLO
bool UseMaximumPercentageatRisk = true;
double MaximumPercentageatRisk =1;
bool IsMicroAccount = true ; //for accounts allowing 0.01 lots
double GetLots(double lotsize_bn)
if((NormalizeDouble(AccountFreeMargin()*(MaximumPercentageatRisk/100)/1000.0,tmpdecimal)<lotsize_bn) && UseMaximumPercentageatRisk)
Print("RPTrade-Lot adjusted from ",old_lot," to minimum size allowed by the server of ",lotsize_bn," but it DOES NOT comply with Maximum Risk condition. User interaction is required!");
Print("RPTrade-Lot adjusted from ",old_lot," to ",lotsize_bn," to comply with Maximum Risk condition. Each trade can risk only ",MaximumPercentageatRisk,"% of free margin.");
Should be something like this ;-)
I was looking at your code in MQL5 for "Maximum Percentage of Equity Risk". I have some doubts regarding to how to use it. I have the mqh file in the include file and use #include <RPTrade.mqh> at the expert that I want to use. Can you elaborate more on how to use this code in a expert advisor please? I'm new to coding. I have made expert advisors, but I don't know how to call a class or function in another file.
I need to call the function GetLots (lotsize) right? And in my order request need to use "lotsize" value for the lots?
First you must add the 2 inputs to your EA:
Then you must call the function GetLots() and set the lotsize you wish into the brackets, for instance call:
MyLotSize = GetLots (100);
And according to what you entered as MaximumPercentageRisk and your account equity, you will get the right size.
For instance, if MaximumPercentageRisk = 1; and your equity = 1000$, the function will return 0.01 lot.
Trade at low risk, markets are wild actually ;-)
Hi, Thanks for sharing this information.
I am a rookie but I would love to be able to have a way to be consistent with my lot size and I would like to know how can I use your code to do that?
Thanks in advance
Please enable the necessary setting in your browser, otherwise you will not be able to log in.