Blog

Backtesting Range Bars in Metatrader 4

This page is obsolete and no longer maintained. Please browse the blog article for information regarding backtesting on different custom charts.

For MT4 build 574 and higher, this backtesting script names are suffixed with “_b574”. Therefore, you should be using RangeBarsBacktesting_b574 and RangeBarsBacktestingAlt_b574 scripts with the latest MT4 builds.

The backtesting feature for RangeBars is available via RangeBarsBacktesting script, which is part of the RangeBars plug-in for Metatrader4 and is located in the Navigator window’s Scripts branch, once you install the range bars plug-in package.

This backtesting method is mainly designed for backtesting EAs that use completed bars to calculate trading decisions. You should use the “Open prices only” model in MT4’s strategy tester. Scalping EAs and EAs that rely on inter-bar price action should be tested using tick data.

When you double-click the script or drag it onto the selected instrument’s chart you will see the following backtesting options:

The meaning of individual variables are described below:

BactestingRangeBars – This is used to select one or more pip ranges that should be prepared for backtesting using all historical data available in MT4 (on the 1-minute chart). The values should be separated by a comma.

i.e. 3,13,20 = 3 pip range, 13 pip range, 20 pip range.

BacktestingSpreadInTicks – This is used to select the spread value that should be used for backtesting. This value is entered in ticks so if your broker has 5 decimal quotes you should enter 20 for a 2 pip spread.

StartFromBar – This variable defines the number of historical bars, which will be used to create the range chart for backtesting. It is set by providing the date & time of the first 1M bar used to calculate the first historical range bar for backtesting.

The default value of “1970.01.01 00:00” will result in using all available data on the 1M chart.

BackTestingServerName – This is the name of the virtual MT4 server that will be created and you will need to login to, to use range bars with MT4’s backtester module.

Once you set the values above and press [OK], the script will begin to set up the virtual server for backtesting. Once this procedure is completed you will see the following message:

Now you can log in to the “range” server by choosing Logon from MT4’s File menu. This will display the following pop-up window:

Now, simply enter “range” in the Server field and click [Login]. Your MT4 should now show “No connection” (this is normal).

Next, you need to shout down MT4 and reopen it again.
This time you will see the selected range bar symbols ready for backtesting in your Market Watch window:

Now you can open MT4’s strategy tester, select the Expert Advisor you wish to test and select the range bar value to be used by the backtester:

IMPORTANT! – Always choose M5 for the period used for backtesting as the range bar chart is stored in this time frame.

Interested in 99% modeling quality, reliable, tick-by-tick backtesting? Click Here

9

Comments

  1. ben  August 31, 2012

    hi i just loaded the backtesting script and kept ‘RenderUsing1MhistoryBars’ at 0, I do not see all bars (4781) of the 1 min chart being used, i only see 93 bars when i change to range sever. what is the point of this?
    when backtesting an ea using only 93 bars it only gets to make one order not able to modify or close. please explain.

    reply
    • admin  September 2, 2012

      This parameter is used to determine the number of 1M bars that will be used to create historical range charts. This number will never be equal to the number of created range bars. In most cases (depending on your range setting), several 1M bars will make up one constant range bar. You should see this video, if you need more range bars in your history.

      reply
  2. ben  August 31, 2012

    do i need to wait for my custom range chart to make more bars? or do i need to add the backtesting script to my custom chart instead of m1 (your pdf does not say)? the main reason i bought you product was for the backtesting as i already have range bars enabled but could not backtest, so backtesting is most important to me!

    reply
  3. ben  August 31, 2012

    I like your feature to make multiple range bar charts from m1 data!

    reply
  4. Noz  January 8, 2013

    Is it possible to create range bars without using/having an offline chart? Or better explained: if there is already an offline chart created based on a fx index (and not based on range, ticks or whatever) and you would like range bars for this fx index, is that possible?

    reply
    • admin  January 9, 2013

      Not sure if I understand you correctly. You would like to create range charts using data that is available on an offline chart?

      reply
  5. Jamie  April 21, 2015

    I am doing a trial at the moment and I will buy this product if it can do the back testing, but at the moment it won’t work due to no “history data” according to the Journal log. I downloaded the CSV file using SQ Tick Data downloader and then converted the CSV file using the Birt modified CSVFXT_rangebars_mod_Alt_b574 script. I applied the RangeBarsBacktestingAlt_b574 script to enable the back testing. Logged in to the virtual “range” server, then restarted to start the Strategy Tester using an M5 timescale with the modified EA including script references. I checked the \tester\history where there are 4 files and 3 of them have no size. The large file is obviously the one used when logged in the broker’s server and I can go back a few years in history on the range bar chart and it looks fine. The MarketWatch is displaying the three range bar versions too.

    21/04/2015 18:19 0 EURUSD18r1_0.fxt
    21/04/2015 18:18 0 EURUSD18r5_0.fxt
    20/04/2015 19:31 5,307,365,280 EURUSD1_0.fxt
    21/04/2015 18:32 0 EURUSD3r5_0.fxt

    As you can see I have followed the instructions very carefully and I have no idea why it doesn’t work and I’m getting a bit frustrated now having spent many hours on this.
    Please advise.

    Thanks.

    reply
    • admin  April 21, 2015

      Please note that there are two different backtesting methods. One uses tick data as the data source for building range bars and the other one used 1 minute data from your broker. From what I see, you are using a mix of the two methods and this just will not work. Since I see that you have already downloaded tick data, please use the more precise method of tick data backtesting, which is described in in the following blog post:

      Backtesting EAs using tick data

      Please note that this method needs Birds Tick Data Suite as a loader to perform the backtest and will not work without it.
      If you don’t have tick data suite, you can use a different loader, which is part of TickStory. You can read more on this topic in the following post:

      Using TickStory as a loader.

      reply

Add a Comment