Download MetaTrader 5

how i can get the chart id of all the opened chart

To add comments, please log in or register
andream1977
52
andream1977  
i'm building ad indicator in mql for mt4

in my mql indicator, i need to get the chart id of all the chart that i opened manually on my mt4
how i can get these id?
Drazen Penic
2701
Drazen Penic  

Use ChartFirst() and ChartNext()  functions to enumerate active charts. 

This is sample code from the documentation for the ChartNext():

//--- variables for chart ID
   long currChart,prevChart=ChartFirst();
   int i=0,limit=100;
   Print("ChartFirst =",ChartSymbol(prevChart)," ID =",prevChart);
   while(i<limit)// We have certainly not more than 100 open charts
     {
      currChart=ChartNext(prevChart); // Get the new chart ID by using the previous chart ID
      if(currChart<0) break;          // Have reached the end of the chart list
      Print(i,ChartSymbol(currChart)," ID =",currChart);
      prevChart=currChart;// let's save the current chart ID for the ChartNext()
      i++;// Do not forget to increase the counter
     }
honest_knave
Moderator
2318
honest_knave  

Or more simply:

long chartID=ChartFirst();
while(chartID >= 0)
  {
   Print(chartID);
   chartID = ChartNext(chartID);
  }
andream1977
52
andream1977  
it's work!, thx to all!
To add comments, please log in or register