Download MetaTrader 5
To add comments, please log in or register
Do you need a trading robot? Orderit via Freelance service!
andream1977
34
andream1977 2016.07.25 10:28 
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
2403
Drazen Penic 2016.07.25 10:36  

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
947
honest_knave 2016.07.25 16:32  

Or more simply:

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