invalide lotsize error

 

I tried to buy a lot of size 4.024 . I got an error because my broker will only allow lots of in increments of .10

If I were to buy a lot size of 4.024 how can I make sure I it will automatically round to 4.000 or if I were to buy a lot size in my EA of size 4.386, it would round to 4.40.

what code or function can I use to do this?


Thanks

 
NormalizeDouble()
MathRound()
 
NormalizeDouble would only work for lot steps of 1.0, 0.1, 0.01 etc. Any other it fails. Do it right
double  minLot  = MarketInfo(Symbol(), MODE_MINLOT),
        lotStep = MarketInfo(Symbol(), MODE_LOTSTEP);
lotSize = MathFloor(lotSize/lotStep)*lotStep; // Or MathRound
if (lotSize < minLot) ...
The same technique is required for pending metal open prices. They must be a multiple of MODE_TICKSIZE (0.5) Point=0.1 and Digits=1
Reason: