prev_calculated

 
Comments not related to "Bugs, bugs, issues" have been moved to this thread.
 

MT5 build 1455

Indicator for the test:

#property indicator_chart_window
#property indicator_buffers     0
#property indicator_plots       0

int OnInit(void) {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 &TickVolume[],
  const long &Volume[],
  const int &Spread[]
) {
  static int si_Tick = 0;
  Print(++si_Tick, ": prev_calculated = ", prev_calculated);
  
  return(rates_total);
}

1. Putting indicator on the chart

2. Close the terminal

3. open terminal

Log:

2016.10.17 08:04:38.755 Test (USDJPY,M15)       1: prev_calculated = 0
2016.10.17 08:04:38.757 Test (USDJPY,M15)       2: prev_calculated = 100322
2016.10.17 08:04:39.060 Test (USDJPY,M15)       3: prev_calculated = 0
2016.10.17 08:04:39.837 Test (USDJPY,M15)       4: prev_calculated = 100322
2016.10.17 08:04:39.837 Test (USDJPY,M15)       5: prev_calculated = 100322
...

Am I missing something or is it impossible to trust the variable prev_calculated, I have to crunch the crutch?

 
Alexander Puzanov:

MT5 build 1455

Indicator for the test:

#property indicator_chart_window
#property indicator_buffers     0
#property indicator_plots       0

int OnInit(void) {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 &TickVolume[],
  const long &Volume[],
  const int &Spread[]
) {
  static int si_Tick = 0;
  Print(++si_Tick, ": prev_calculated = ", prev_calculated);
  
  return(rates_total);
}

1. Putting indicator on the chart

2. Close the terminal

3. open terminal

Log:

2016.10.17 08:04:38.755 Test (USDJPY,M15)       1: prev_calculated = 0
2016.10.17 08:04:38.757 Test (USDJPY,M15)       2: prev_calculated = 100322
2016.10.17 08:04:39.060 Test (USDJPY,M15)       3: prev_calculated = 0
2016.10.17 08:04:39.837 Test (USDJPY,M15)       4: prev_calculated = 100322
2016.10.17 08:04:39.837 Test (USDJPY,M15)       5: prev_calculated = 100322
...

Am I missing something or is it impossible to trust the variable prev_calculated, I have to crunch the crutch?

Variable prev_calculated can be reset to 0 even without history paging if checksum has changed (this is an approximate response from servicedesk).
 
Alexey Kozitsyn:
The variable prev_calculated can be reset to 0 even without history paging if the checksum has changed (this is a rough answer from servicedesk).
Got it. Thanks. So to the carpenter...
 
Alexander Puzanov:
I see. Thank you. So to the carpenter...
There is no need to exaggerate - zero return from prev_calculate is a very common event. The task of the programmer is to catch such an event and correctly fill in the indicator buffers in such a case. No more and no less.
 
Ilyas:

Added operators *(Dereference/Inderection) and &(Address-of), no additional language changes will be made/planned

Please clarify the following:

* getting a variable by reference - only applies to:

1. class objects

2. structure objects

3. Fundamental types

In this context, is it just rlvalue or lvalue as well?

 
Karputov Vladimir:
The task of the programmer is to catch such an event

So I'm not a programmer - my tasks are different. Carpenter, I guess - I'll 'crutch the crutch' and think I'm 'catching the event'.

And I'm not exaggerating, because the stated purpose of this variable:

prev_calculated  // обработано баров на предыдущем вызове

In addition to that purpose, it's also supposed to be a change flag in the history, plus it's supposed to track some other changes. All this is useful but we cannot use it for its direct purpose - to show how many 'bars were processed during the previous call' - prev_calculated.

 
Alexander Puzanov:

So I'm not a programmer - my tasks are different. Carpenter, I guess - I'll 'crutch the crutch' and think I'm 'catching the event'.

And I'm not exaggerating, because the stated purpose of this variable:

prev_calculated  // обработано баров на предыдущем вызове

In addition to that purpose, it's also supposed to be a change flag in the history, plus it's supposed to track some other changes. All this is useful but you cannot use it for its direct purpose - to show how many 'bars were processed at the previous call' - prev_calculated

And if we simply recalculate the whole indicator when 0? Seems like the best solution to me.
 
Alexander Puzanov:

So I'm not a programmer - my tasks are different. Carpenter, I guess - I'll 'crutch the crutch' and think I'm 'catching the event'.

And I'm not exaggerating, because the stated purpose of this variable:

prev_calculated  // обработано баров на предыдущем вызове

In addition to that purpose, it's also supposed to be a change flag in the history, plus it's supposed to track some other changes. All this is useful but we cannot use it for its direct purpose - to show how many bars were 'processed in the previous call' - prev_calculated

If prev_calculated=0, it means that a full recalculation should be performed. All standard indicators are completely recalculated in this case.

What is not clear?

It is said that the checksum has changed in the history. It would be cheaper to re-calculate the indicator than to find out why the checksum has changed.

The documentation explicitly mentions that

Note the connection between the return value of OnCalculate() and the second input parameter prev_calculated. The prev_calculated parameter in the function call contains a value returned by OnCalculate() on thepreviouscall. This allows for economical algorithms for calculating the custom indicator in order to avoid repeated calculations for those bars that haven't changed since the previous call of this function.

For this, it is usually enough to return the value of the rates_total parameter, which contains the number of bars in the current function call. If since the last call of OnCalculate() price data have changed (a deeper history was pumped or history blanks were filled), then the value of the input parameter prev_calculated will be set to zero by the terminal.

 
Alexey Kozitsyn:
How about just recalculating the whole indicator when 0? In my opinion, the best solution.
This is exactly what you should do: when you get prev_calculate==0 you should recalculate the whole indicator. Since rev_calculate==0 is usually a history swap. And if the history is swapped, it means that there may be new bars that were missed or were not calculated earlier - i.e. the indicator readings will already be wrong.
 
Karputov Vladimir:
This is exactly what you should do: when prev_calculate==0 is received, you should recalculate the WHOLE indicator. Since rev_calculate==0 is usually a history swap. And if the history is swapped, it means that there may be new bars that were missed or were not calculated earlier - i.e. the indicator readings will be incorrect.
:) That's what I do...
Reason: