Backtesting is a convenient way for showing what could have happened had your trading system traded through the past. Backtesting in Metatrader 4 leaves some things left desired.
Caveats With Backtesting in Metatrader 4
For starters, Metatrader 4′s backtesting engine can only backtest to 1 minute accuracy. In a given minute, there could be as many as 110 ticks (as per my measuring). Those fluctuations in price are not always captured accurately in Metatrader 4′s backtester. If your trading system has trades that are open maybe 30 minutes or less on average, there is a good chance that they are not accurately represented.
Calculation of the spread is also not particularly accurate. Metatrader 4 as of build 416 seems to use the most recent spread for a given currency pair. That means during the week–when the spreads tend to be smaller–most backtests will show a better result than backtests performed during the weekends–when spreads are at their widest.
The biggest problem is backtesting multiple currency pairs. There are a growing number of trading systems which take advantage of high positive or negative correlation between currency pairs in an effort to achieve higher returns. Metatrader 5 attempted to compensate for this, but that step forward was significantly hindered by numerous other limitations that I’d rather not go into.
How to Setup the Best Backtest Within Metatrader 4
Above all else, there is one thing that you need to make sure you have if you expect to have an accurate backtest. The finer the data, the more accurate your results. The absolute best source of data is recorded price data. The problem with this datasource is it’s often incredibly expensive, and time consuming. The most accurate free and reliable source of data available can be found here: (http://www.forextester.com/data/datasources.html)
I generally keep a dedicated metatrader terminal strictly for backtesting. It’s a lot easier to manage the data.
Clear Out Old Data
The first thing you should do is remove any old and potentially gapped data. To do this, you need to:
- Exit Metatrader Terminal if you haven’t done so already.
- Navigate to the [MetatrderFolder]\History folder.
- Select the folder with the same name of the server you are using.
- Delete all .hst files associated with the currency pair that you intend to test.
Acquire and Add New Data
Once you’ve cleared out the old data, you need to acquire and import the new data.
- Download the most continuous data possible. This is the best place to get free minute-level data (http://www.forextester.com/data/datasources.html)
- Unzip the file.
- Start Metatrader Terminal
- Press F2 or go to Tools -> History Center
- Navigate to the currency pair and the 1M (one minute) timeframe.
- Click Import
- Load the file you unzipped in step 2.
- Look for the input relating to GMT shift. You need to make sure the data you receive is shifted accordingly to match with your broker.
- Click OK to import the data. Note: It may appear that Metatrader 4 isn’t working properly, or has frozen. To check, open up Task Manager (Ctrl+Alt+Del), go to the process tab, and look for ‘Terminal.exe’. If that process is using up CPU and RAM, then Metatrader 4 is still working. To import 10 years of data takes somewhere in the neighborhood of 5-10 minutes if you have a fast computer.
- Once you’ve imported the data you need to convert it. Exit out of the history center, and open up a chart on the 1 minute timeframe for the currency pair you just imported.
- Look for the script ‘Period_converter’ and attach it to the chart.
- The script will ask you for a multiplier input. Make sure to set up the proper multiplier for the timeframe you intend to backtest in. What this script will do is it will take the 1 minute data, find the open, high, low, and close of the data in a specific time range, and use that data to create the open, high, low, and close of the higher timeframe.
Once you’ve completed the data import and conversion, you have given yourself the cleanest data possible to perform the backtest of your EA(s).