Download MetaTrader 5

Using switch to determine the AccountCurrency() ?

To add comments, please log in or register
mop0
197
mop0  

I tried the following but it didn't work. The error in compiling says it expected each case to be an integer but I have strings such as "USD", "EUR", etc.

double USDBalance;
switch (AccountCurrency())
   {
      case "USD": USDBalance = AccountBalance(); break;
      case "GBP": USDBalance = AccountBalance() * iClose("GBPUSD",0,0); break;
      case "EUR": USDBalance = AccountBalance() * iClose("EURUSD",0,0); break;
      default: Print ("Error in currency determination.");
   }

Can switch handle strings? If not I can always go back to if/else if/else statements...

Ubzen
5390
Ubzen  
eempc:

I tried the following but it didn't work. The error in compiling says it expected each case to be an integer but I have strings such as "USD", "EUR", etc.

Can switch handle strings? If not I can always go back to if/else if/else statements...

MQL4 Reference / Language Basics / Operators / Switch Operator

Switch Operator

Compares the expression value with constants in all the case variants and passes control to the operator that corresponds to the expression value. Each variant of case can be marked with an integer constant, a literal constant or a constant expression. The constant expression can't contain variables or function calls. Expression of the switch operator must be of integer type.

mop0
197
mop0  
Oh well...
onewithzachy
2269
onewithzachy  
eempc:

I tried the following but it didn't work. The error in compiling says it expected each case to be an integer but I have strings such as "USD", "EUR", etc.

Can switch handle strings? If not I can always go back to if/else if/else statements...

Convert to ASCII char, then you can use switch, but using nested ifs -= alot of if within if - will do the trick.


To add comments, please log in or register