Market Watch instrument position number

 

Hello,


I would like to know if there's a relatively simple (but mql-only) way to find the position number of a given symbol in the market watch symbols list.

For instance something like: EURUSD is the 4th symbol, EURCAD is the 12th, XAUUSD is the 24th and so on


thanks in advance

 
Dalta:

Hello,


I would like to know if there's a relatively simple (but mql-only) way to find the position number of a given symbol in the market watch symbols list.

For instance something like: EURUSD is the 4th symbol, EURCAD is the 12th, XAUUSD is the 24th and so on


thanks in advance


Function:

int FindIndex(string symbol, bool selected=true)
  {
   for(int i=0; i<SymbolsTotal(selected); i++) if(SymbolName(i,selected)==symbol) return(i);
   return(-1);
  }


Call:

   int i = FindIndex("EURUSD");
   if(i<0) Print("EURUSD not found!"); else Print("EURUSD index is ",i);
 
honest_knave:


Function:


Call:


I feel stupid... :P


Thank you!

 
Dalta:


I feel stupid... :P


Thank you!


There are no stupid questions, only stupid answers 
 
honest_knave:

There are no stupid questions, only stupid answers 

There's a way to force the market watch to display all the available symbols? Like the "show all" option? Because I would need the absolute symbol index, not the relative position to the current displayed symbol list
 
Dalta:

There's a way to force the market watch to display all the available symbols? Like the "show all" option?
for(int i=0; i<SymbolsTotal(false); i++) SymbolSelect(SymbolName(i,false),true);

Or if you don't want to show all the symbols, but you want the index from the general list: 

int i = FindIndex("EURUSD",false);
if(i<0) Print("EURUSD not found!"); else Print("EURUSD index is ",i);
 
honest_knave:

Or if you don't want to show all the symbols, but you want the index from the general list: 


cheers!
Reason: