illegal switch expression type - error

Rupak Roy
182
Rupak Roy  

Hi,

Could anybody please check the code - that return error : "illegal switch expression type" and "'0.01' - constant expression is not integral".

the code was working in old version. 



double step = MarketInfo(Symbol(), MODE_LOTSTEP);

   switch(step) {
      case 0.01 : Lotdecimal = 2; break;
      case  0.1 : Lotdecimal = 1; break;
      case    1 : Lotdecimal = 0; break;
   }
      if (Digits == 5 || Digits == 3) gi_222 = 10;
         return (0);
}


Thanks a lot for help

Keith Watford
Moderator
31113
Keith Watford  
Rupak Roy:

Hi,

Could anybody please check the code - that return error : "illegal switch expression type" and "'0.01' - constant expression is not integral".

the code was working in old version. 




Thanks a lot for help

Expression of the switch operator must be of integer type

Rupak Roy
182
Rupak Roy  
Rupak Roy:

Hi,

Could anybody please check the code - that return error : "illegal switch expression type" and "'0.01' - constant expression is not integral".

the code was working in old version. 




Thanks a lot for help

Keith Watford:

Expression of the switch operator must be of integer type

Hi Keith, 

Thanks, If integer used then no then it doesn't show error. As the operator hold decimal so double used. Integer will work for that for decimal ? 

Keith Watford
Moderator
31113
Keith Watford  
Rupak Roy:

Hi Keith, 

Thanks, If integer used then no then it doesn't show error. As the operator hold decimal so double used. Integer will work for that for decimal ? 

I don't know what you are asking.

You cannot use a double, only int and uint.

Keith Watford
Moderator
31113
Keith Watford  

I have deleted your other topic as it is a repeat of this topic and you have already been answered.

MarketInfo() returns a double so you were once again using a double with switch().

The variable names suggest that you are working with decompiled code.

If you post decompiled code, it will be deleted and you could be banned from the forum.

Chris70
544
Chris70  
... and just in case you didn't read it before the other topic was deleted: -log10(step) is the simple answer
Rupak Roy
182
Rupak Roy  
Chris70:
... and just in case you didn't read it before the other topic was deleted: -log10(step) is the simple answer

Could you show me the way of using -log10(step) for the following code - 

int init() {
   trD = MarketInfo(Symbol(), MODE_SPREAD) * Point;
   if (IsTesting() ==  TRUE) Display_Info(); //  TRUE
   if (IsTesting() == FALSE) Display_Info(); // FALSE
   int step = MarketInfo(Symbol(), MODE_LOTSTEP);
   switch(step) {
      case  0.01:Lotdecimal_0_1_2 = 2; break;
      case  0.1 : Lotdecimal_0_1_2 = 1; break;
      case    1 : Lotdecimal_0_1_2 = 0; break;
   }
      if (Digits == 5 || Digits == 3) val_1= 10;
         return (0);
}
Chris70
544
Chris70  
int init()
  {
   trD = MarketInfo(Symbol(), MODE_SPREAD) * Point;
   if (IsTesting() ==  TRUE) Display_Info(); //  TRUE
   if (IsTesting() == FALSE) Display_Info(); // FALSE
   
double step = MarketInfo(Symbol(), MODE_LOTSTEP);
   Lotdecimal_0_1_2=-log10(step);
   if (Digits == 5 || Digits == 3) val_1= 10;
   return (0);
  }

not tested and I use MQL5 only, but this should work with MQL4, too, because it is basic calculus:

-log10(0.01)=2

-log10(0.1)=1

-log10(1)=0

just be aware, that log doesn't return valid numbers for values <=0

[edit: sorry, didn't see that "step" was declared as an integer --> now corrected

btw: the declaration of "step" doesn't even appear necessary, so even shorter:

int init()
  {
   trD = MarketInfo(Symbol(), MODE_SPREAD) * Point;
   if (IsTesting() ==  TRUE) Display_Info(); //  TRUE
   if (IsTesting() == FALSE) Display_Info(); // FALSE
   Lotdecimal_0_1_2=-log10(MarketInfo(Symbol(), MODE_LOTSTEP);
   if (Digits == 5 || Digits == 3) val_1= 10;
   return (0);
  }

]

Keith Watford
Moderator
31113
Keith Watford  
   int step = MarketInfo(Symbol(), MODE_LOTSTEP);

MarketInfo() returns a double.

You should always use 

#property strict

then you will get a warning about the double being implicitly cast as an integer.

Rupak Roy
182
Rupak Roy  
Keith Watford:

MarketInfo() returns a double.

You should always use 

then you will get a warning about the double being implicitly cast as an integer.

Thanks Keith for supporting

Rupak Roy
182
Rupak Roy  
Chris70:

not tested and I use MQL5 only, but this should work with MQL4, too, because it is basic calculus:

-log10(0.01)=2

-log10(0.1)=1

-log10(1)=0

just be aware, that log doesn't return valid numbers for values <=0

[edit: sorry, didn't see that "step" was declared as an integer --> now corrected

btw: the declaration of "step" doesn't even appear necessary, so even shorter:

]

Thank YOU Chris that really helpful