Inconsistent backtest results

 

Yet another quirk of MT5, with exactly the same conditions the visual tester does the job right while the non-visual tester opens a position when it shouldn't.

I'm having a very deep look into this and there's no "randomness" in the code.

- I tried all modeling methods (everytick, 1 min ohlc, etc..)

- verified buffer reads for the bar and it was all okay. the buffer values in the visual tester and non-visual tester match at the time of the trade

Im not sure, maybe the non visual tester does not apply one of my indicators buffer shifts or it is caused by multi-threading the process.

Averaging Price Series for Intermediate Calculations Without Using Additional Buffers
Averaging Price Series for Intermediate Calculations Without Using Additional Buffers
  • www.mql5.com
This article is about traditional and unusual algorithms of averaging packed in simplest and single-type classes. They are intended for universal usage in almost all developments of indicators. I hope that the suggested classes will be a good alternative to 'bulky' calls of custom and technical indicators.
 

Hard to tell what it is. Are you using custom indicators? I had a problem like this once. The indicator worked normally in the visual test, but it had a glitch that would make it not work properly in non-visual test mode, thus the results were different.


If possible, share some code so that we can reproduce the error (not necessarily your EA, but a new one where the error also occurs). 

 
Emanuel Cavalcante Amorim Filho #:

Hard to tell what it is. Are you using custom indicators? I had a problem like this once. The indicator worked normally in the visual test, but it had a glitch that would make it not work properly in non-visual test mode, thus the results were different.


If possible, share some code so that we can reproduce the error (not necessarily your EA, but a new one where the error also occurs). 

Thank you for the response.

I was able to figure out what is causing the problem but not the solution yet.

-   Im using the standard iMA(), when I set PRICE_CLOSE for the applied price there will be contradictory buffer reads with more than 100 points difference in EURUSD resulting in a false positive.

-   the iMA() is reading values from higher timeframe (H6) and it reads correctly in the live chart and the visual tester. by "correct" I mean if I go to the original timeframe the values are the same as the lower timeframe (H1).

-   the moving average is shifted by one higher timeframe bar ( 6 x H1 bars ) so there shouldn't be a problem of repaint

-   the buffer values for PRICE_HIGH and PRICE_LOW are consistent in all situations

-   the EA is being calcualted for every bar open

So given that every other buffer read is consistent, maybe there's a problem with the calculation of bar close from H6 ?


P.S.

I haven't posted the code as it is somewhat large and hard to track. the schematic of my code base is like this:

A wrapper indicator calls 3 iMA() functions and does the extra buffer calculations - then the EA imports the wrapper indicator using iCustom.

this is how the wrapper indicator reads from higher timeframe (simplified)

    for (int i = 0; i < copy_bars; i++) {

        // declare swap buffers
        double arc_mid_swap[1];

        // copy buffer data
        if ((CopyBuffer(arc_mid_handle, 0, time[i], 1, arc_mid_swap) < 1)) return(0);

        arc_mid_buffer[i] = arc_mid_swap[0];
    }
Reason: