Problem with switch.

 

Hi there!

Sorry, I was looking at the forum but have not found an answer... but I think it's a very silly question.

I have the next code:

switch(Symbol())

{

case "EURUSD" :

A = 35; Z = 50;

break;

}


Well, this code dont work and i dont know why.... pls i need some help :)

note: single quotes does not work...

 
You can only 'switch' on integers.
 
gordon:
You can only 'switch' on integers.

That's right.

You can use something like

int intPair = 0;

if(Symbol()=="EURUSD) intPair=1;

if(Symbol()=="USDCHF) intPair=2;

etc
Then use your switch with intPair not Symbol()
 
  1.      if(Symbol()=="EURUSD) { /* case 1 */ }
    else if(Symbol()=="USDCHF) { /* case 2 */ }
     ...
  2. static string pairs[] = {"EURUSD", "USDCHF" ...}
    for(int intPair = ArraySize(pairs)-1; intPair >= 0; intPair--) if(
        Symbol() == pairs[intPair]) break;
    if(intPair<0) // Error logic
    

 
WHRoeder:

Thanks!.

I mistook a sentence from manual... "Each variation 'case' can be marked by an integer constant, a character constant, or a constant expression"... now I understand the meaning. I should read better the first sentence: "The values of Expression and of Parameters can only be the values of int type".

WHRoeder, smart second choice.

Thanks again.

 
string vType = "CLOSE";

switch(vType) {

        case 'CLOSE' :
        
                //do something

                break;
}
"more that 1 symbol" error

Please put error reported by terminal, it's more easy to find it in the forum, it could be stupid error but works!

I've waste a lot of time to find this post, I could open new.

Reason: