MetaTrader you had one job - inconsistencies when backtesting (visual vs. non visual) - page 3

 
hematinik #:
Yes of course, that's the first thing I always do. complete logging is the first thing I always do.  as you correctly pointed out it was the indicator readings but I couldn't figure out Why that thing keeps happening only inside non-visual tester. that was the very core of my question

"Why" was explained from very beginning.

If you don't have an access to the source code of the indicator, you could possibly try to create your own wrapper indicator for it, and insert tester_everytick_calculate directive into it, but I'm not sure if this helps. Just an idea.

PS. Looking at the screenshots I suppose you can find similar indicators with open source.
 
Stanislav Korotky #:

"Why" was explained from very beginning.

If you don't have an access to the source code of the indicator, you could possibly try to create your own wrapper indicator for it, and insert tester_everytick_calculate directive into it, but I'm not sure if this helps. Just an idea.

PS. Looking at the screenshots I suppose you can find similar indicators with open source.

Sure it got solved early on and that specific indicator is not a big deal. the rest is just our discussion about the underlying logic that allows for such problem, in which you can have a perfectly working EA inside live chart and visual backtester but not in the non-visual tester with the same configuration.

And the Idea, It should work I believe. if so it would recompense the non-visual tester's *not respecting* every tick modeling.

 
Stanislav Korotky #:

If you don't have an access to the source code of the indicator, you could possibly try to create your own wrapper indicator for it, and insert tester_everytick_calculate directive into it, but I'm not sure if this helps. Just an idea.

PS. Looking at the screenshots I suppose you can find similar indicators with open source.

Here is a follow up, if somebody will be interested in.

If you don't have source codes of an external indicator, but want to force it recalculate on every tick in non-visual tester, try to add the following macro into very beginning of OnTick (or other trading-triggerring, like OnTimer) event handler in your EA.

#define FORCE_TESTER_CALCULATE(H) if(MQLInfoInteger(MQL_TESTER) && !MQLInfoInteger(MQL_VISUAL_MODE)) { static double dummy[1]; CopyBuffer(H, 0, 0, 1, dummy); }

...

void OnTimer()
{
   MqlTick tick;
   if(!SymbolInfoTick(_Symbol, tick)) return;
   FORCE_TESTER_CALCULATE(handle); // handle is the indicator handle
   ...
   // irrespective of using or not FORCE_TESTER_CALCULATE, it's better to do these check-ups to make sure everything is in sync:
   // * BarsCalculated(handle) == Bars(_Symbol, _Period) for every related symbol/timeframe/handle
   // * tick.time >= iTime(_Symbol, _Period, 0) && tick.time < iTime(_Symbol, _Period, 0) + PeriodSeconds(_Period)
   ...
   // trade by signals of the indicator
}