MT5 build 1455
Indicator for the test:
#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.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?
MT5 build 1455
Indicator for the test:
#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.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?
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).
I see. Thank you. So to the carpenter...
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:
2. structure objects
3. Fundamental types
In this context, is it just rlvalue or lvalue as well?
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:
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.
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:
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
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:
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.
How about just recalculating the whole indicator when 0? In my opinion, the best solution.
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.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use