How to backtest an Expert Advisor in Metatrader
- What is a backtest
- The importance of backtesting to evaluate strategies
- How to backtest in Metatrader (Mt4)
Traders keep adjusting their trading strategies everyday by improving the way they buy or sell. They seek to improve their performances according to past experiences. Backtesting is something very similar. In fact backtesting is a way to estimate the performance of a strategy as if it had been employed during a past period. This requires simulating past conditions with sufficient detail, thus having very detailed and high quality historical data for the financial instrument you want to run your strategy on. Backtesting provides information not available for models and strategies tested on synthetic data, so the first thing you need is back test data before starting with backtesting.
Backtesting is a way to simulate strategies in the past and so providing the information of a working or not working strategy. Algotraders need to know how to backtest strategies, otherwise they could incur in overfitting or bad backtesting and get wrong results from their models. It is important to do backtesting the right way, so we will try to give some hints on how to backtest a trading strategy with the mql4 strategy tester, the Metatrader 4 backtesting tool. Backtesting has historically only been performed by large institutions and professional money managers due to the expense of obtaining and using detailed datasets. However, thanks to our high quality data offered at a really affordable price and independent web-based backtesting platforms like Metatrader 4, even retail traders can run backtests on a wider base.
According to our experience, when trading according to a manual strategy, a trader sees just a limited set of scenarios showing information of a partial period in the current past. A trader should have so much time available to run his strategy before understanding all the possible scenarios of the market and evaluate its robustness. This is why backtesting is so important. All the past scenarios are available in one shot and the results are immediately evaluable with the result of the backtest.
Since the backtest shows all the scenarios, it is possible to optimise the strategy just by analysing the results. Algotraders fine tune variables of their algorithms in order to optimise performances and run backtests again with improved variables’ values and obtain better performances.
A backtest creates even comparable data that will let you analyse the results of your real trading performances with the ones of the backtest. In short words by backtesting a trading strategy you create a benchmark that will help you analysing future performances in real trading.
Just to sum up, backtests tell you:
- How your strategy behaved in the past,
- How you can optimise the trading strategy behind the algorithm in order to improve performances
- What is the benchmark for your real trading performances when your algorithm will run for real in the market
Many traders are asking us how to start with backtesting. That’s why we decided to write a quick guide to help you all get started, explaining how to backtest an Expert Advisor in Metatrader 4 through a quick how-to on using the Strategy Tester feature of MT4.
First of all you need an Expert Advisor. You can learn how to code them, or just buying one from some trusted providers.
Once you have your Expert Advisor ready, open the Strategy Tester panel by clicking on View and then selecting Strategy Tester as it is shown by the following image.
A panel appears on the bottom of Metatrader platform.
Now you just need to follow these 7 steps:
- Pick up the Expert Advisor you chose from the list in the field called “Expert Advisor:”
- Select the financial symbol from the “Symbol” field and the timeframe you wish to backtest your strategy with from the field called “Period”.
Warning: remember to load historical data for the symbol you chose before going ahead, please read this short guide on how to load data in Metatrader if you do not know how to do it
- Choose the Model value. There are three possibilities according to your needs:
- “Every tick” lets you have a more precise backtest, but it is really slow because Metatrader reads Open, High, Low Close prices from historical dataset and generates random prices inside each candlestick, starting from the opening price until the closing one
- “Open Close Only” it’s a good parameter to run backtests if your strategy is a middle term one, you do not care about movements inside the single candlestick and you do not need reading High and Low prices. It is a really faster method and a good compromise if you need to run multiple tests for optimisation
- “Control Points” it’s a bad method because it is based on the nearest less timeframe and I suggest not to use it.
- Select the “Spread” according to your Broker fees. My suggestion is to backtest always with spreads two times bigger than the ones you really have to pay to your Broker. It is always better to backtest in a Worst Case Scenario. If you do not know this information, just select “Current” from the Spread field
- Do not flag the field “Use date” because it is just a way to reduce your backtesting date range. It will be useful for optimisations to run walk forward analysis and to avoid overfitting
- Do not flag “Optimization” button because you are running the backtest for the first time. You need to optimise the strategy later, in a second moment
- Click “Start” button and run your backtest
In this example I am running the backtests for the Expert Advisor called “High Potential Days” using EUR/USD 1-minute time frame for the full history loaded in my History Center.
Remember that as a golden rule, the higher the data quality the more accurate the backtest. We suggest to use 1 minute high quality data.
In a few time a graph called equity line should appear in “Graph” section. In the “Result” section you have all the parameters and past performances of your strategy, as it is shown by the next images.
The main parameters to be taken into account to evaluate a strategy are explained better in our algorithmic trading page
I hope this quick tutorial makes Expert Advisors a little less intimidating for newbies out there! If you have any questions, just post them in the comment box below. And for the expert traders around, I’m counting on you to help beginners out!
Knowing how to backtest a strategy is just the beginning of the path. Now you need to know how to optimise strategies with Metatrader 4 and how to deal with real trading, stay tuned