Blog

How to properly backtest RangeBars, MedianRenko, Renko and PointO using Tick Data with 99% modeling quality

This is a short guide on how to properly backtest EAs on Metatrader4 using Tick Data and price based charts such as RangeBars, MedianRenko, Renko, and PointO.

One of the most common mistakes when backtesting strategies on price based charts is not understanding how these very specific charts work and thus incorrectly performing backtests, which may lead to frustration when later finding out that actual trading results are not even close to what one may expect after witnessing a flawless backtest – even using Tick Data and obtaining a 99% modeling quality reading in MT4.

First of all, you should know that constant range price charts such as RangeBars, Median Renko, Renko, and PointO are all modeled charts, which in general means that the Open & Close prices for a vast number of bars are virtual. They are modeled to obtain a chart where individual bars have the same ranges (RangeBars) or the same body sizes (Median Renko, Renko, and PointO).

Such modeling is not a bad thing! It is what makes these price charts easier to trade, but on the other hand harder to backtest correctly using MT4’s backtester.

For example, Median Renko charts have the ability to smooth out indicator readings, which in return gives us clearer signals and less noise on the charts. However when backtesting such charts one should know that the Open price of every bar is virtual (a single tick that almost never existed), because it is shifted back to the middle of the previous bar’s body. However, the next tick is real and this is where EAs would place trades when live trading. Therefore, live trading will not be influenced in a negative way (even when using an EA). Backtesting MedianRenko charts is a different story – when done improperly, will give a false backtest. That is because EAs will have no problems opening trades using the virtual open price value of a new bar.

Here are two examples of a simple stop & reverse strategy backtest performed on a 20 pip Median Renko chart of EURUSD (01/2012 – 11/2012):

Notice the first backtest was performed using high quality tick data. However, the EA did not take into consideration the specific design of MedianRenko charts.

This second backtest was done correctly. It also utilizes the same strategy, same charts, same tick data, same signals, and the same number of trades, but this time trade execution was aware of the specific design of MedianRenko charts.

 

What happened? Where does the difference in performance come from?

Let’s take a closer look at the charts from both backtest results. As you can see below, the charts are the same and the same number of trades got executed (454 is the last ticket number)

On this chart, trades were taken at non-existing prices (the virtual open price of a MedianRenko bar). This gives us an extra 10 pips on all profitable trades and a 10 pip smaller loss on all losing trades.

Here trades were executed at real market prices (not the virtual open prices), which gives us results closer to the real deal*.

*) Live trades would only differ by any possible slippage in trade execution at the broker’s side.

Same principle applies to backtesting Renko, Range bars & Point Original charts.

 

OK, so what do you need to correctly perform backtesting on custom price based charts?

  1. Good quality tick data, which you can download from various sources in CVS format.
  2. A professional price based charting plug-in for MT4 (such as RangeBars, Median Renko, Renko, or PointO)
  3. A script to convert tick data into MT4’s data format using the corresponding price based charting plug-in (see individual plug-in pages: RangeBars, Median Renko, Renko, PointO) for details).
  4. Tools to utilize tick data in MT4’s backtester.
  5. An MQL code snippet, which will enable you to correctly backtest your strategy on price based charts.

The CustomChartingBacktest.mqh code snippet is part of the PRO versions of RangeBars, Renko, Median Renko & PointO plug-ins. It is already placed in the correct folder of your MT4 installation when you install any one of the plug-ins mentioned above.

You need to add the following two lines of code at the beginning of your EA source file. Somewhere at the top of the file include the code snippet into your EA by calling:

#include <CustomChartingBacktest.mqh>

and at the very top of the void OnTick() function add the following function call:

if(skipFirstTickOnBacktest()) return;

Top

 

10

Comments

  1. siriusfx  November 2, 2013

    Hey how accurate is this script is it really 99% accurate If i backtest with your script? Have you noticed any slight differences between your backtest script and live besides slippage?

    reply
    • admin  November 4, 2013

      The CSV2FXT script outputs an HST & FXT file pair, which is constructed using a provided historical tick data source (CSV file). The created files can be used by Tick Data Suite or Birt’s Patch to perform a backtest using MT4’s built in backtester and achieve very accurate backtests of EA’s on custom price action charts. The accuracy depends on your tick data source as every tick is included in the backtest.

      reply
  2. luvene  April 6, 2015

    Very interesting. I like Range Bars very much and I want to try PO bars. However it seems to me it is a little bit complicated to change something in the EA. I am not a programmer. Please, can you advice me what is the best quality tick data?

    reply
    • admin  April 6, 2015

      PointO charts don’t really require the changes in the EA to be made. The described changes are only mandatory for MedianRenko and Renko type charts due to the nature of these charts, where the opening price is shifted on reversals or even each bar.

      There are probably a few commercial sites that offer good quality tick data, but I find Dukascopy data source to be sufficient. There are a number of gaps in individual currency quotes, but personally, that does not bother me since I’m not tying to curve fit the results to an ideal dataset.

      reply
  3. Ebin Lazar  April 20, 2018

    I tried to load the script on to a 5.0 bar size with 1.0 retracement. The whole process went fine, I clicked OK after entering the desired settings and pop said UNABLE TO OPEN THE CSV file. I downloaded it in Tick Data Suite and exported it as explained in the video. Admin please advice. Thank you.

    reply
  4. Julian  July 11, 2020

    HI, You have 3 links About renko Bastesting with 99% modeling. I just buy “Renko & Tick charting plug-in for Metatrader 4 & 5” and now i need to do my backtesting. I used “Renko with Wicks” so i am confused i dont know the correctly way, ¿should i use tick data or rickstory lite or https://strategyquant.com/? Please some advice

    reply

Add a Comment