This function returns the lot size depending on the amount of money in the deposit currency being used. Input parameters are represented by three variables:
double GetLotForOpeningPos ( string symbol, // Symbol of the pair for the calculation of the lot size ENUM_POSITION_TYPE direction, // Direction of the trade double lot_margin // The amount of money in the deposit currency being used, for the calculation of the lot size )
The function uses the library GetLotForOpeningPos.mqh (to be copied into the terminal_data_directory\MQL5\Include) the contents of which should be included in the developed code using the #include directive prior to using the function at the global level:
#include <GetLotForOpeningPos.mqh>
Translated from Russian by MetaQuotes Software Corp.
Original code: http://www.mql5.com/ru/code/961
WRONG !
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.
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
4. A complete calculation
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.
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.
Cheers