Warm tip: This article is reproduced from serverfault.com, please click

Why MQL4 Backtest RSI values do not match with RSI on chart?

发布于 2020-12-09 14:58:29

I have a simple backtest of below EA:

    void OnTick()
    {
       double rsi = iRSI( Symbol(), PERIOD_M5, 14, PRICE_CLOSE, 0 );
       
       int day  = TimeDay(    TimeCurrent() );
       int hour = TimeHour(   TimeCurrent() );
       int min  = TimeMinute( TimeCurrent() );
       if (  day  ==  7
          && hour >=  9
          && hour <  11
             ) {      
          Print( Symbol(), " / ", PERIOD_M5, " rsi: ", (string) rsi );
       }
    }

However, the backtest log seems does not match with show in the chart as this image:

enter image description here http://i.imgur.com/PRhtvQD.png

Could you please give some explanation?

Questioner
dvn0zzz
Viewed
0
user3666197 2020-12-10 01:47:10

Q : "Could you please give some explanation?"

Sure, your code calculates & updates a printed RSI(14)-value (per-tick)

Kindly notice, that the previous bar 08:55 has finished with RSI(14)-value well above the HLINE ~ 30% (if in doubts, one can initially Print( iRSI( Symbol(), PERIOD_M5, 14, PRICE_CLOSE, 1 ) ); where you will see the "previous"-bar value numerically.

From about that value ( above ~ 30% ) the newly opened bar [0] will start to "develop" the actual RSI(14)-value, inside the new bar. So, initially, the values will "move" and the graph plots / redraws the line ( we can visualise each such change as a dot, marker or a Hi/Lo-range ), which is THE REASON, why we finally see a blue line fallen to the position, where the Close[0] has "finished" upon exiting of the bar under review (the 09:00 one, at about the 09:04:59:9999 time).