prev_calculated reset twice when MT4 restart

 

Hi all,

I have the following simplified code:

bool init_;

int OnInit()
  {

   init_ = true;
   
   
//---
   return(INIT_SUCCEEDED);
  }
  

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---


   
   Print(rates_total, "_", prev_calculated, "_", init_);
   init_ = false;
   return(rates_total);
  }


I have got the following output when restart MT4 while having indicator attached to the chart. The prev_calculated has been reset to 0 again after 7 seconds despite the indicator has not reloaded. I would like to seek reason behind the issue. Thank you in advance for your help.


 
Tee Yan Sheng: I have the following simplified code: I have got the following output when restart MT4 while having indicator attached to the chart. The prev_calculated has been reset to 0 again after 7 seconds despite the indicator has not reloaded. I would like to seek reason behind the issue. Thank you in advance for your help.

This may happen when history data is updated or changed, or the maximum number of bars for a chart or history overflows, affecting the beginning of the available data. In these cases, the Indicator has to be recalculated.

Also, when you restart the terminal, there is a delay between using the data available on file and an update of the data from the broker, at which point the previous reason comes into effect.

 
Fernando Carreiro #:

This may happen when history data is updated or changed, or the maximum number of bars for a chart or history overflows, affecting the beginning of the available data. In these cases, the Indicator has to be recalculated.

Also, when you restart the terminal, there is a delay between using the data available on file and an update of the data from the broker, at which point the previous reason comes into effect.

Thank you very much for the detailed explanation.

Reason: