Download MetaTrader 5
To add comments, please log in or register
Create Forum topics and improve your rating!
Automated-Trading 2012.08.12 16:44 


The function that calculates the lot size depending on the amount of money in the deposit currency being used.

Author: Nikolay Kositsin

onewithzachy 2012.08.12 17:44  


//---- normalizing the lot size to the nearest standard value 
lot = LOTSTEP*MathFloor(lot/LOTSTEP);

That lot min-lot step calculation is wrong !.

What we should do is :

1. Subtract the (raw) lot with minimum lot, because we always have have to start calculating lot from the minimum lot defined by broker. If the result is less than 0 then we have no lot.

lot -= MinLot;
if (lot < 0) lot = 0; //--- not even qualify for minimum lot

2. Calculate how many step required for step lot to get to the lot. Don't use MathFloor() function, coz the return type of MathFloor() is double which risking having an error when final lot not compliance with broker requirement. Use some integer type variable.

int the_step;

the_step = lot/LOTSTEP;

3. Final calculation, get them all together

lot = MinLot + the_step*STEPLOT;

4. A complete calculation

//---- normalizing the lot size to the nearest standard value
lot -= MinLot;
if (lot < 0) lot = 0;

int the_step;
the_step = lot/LOTSTEP;

lot = MinLot + the_step*STEPLOT;

//---- checking the lot for the minimum allowable value
if (lot < MinLot) lot=0;

//---- checking the lot for the maximum allowable value       
if(lot>MaxLot) lot=MaxLot;

 5. Terrible - this lot calculation does not include money management which any common sense trader should and must have. Money management calculate the risk of opening position, which is - but not limited to - the cost of losing money to Stop Loss.

To avoid losing money is part of the game. 


PhoenixRising 2012.08.15 15:36  

Hi Nikolay,

 I'm new to MT5 and am wondering if you can suggest an indicator that does this well as you suggest?

Thank you for your informative post.



To add comments, please log in or register