checking charts

Back to topics list To post a new topic, please log in or register
avatar
147
nondisclosure 2015.01.07 05: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. 

avatar
736
honest_knave 2015.01.07 10: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);}

 

 

avatar
2017
gooly 2015.01.07 10:12 #
 

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

It's all in the reference

Back to topics list  

To add comments, please log in or register