Download MetaTrader 5
To add comments, please log in or register
Add our Twitter channel to friends and follow the news!
Michael
492
Michael 2015.01.07 04:33 

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
951
honest_knave 2015.01.07 09:12  

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
5932
Carl Schreiber 2015.01.07 09:12  

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