Download MetaTrader 5

checking charts

To add comments, please log in or register
Do you have Mac OS? Find out how to install MetaTrader on it!
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?  


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) { 
         break; }
   if(!found) {
Carl Schreiber
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