I have the following code...
maxLots = AccountFreeMargin() / MarketInfo(Symbol(),MODE_MARGINREQUIRED);
lotStep = MarketInfo(Symbol(), MODE_LOTSTEP);
maxLots = floor(((maxLots / lotStep) * lotStep) * 100) / 100;
maxLots = NormalizeDouble(maxLots, 2);
With $1,000 in Free Margin on an account with 50:1 leverage, it says I can open 0.36 lots of GBPUSD. However, when I try to open a position of that size, it fails due to insufficient margin.
Can anyone tell me what I am doing wrong?
All the best,Fred
Margin has nothing to do with lotstep. Risk depends on your initial stop loss, lot size, and the value of the pair.
In code (MT4):