Download MetaTrader 5

Custom Indicator: OnCalculate Function Query

To add comments, please log in or register
tbaronetti
26
tbaronetti  

I am testing an MQL5 custom indicator on historical data using Strategy Tester. See below:

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

{

   int openLastElement=ArraySize(open)-1;

   Print("openLastElement="+openLastElement, " O="+open[openLastElement]," H="+high[openLastElement]," L="+low[openLastElement]," C="+close[openLastElement]);

   return(rates_total);

}

Second last (previous) bar on ST chart shows a bar O=1.0951, H=1.0951, L=1.0950, C=1.0950. (This bar is EUR/USD at 2015.08.03 23:59)

At this stage the next (current) bar being is being drawn and the only 1st tick of this new bar has been drawn on the chart. (This bar is EUR/USD at 2015.08.04 00:00) The data window shows the following values for this new bar:

O=1.0951, H=1.0951, L=1.0951, C=1.0951.

However, the above Print statement results show that the arrays (open, high, low, close) still contain the values from the previous bar. Only when the 2nd tick of the new bar arrives, do we see the results from the 1st tick n the arrays. For every new tick of each bar, the same is true: The arrays contain the information only up to the previous tick.

You can test it for yourself to see it for yourself, if you wish. Is this a bug or is MQL5 designed with this intention in mind?

Alain Verleyen
Moderator
33271
Alain Verleyen  

Forum on trading, automated trading systems and testing trading strategies


Hello,

Please use the SRC button when you post code. Thank you.


This time, I edited it for you.


Alain Verleyen
Moderator
33271
Alain Verleyen  
tbaronetti:

I am testing an MQL5 custom indicator on historical data using Strategy Tester. See below:

Second last (previous) bar on ST chart shows a bar O=1.0951, H=1.0951, L=1.0950, C=1.0950. (This bar is EUR/USD at 2015.08.03 23:59)

At this stage the next (current) bar being is being drawn and the only 1st tick of this new bar has been drawn on the chart. (This bar is EUR/USD at 2015.08.04 00:00) The data window shows the following values for this new bar:

O=1.0951, H=1.0951, L=1.0951, C=1.0951.

However, the above Print statement results show that the arrays (open, high, low, close) still contain the values from the previous bar. Only when the 2nd tick of the new bar arrives, do we see the results from the 1st tick n the arrays. For every new tick of each bar, the same is true: The arrays contain the information only up to the previous tick.

You can test it for yourself to see it for yourself, if you wish. Is this a bug or is MQL5 designed with this intention in mind?

You are wrong, check again (tested with build 1150).
To add comments, please log in or register