How to reinitialise all charts with MQL?

Hi guys

I am trying to find a way to programmatically re-initialise all of the active charts.

What I tried is to write a loop that goes through all the active charts and change the TF to M1 and back to its previous TF.

void InitialiseActiveCharts()
   long currChart,prevChart=ChartFirst(); 
   int i=0,limit=10000; 
   while(i<limit)// We have certainly not more than 100 open charts 
      currChart=ChartNext(prevChart); // Get the new chart ID by using the previous chart ID 
      if(currChart<0) break;          // Have reached the end of the chart list 
      prevChart=currChart;// let's save the current chart ID for the ChartNext() 
      i++;// Do not forget to increase the counter 
      int period= ChartPeriod(currChart); // save the chart period
      string symbol= ChartSymbol(currChart); // save the chart symbol 
      ChartSetSymbolPeriod(currChart,symbol,1);  // change to M1
      ChartSetSymbolPeriod(currChart,symbol,period); // apply the previous TF

The problem with the above function is that the “period” that was meant to save the initial TimeFrame of the chart gets lost and does not proceed.

Also changing the TF could disturb the smooth operation of the EA.

Does anyone have any suggestion of how to achieve that?

The reason is the following.

I have several charts running the same EA with a function in the init() part that reads a file.

I only need to read the file on the initialization.

The file gets populated based on another EA (Master EA) that runs on another chart. Whenever this master EA gets initialized the file gets updated

and therefore I need the other charts to re-initialize so they can read the new values.

Do these charts need a recalculation when values change ?

If not , you can have a trigger file with timestamp in it , and read it from the “following” ea’s at time intervals .
When the timestamp is different than the previous one , you pull the file contents (that the master ea populates) from the other eas.

Thank you.

Yes they do.

I will keep in mind this solution also.

Don’t actually use OnInit for those purposes. Instead make your own reinit function and invoke it by sending a custom chart event to the worker EAs from the master… something like this.


input bool inp_is_master = false;
int OnInit()
      Alert("Master is here, telling everyone to reinitialize!");
      for(long ch=ChartFirst(); ch >=0; ch=ChartNext(ch)){
         EventChartCustom(ch, EVENT_SEND_REINIT, 0, 0.0, NULL);
void OnTick(){}
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
   if(id == CHARTEVENT_CUSTOM+EVENT_SEND_REINIT && !inp_is_master)
void reinit()
   //do file stuff, etc.
   Alert(StringFormat("%lld reinitializing.", ChartID()));

That is amazing. Thanks a million