Strategy Backtesting

Reading this page: 10 minutes.
Setting up your backtesting environment: 2-4 hours.
Data downloading and processing time: 1-3 days.
Backtesting and optimising EAs: 2 minutes to 10 hours – depending on the complexity of the Expert Advisor (EA) being tested.

What is backtesting then?

To cut a long story short, all we do is load an EA in MetaTrader’s Strategy Tester window, set the trading parameters and then run it against historical price data to see how it would have performed over the period set.

We can adjust trading parameters or run optimisation tests on many permutations of available settings to try to find the most  reliable ones over the longest period.

The aim being that knowing what worked well over many years should give us a good idea what might work well in future.

This is all easier said than done though, underlying this computer modelling is the maths of statistical analysis; meaning we need to make sure our results are as comprehensive as possible, based on real world data, so that the probabilities measured are statistically significant compared to the possibilities of random luck.

Tick-data backtesting

EA strategy testing and optimisation is only as useful as the quality of the data being used to backtest with.

You will find many system vendors online showing backtests with 90% quality – this means the strategy was only tested on the OHLC values for that timeframe’s bars/candles – perhaps because it is a lot quicker to do, and therefore quicker to find over-optimised parameters to sell the EA. (We’ll get on to over-optimising next).

Testing whole-bar data (90% quality) is only useful for strategies that just open and close trades on bar open and closes. For most strategies however, a trade can be opened or closed mid-bar – this means that we need to know whether price hit the high or low first. To do this we need to backtest our EAs against all the market ticks contained with the bars. This we call; tick-data backtesting (with 99% quality – nothing is perfect).

By default, the historical data in MetaTrader from your broker, or the history download centre, is not completely reliable for many reasons (and is normally somewhere between 40%-80% quality). It will often contain data gaps and spurious spikes that didn’t actually happen but are in this historical data due to interruptions to server connections etc. Therefore, we need to source high-quality historical price-data to import into our MetaTrader setup.

Setting up your backtesting environment

To set yourself up for reliable and extensive tick-data backtesting, we refer you to our old friend Birt and his website, Birt’s EA Reviews. As an experienced programmer, he has spent a significant amount of time researching data and developing a toolset to get that data into MetaTrader. There is a fair amount of reading and work to do but his site, methods and software are very well supported and tested. It is a lot quicker to follow his instructions than try and figure it all out for yourself.

For our tick-data testing environment we us an FX Pro MetaTrader installation (due to it’s GMT/BST +2h offset), with Birt’s toolset used to download, convert and install the tick-data – from both; Dukascopy servers for the last 5 years for 16 forex pairs; and from OANDA servers for the last 8 years for 6 forex major pairs (you need a live account with at least $1,000 deposited to access this). This gives us the best quality testing environment, and all for free using MetaTrader.

There are other platforms all this can be done with, like Trade Station and Ninja Trader, but when we started the costs were high and the data no better than we already had, so we have stuck with MetaTrader over the years because it works very well for us.

If you have the time to get setup, it is well worth the effort to give yourself the ultimate confidence in your EAs before trading them with live money, but be sure to read through the next pay on Optimisation vs Curve-Fitting to make sure you don’t get carried away. It is all too easy to think you’ve found the holy-grail the first time you see the enigmatic maximum profit figures, with a pretty rising equity curve to make your millions by this time next year, but there’s still a bit more to understand…