Download MetaTrader 5

How can I use switch operator with _Symbol?

To add comments, please log in or register
Daniel Arges
174
Daniel Arges  
I need to return a specific value based on _Symbol of current chart. It seems switch operator doesn't work with _Symbol. Thanks
nicholishen
1519
nicholishen  
Daniel Arges:
I need to return a specific value based on _Symbol of current chart. It seems switch operator doesn't work with _Symbol. Thanks

int SymbolValue(const string symbol)
{
   if(StringFind(symbol,"EURUSD")>=0) return 1;
   if(StringFind(symbol,"USDJPY")>=0) return 2;
   ...
}
whroeder1
17050
whroeder1  
or variations of:
enum SymbolIndex { SI_EURUSD, ..., SI_USDJPY}; #define SI_COUNT (SI_USDJPY+1)
int symbol_to_index(const string symbol){
   SymbolIndex si=SI_COUNT;   while(--si != WRONG_VALUE){
      string si_XXX = EnumToString(idx);                        // SI_XXX
      string xxx    = StringSubstr(si_XXX, 3);                  // XXX
      if(StringFind(symbol,xxx)>=0) break;
   }
   return si;
}
Daniel Arges
174
Daniel Arges  
whroeder1:
or variations of:

Thank you all!

To add comments, please log in or register