WRONG !
//---- 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.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
GetLotForOpeningPos:
Author: Nikolay Kositsin