Hello,
I'm using this function in my EA to calculate the lot size position according to account balance percentage but the problem is that the calculation is not accurate specially in JPY pairs,
For example if the loss must be 50 usd according to account balance percentage risk most of the time it's more than the desired risk percentage sometimes ( 60 or 70 usd)
Please if someone can help me it will be appreciated i've been trying for so long without success.
Best Regards,
I'm using this function in my EA to calculate the lot size position according to account balance percentage but the problem is that the calculation is not accurate specially in JPY pairs,
For example if the loss must be 50 usd according to account balance percentage risk most of the time it's more than the desired risk percentage sometimes ( 60 or 70 usd)
Please if someone can help me it will be appreciated i've been trying for so long without success.
Best Regards,
MQL4:
double GetLotSize(string symbol, double risk, double SL) { double tickvalue = MarketInfo(Symbol(), MODE_TICKVALUE); double lotstep = MarketInfo (Symbol(), MODE_LOTSTEP); double minlot = MarketInfo(Symbol(), MODE_MINLOT); double maxlot = MarketInfo(Symbol(), MODE_MAXLOT); double lotsize; if (StringFind(symbol, "jpy") != -1) { lotsize = ((AccountBalance() * risk) / ( SL * tickvalue ))*Point; } else { lotsize = ((AccountBalance() * risk) / ( SL * tickvalue ))/1000; } // Ensure that the calculated lot size is within the minimum and maximum allowed by the broker lotsize = MathMin(lotsize, maxlot); lotsize = MathMax(lotsize, minlot); // Round the lot size to the nearest step size allowed by the broker lotsize = MathRound(lotsize/lotstep)*lotstep; double pipval = (AccountBalance() * risk) / SL /100; Print( " tickvalue=", tickvalue, " lotstep =", lotstep, " Lotsize=", lotsize, " Pipval=",pipval ); return lotsize; }