OrderLot() Problem

 

Hey all,

My demo account in the strategy tester uses lots of two decimals, 0.21, 0.55 etc etc. When I call OrderLots() I get a one decimal value, 0.5, 0.6 etc. What is even more problematic is the OrderProfit() and OrderSwap() is calculated from the OrderLot() with one decimal thus if I manually add the results they are not the same as the results given by the strategy tester.

Does anyone maybe know how to fix this?

Thanks

 
Found the problem when opening a mini account the problem disappears
 

To find out how many decimal places your lot sizes can use call

MarketInfo(Symbol(),MODE_LOTSTEP));
 
Saidar:
When I call OrderLots() I get a one decimal value, 0.5, 0.6 etc.

No you don't. When you call OrderLots() you get a double 0.5000000000 0.600000000.

It's only if you Print (Alert, Comment or StringConcatenate) a double without using DoubleToStr() that the trailing zero's get dropped, e.g. Print(1.2000) will show 1.2 and Print(1.2300) will show 1.23.

int DigitsLots(string pair=""){
    if (pair == "") pair = Symbol();
    double  LS      = MarketInfo(pair, MODE_LOTSTEP);
    int     nDigits = 0;
    for(double test = 1; test > LS; test /= 10.) nDigits++;
    return(nDigits);
}
 
WHRoeder:

No you don't. When you call OrderLots() you get a double 0.5000000000 0.600000000.

int DigitsLots(string pair=""){
    if (pair == "") pair = Symbol();
    double  LS      = MarketInfo(pair, MODE_LOTSTEP);
    int     nDigits = 0;
    for(double test = 1; test > LS; test /= 10.) nDigits++;
    return(nDigits);
}

This code look well dodgy. You are doing one of them there direct double compares, which may or may not work as you hope.

 
Saidar:

Hey all,

My demo account in the strategy tester uses lots of two decimals, 0.21, 0.55 etc etc. When I call OrderLots() I get a one decimal value, 0.5, 0.6 etc. What is even more problematic is the OrderProfit() and OrderSwap() is calculated from the OrderLot() with one decimal thus if I manually add the results they are not the same as the results given by the strategy tester.

Does anyone maybe know how to fix this?

Thanks

Use MODE_MINLOT and MODE_LOTSTEP correctly in MarketInfo and all will become clear.

If you run this code as a script you should get a better idea ...

string Info(int type, int precision){
   return( DoubleToStr( MarketInfo(Symbol(),type), precision ) );
}
//---------------------------------------------------------------------------------
int start(){

   string str="";
   str= str + "MODE_DIGITS="        + Info(MODE_DIGITS,0)          +"\n";
   str= str + "MODE_SPREAD="        + Info(MODE_SPREAD,0)          +"\n";
   str= str + "MODE_STOPLEVEL="     + Info(MODE_STOPLEVEL,0)       +"\n";
   str= str + "MODE_FREEZELEVEL="   + Info(MODE_FREEZELEVEL,0)     +"\n";
   str= str + "MODE_TICKVALUE="     + Info(MODE_TICKVALUE,Digits)  +"\n";
   str= str + "MODE_TICKSIZE="      + Info(MODE_TICKSIZE,Digits)   +"\n";
   str= str + "MODE_POINT   ="      + Info(MODE_POINT,Digits)      +"\n";
   str= str + "MODE_MINLOT="        + Info(MODE_MINLOT,3)          +"\n";
   str= str + "MODE_LOTSTEP="       + Info(MODE_LOTSTEP,3)         +"\n";
   str= str + "MODE_MAXLOT="        + Info(MODE_MAXLOT,3)          +"\n";
   str= str + "MODE_LOTSIZE="       + Info(MODE_LOTSIZE,0)         +"\n";
   str= str + "MODE_MARGINREQUIRED="+ Info(MODE_MARGINREQUIRED,2)  +"\n";
   Comment(str);
   
   return(0);
}
Reason: