Lot Size Calculation from Risk Percentage - page 3

 

Please take a look at

https://www.mql5.com/en/forum/11943/page2#comment_2759458

Free public domain working library for any financial instrument, any leverage, any account type etc.

How to calculate a position size correctly
How to calculate a position size correctly
  • reviews: 1
  • www.mql5.com
I'm running this in Strategy Tester with 1:100 leverage and an initial margin of $10000 on GBPUSD and alpari as my broker (who run a 5 _digit).
 
// External variables
extern bool DynamicLotSize = true;
extern double EquityPercent = 2;
extern double FixedLotSize = 0.1;
// Start function
if(DynamicLotSize == true)
{
double RiskAmount = AccountEquity() * (EquityPercent / 100);
double TickValue = MarketInfo(Symbol(),MODE_TICKVALUE);
if(Digits == 3 || Digits == 5) TickValue *= 10;
double CalcLots = (RiskAmount / StopLoss) / TickValue;
double LotSize = CalcLots;
}
else LotSize = FixedLotSize;
try this
 
Muhammad Mudasir:
try this
Thank you so much!
 
Alain Verleyen:

Hi Alain,

I have made your code as a double function which returns lotsize but the problem is that it is not giving correct lotsize for "usdjpy" in tester but showing correct lotsize if i loaded ea on chart(it's working on real time but not on tester).

Need help to fix it.(mt5)

Reason: