Meaning of prev_calculated in OnCalculate

 

First, I will reprint a paragraph of the English help file:

We should noted the connection between the return value of OnCalculate() and the second input parameter prev_calculated. During the function call, the prev_calculated parameter contains a value returned by OnCalculate() during previous call.

As I do not believe anything in the new betatrader 600+, I started a test, and I placed only a Print statement to see how the values change.
In addition I placed a random number for the return value, to confirm if it appears back in the prev_calculated variable.

int OnCalculate (const int rates_total,      // size of input time series
                 const int prev_calculated,  // bars handled in previous call
                 const datetime& time[],     // Time
                 const double& open[],       // Open
                 const double& high[],       // High
                 const double& low[],        // Low
                 const double& close[],      // Close
                 const long& tick_volume[],  // Tick Volume
                 const long& volume[],       // Real Volume
                 const int& spread[]         // Spread
   ) {
   Print ("Volume: ", Volume[0], " , prev_calculated: ", prev_calculated, " ,rates_total: " ,rates_total, " , IndicatorCounted: " , IndicatorCounted(), " , Bars:", Bars);
   return(rand());
);

The output was like that:

15:04:00 tick EURUSD,M1: Volume: 33 , prev_calculated: 75333 ,rates_total: 75333 , IndicatorCounted: 75332 , Bars:75333
15:04:00 tick EURUSD,M1: Volume: 34 , prev_calculated: 75333 ,rates_total: 75333 , IndicatorCounted: 75332 , Bars:75333
15:04:01 tick EURUSD,M1: Volume: 35 , prev_calculated: 75333 ,rates_total: 75333 , IndicatorCounted: 75332 , Bars:75333
15:04:04 tick EURUSD,M1: Volume: 1 , prev_calculated: 75333 ,rates_total: 75334 , IndicatorCounted: 75332 , Bars:75334
15:04:06 tick EURUSD,M1: Volume: 2 , prev_calculated: 75334 ,rates_total: 75334 , IndicatorCounted: 75333 , Bars:75334
15:04:06 tick EURUSD,M1: Volume: 3 , prev_calculated: 75334 ,rates_total: 75334 , IndicatorCounted: 75333 , Bars:75334

From this listing, I haven't found the previous return value in the function parameter. The prev_calculated equals the previous rates_total instead (= IndicatorCounted() + 1).

So, I wonder what will change in the future - implementation or the help file? What shall I keep an eye on?

 

This cannot be the code that you are showing the results from. You have placed your print and return in the parameters for the OnCalculate function. There is no way that this will work.

int OnCalculate (const int rates_total,      // size of input time series
                 const int prev_calculated,  // bars handled in previous call
                 const datetime& time[],     // Time
                 const double& open[],       // Open
                 const double& high[],       // High
                 const double& low[],        // Low
                 const double& close[],      // Close
                 const long& tick_volume[],  // Tick Volume
                 const long& volume[],       // Real Volume
                 const int& spread[]         // Spread

   Print ("Volume: ", Volume[0], " , prev_calculated: ", prev_calculated, " ,rates_total: " ,rates_total, " , IndicatorCounted: " , IndicatorCounted(), " , Bars:", Bars);
   return(rand());
);
 
GumRai:

This cannot be the code that you are showing the results from. You have placed your print and return in the parameters for the OnCalculate function. There is no way that this will work.


Thank you, I added the missing line. Any other comment?