Different value from the indicator on the same day while debugging on historical data and running strategy tester.
Hello, I am testing ea using iCustom function to pull data from indicator. But I found some discrepancies in the data that indicator gave on the chart vs iCustom function on the same date. I thought that my ea had some bug and run the debugging on the same date and while running code step by step it gave me correct value on that particular date ( same as indicator on the chart window). But when I run strategy tester using the same ea values are differ from the indicator on the chart... I don't know why it is behaving like that. Actually, while debugging all the values are identical to what indicator is giving, and while running strategy tester all the values are way off from what it should be. Is there some sort of buffer that I need to reset every time I call iCustom or something?
I found the reason and solution to my issue. To my embarrassment it all was written in a MQL5 help file :
Testing Trading Strategies"The Calculation of Indicators During Testing
In the real-time mode, the indicator values are calculated at every tick.
In the Strategy Tester, indicators are calculated only when they are accessed for data, i.e. when indicator buffer values are requested. The only exceptions are custom indicators with the specified #property tester_everytick_calculate. In this case, recalculation is done on each tick.
In the visual testing mode, all indicators are unconditionally recalculated when a new tick arrives in order to be correctly displayed on the visual testing chart.
The indicator is calculated once per tick. All subsequent requests for indicator data do not lead to recalculation until a new tick arrives. Therefore, if the timer is enabled in an EA via the EventSetTimer() function, the indicator data is requested from the last tick before each call of the OnTimer() handler. If the indicator has not been calculated on the last tick yet, the calculations of the indicator values are launched. If the data has already been prepared, it is provided without a new recalculation.
Thus, all indicator calculations are performed in the most resource-saving manner — if the indicator has already been calculated at a given tick, its data is provided 'as is'. No recalculation is launched."
Solution to my issue was to modify my indicator by adding #property tester_everytick_calculate .
I found the reason and solution to my issue. To my embarrassment it all was written in a MQL5 help file :
Testing Trading Strategies"The Calculation of Indicators During Testing
In the real-time mode, the indicator values are calculated at every tick.
In the Strategy Tester, indicators are calculated only when they are accessed for data, i.e. when indicator buffer values are requested. The only exceptions are custom indicators with the specified #property tester_everytick_calculate. In this case, recalculation is done on each tick.
In the visual testing mode, all indicators are unconditionally recalculated when a new tick arrives in order to be correctly displayed on the visual testing chart.
The indicator is calculated once per tick. All subsequent requests for indicator data do not lead to recalculation until a new tick arrives. Therefore, if the timer is enabled in an EA via the EventSetTimer() function, the indicator data is requested from the last tick before each call of the OnTimer() handler. If the indicator has not been calculated on the last tick yet, the calculations of the indicator values are launched. If the data has already been prepared, it is provided without a new recalculation.
Thus, all indicator calculations are performed in the most resource-saving manner — if the indicator has already been calculated at a given tick, its data is provided 'as is'. No recalculation is launched."
Solution to my issue was to modify my indicator by adding #property tester_everytick_calculate .
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello, I am testing ea using iCustom function to pull data from indicator. But I found some discrepancies in the data that indicator gave on the chart vs iCustom function on the same date. I thought that my ea had some bug and run the debugging on the same date and while running code step by step it gave me correct value on that particular date ( same as indicator on the chart window). But when I run strategy tester using the same ea values are differ from the indicator on the chart... I don't know why it is behaving like that. Actually, while debugging all the values are identical to what indicator is giving, and while running strategy tester all the values are way off from what it should be. Is there some sort of buffer that I need to reset every time I call iCustom or something?