Download MetaTrader 5

ChartClose - all charts?

To add comments, please log in or register
Jeremy Roach
2455
Jeremy Roach  

Hi,

I'm wondering the easiest way to close all charts. I need it as I have a script that opens about 50 charts to apply a template, and I want an easy way to close them all.

I have utilised this script  ( https://www.mql5.com/en/code/11566 ), but it only closes charts of the same currency pair.  

void OnStart()
  {string cs = ChartSymbol();
  long chid=ChartFirst();long pom;
//---
  //ChartAc
  for(int i=0;i<20;i++)
    {pom=ChartNext(chid);if(ChartSymbol(chid)==cs)ChartClose(chid);if(pom==-1)break;chid=pom;}
    
  }
//+

 

I imagine you could do a loop, close chart Id = 1, id +1, until ID = 100 (no more then 100 charts?) 

Any help would be great. 

Thanks 

whroeder1
14786
whroeder1  
yeders: I imagine you could do a loop, close chart Id = 1, id +1, until ID = 100 (no more then 100 charts?)
  for(int i=0;i<20;i++)
Don't hard code numbers, don't assume. Read the documentation
long chid=ChartFirst();
while(chid >= 0){                            // Just do ALL charts, no counting needed.
   long nextID = ChartNext(chid);            // Get the next chart before closing current
   if(ChartSymbol(chid)==cs)ChartClose(chid);
   chid = nextID;                            // process next chart.
}
To add comments, please log in or register