Download MetaTrader 5

Market Watch instrument position number

To add comments, please log in or register
Dalta
50
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

honest_knave
Moderator
2326
honest_knave  
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);
Dalta
50
Dalta  
honest_knave:


Function:


Call:


I feel stupid... :P


Thank you!

honest_knave
Moderator
2326
honest_knave  
Dalta:


I feel stupid... :P


Thank you!


There are no stupid questions, only stupid answers 
Dalta
50
Dalta  
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
honest_knave
Moderator
2326
honest_knave  
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);
Dalta
50
Dalta  
honest_knave:

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


cheers!
To add comments, please log in or register