Download MetaTrader 5

checking charts

To add comments, please log in or register
Michael
702
Michael  

I'm racking my brain about this and can't quite figure it out.

How can I go about checking to see if a chart is open or not?  And if it's not open, open it?  

Thanks. 

honest_knave
Moderator
2412
honest_knave  

Loop through the open charts and check the symbol / timeframe as required.

If the chart isn't found, open the chart using ChartOpen() . You can also use ChartApplyTemplate() for your newly opened chart, if required.

An example which will check for the GBPJPY M15 chart, and open one if necessary:

   string sym   = "GBPJPY";
   int    tf    = PERIOD_M15;
   bool   found = false;
   long   ID    = ChartFirst();
   while(ID>=0) {
      if(ChartSymbol(ID)==sym && ChartPeriod(ID)==tf) { 
         found=true;
         break; }
      ID=ChartNext(ID);}
   if(!found) {
      ChartOpen(sym,tf);}
Carl Schreiber
6788
Carl Schreiber  

You can loop through the open charts with ChartFirst(), ChartNext(), ChartID(), ChartSymbol(), ..

It's all in the reference

To add comments, please log in or register