Changing the TF is a problem

 
Actually the problem is that the indicator that draws the line when it changes the TF where the history is not yet loaded, then the bars are added to the chart, and it again calculates the data, respectively, the previous ones are also left out + skipping.
 
Vasyl Nosal:
The problem is that the indicator , that draws the line when it changes the TF, on which the history is not loaded yet, calculates the data, then the bars are added to the chart, and it again calculates the data, respectively, the previous ones are also left out.

So there is an error in the logic of the indicator. When loading the history, the ideal option of the indicator: to calculate its state at the time of the last bar, which hasn't changed in the history and to recalculate the data on the updated portion of the history.

In reality, this option is not always possible, because to return the environment of the indicator on a certain bar would mean to carry out the calculation from the beginning of the history. Therefore, in complex algorithms of the indicator a complete recalculation of the history is performed when loading even one bar (do not confuse with the opening of a new bar).

 
Vasyl Nosal:
Actually the problem is that the indicator that draws the line at the change of TF, on which the history is not loaded yet, calculates the data, then the bars are added to the chart, and it again calculates the data, respectively, the previous ones are also left + skipping.

In the indicator in OnCalculate() check should be done:

if(prev_calculated==0)  // значит история изменилась или это первый проход
 
Karputov Vladimir:

The indicator in OnCalculate() needs to check for:

Thank you.

I was just confused by the fact that the alerts gave me that the story was being loaded in chunks.

Yes. That's right.

 
Ihor Herasko:

So there is an error in the logic of the indicator. When loading the history, the ideal option of the indicator: to calculate its state at the time of the last bar, which hasn't changed in the history and to recalculate the data on the updated portion of the history.

In reality, this option is not always possible, because to return the environment of the indicator on a certain bar would mean to carry out the calculation from the beginning of the history. Therefore, in complex algorithms of the indicator a complete recalculation of the history is performed when loading even one bar (do not confuse with the opening of a new bar).

So the only workable solution is only?

for(int i=rates_total-prev_calculated;i>=0;i--)

 
Vasyl Nosal:

So the only solution that works is?

for(int i=rates_total-prev_calculated;i>=0;i--)

And if I need recalculation of not only current bar then (for example 4)?

for(int i=rates_total-prev_calculated+4;i>=0;i--) 

{ 

if(i>Bars) i=Bars; 
 

Yeah, it works.

When bars are loaded in chunks, they are recalculated in chunks.

The correct chunk is only the last one to be loaded further to the left haha.

 
Vasyl Nosal:

Yeah, it works.

When bars are loaded in chunks, they are recalculated in chunks.

The correct chunk is only the last one to be loaded further to the left haha.

Time to learn how to write indicators.
 
Victor Nikolaev:
It's time to learn how to write indicators

Teach me.

And I say that the developers should make adjustments in the first calculations of the indicator.

 
Victor Nikolaev:
Time to learn how to write indicators

Want a trick? Guess what Alert returned?

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[])
  {
  if(prev_calculated!=0) Alert(prev_calculated," M:",Period());
return(rates_total);
  }

 
Vasyl Nosal:

You want a trick? Guess what Alert returned?

I don't use alerts in indicators. Provide for a full recalculation if there is a history download. It's easy to control.

Reason: