Lotsize Calculation

 

Lets assume the following (simplified) Code:

extern double Lots = 0.1;
extern double LotMultiplier = 1.4;

/* First Order */
myLot = 0.1;

/* Second Order */
myLot = 0.1 * LotMultiplier; // = 0.14

/* Third Order */
myLot = 0.14 * LotMultiplier; // = 0.196

/* ... n Orders ...*/
myLot = <LastOrderLotSize> * LotMultiplier;
 

This works well with MODE_LOTSTEP = 0.01.

With MODE_LOTSTEP 0.1 it does not work because 0.14 Lot is not allowed.

How can I calculate on Init to Print Out an Alert und prevent trading with this Lot Size?

thanks in advance 

 
fx_maddin:

Lets assume the following (simplified) Code:

This works well with MODE_LOTSTEP = 0.01.

With MODE_LOTSTEP 0.1 it does not work because 0.14 Lot is not allowed.

How can I calculate on Init to Print Out an Alert und prevent trading with this Lot Size?

thanks in advance 

Why init() ?  you should be checking when you have calculated your position size,  or adjust it to fit within the requirements of MODE_MINLOT  MODE_MAXLOT and MODE_LOTSTEP 
 
RaptorUK:
Why init() ?  you should be checking when you have calculated your position size,  or adjust it to fit within the requirements of MODE_MINLOT  MODE_MAXLOT and MODE_LOTSTEP 


I will check on Init if the LotMultiplier work with current LotStep. I think it will be okay to check once. Is there a way to calculate?
 
fx_maddin:

I will check on Init if the LotMultiplier work with current LotStep. I think it will be okay to check once. Is there a way to calculate?
This is why it is a bad idea to do it that way,  your code will be dependant on the way in which you use your LotMultiplier variable,  if you change it then you have to change your code,  you code is not reusable,  it's inefficient and bad practice. 

Your first post in this thread is incorrect,  the third order position size, 0.196 ,  does not work even with a LOTSTEP of 0.01 . . .  the fourth position size would be 0.2744  and would also not work.
 
RaptorUK:
This is why it is a bad idea to do it that way,  your code will be dependant on the way in which you use your LotMultiplier variable,  if you change it then you have to change your code,  you code is not reusable,  it's inefficient and bad practice. 

Your first post in this thread is incorrect,  the third order position size, 0.196 ,  does not work even with a LOTSTEP of 0.01 . . .  the fourth position size would be 0.2744  and would also not work.

I know that it will not work, therefore I looking for a possibility to calculate. If LotStep 0.01 and LotMultiplier = 1.4 everything works well. If LotStep 0.1 and LotMultiplier is 1.4, an Alert should tell the user to change theMultiplier. If this not possible, I must do it another way.
 
fx_maddin:

I know that it will not work, therefore I looking for a possibility to calculate. If LotStep 0.01 and LotMultiplier = 1.4 everything works well. If LotStep 0.1 and LotMultiplier is 1.4, an Alert should tell the user to change theMultiplier. If this not possible, I must do it another way.
" If LotStep 0.01 and LotMultiplier = 1.4 everything works well."  NO,  it doesn't . . .
 
RaptorUK:
" If LotStep 0.01 and LotMultiplier = 1.4 everything works well."  NO,  it doesn't . . .


It works because I use NormalizeDouble

myLot = NormalizeDouble(myLot * 1.4, Digits);

But it does not work on Lotstep 0.1 :-( 

 
fx_maddin:


It works because I use NormalizeDouble

But it does not work on Lotstep 0.1 :-( 

No,  it doesn't. If myLot is 0.14 and you multiply by 1.4 you get 0.196,  use NormalizeDouble on a 3, 4 or 5 digit pair and you will end up with 0.196, 0.1960 or 0.19600  none of which are full multiples of 0.01
 

It seems to be working on 4 several Broker and 8 different Pairs: 

265541242012.11.06 09:18sell0.01eurusdm
265548242012.11.06 09:30sell0.01eurusdm
265550082012.11.06 09:32sell0.01eurusdm
265552772012.11.06 09:38sell0.01eurusdm
265554212012.11.06 09:40sell0.02eurusdm
265554632012.11.06 09:40sell0.03eurusdm
265555962012.11.06 09:41sell0.05eurusdm
265556332012.11.06 09:41sell0.07eurusdm
265556882012.11.06 09:41sell0.10eurusdm
265558702012.11.06 09:42sell0.14eurusdm
265561402012.11.06 09:48sell0.20eurusdm
265568832012.11.06 10:03sell0.28eurusdm
265573192012.11.06 10:10sell0.40eurusdm
265574202012.11.06 10:10sell0.56eurusdm
265576722012.11.06 10:11sell0.79eurusdm
265577162012.11.06 10:11sell1.11eurusdm
265579972012.11.06 10:14sell1.55eurusdm

 

The only thing I do in my Code is what I posted above... It works as I expected.

 
fx_maddin:


It works because I use NormalizeDouble

myLot = NormalizeDouble(myLot * 1.4, Digits);

But it does not work on Lotstep 0.1 :-( 

That will also not work correct. It assumes lotStep = 0.0001 A lot of brokers have minlot=0.1, lotStep=0.01. Normalize it correctly
double NormalizeLots(double lots, string pair=""){
    if (pair == "") pair = Symbol();
    double  lotStep     = MarketInfo(pair, MODE_LOTSTEP),
            minLot      = MarketInfo(pair, MODE_MINLOT);
    lots    = MathRound(lots/ls) * ls;
    if (lots < minLot) lots = 0;    // or minLot
    return(lots);
}