Backtesting a strategy with MetaTrader 4

Before launching an expert advisor (EA) on a real account, it is important to test it on historical data to evaluate the performance of the trading system.

MetaTrader 4 trading software features a strategy tester that can simulate performance over a defined period of time. It is also possible to optimize the parameters of the EA to find the optimal settings of the strategy for each currency pair.

The reliability of MT4's strategy tester is often criticized due to the inaccuracy of the data provided by brokers. Backtest results can therefore be approximate.

Despite these shortcomings, a backtest with MetaTrader provides valuable information on past performance. The backtest is a necessary step before launching an EA on a demo account, and then on a real account.

Historical data of the currency market

In order for MetaTrader to use the maximum available historical data, go to the menu of the MetaTrader 4 platform (Tools / Options), then go to the Charts tab. Enter the maximum value​in the Max bars field 9 999 999 999.

Historical forex data is accessible from the menu (Tools / History Center). The interface allows one to download the data needed to perform a backtest.

MetaTrader History Center

The data is provided by forex brokers, but most of the time it is not accurate. Gaps in the data can lead to errors, so it is recommended that you test several brokers to find the most reliable data possible. It is also possible to download data from MetaQuote from this window.

The MT4 strategy tester

Open the tester strategy in the menu (View / Strategy Tester). This window allows you to configure the parameters of the backtest.

MT4 Tester

Select the parameters according to the available options: the choice of the EA, the currency pair, the chart's time frame, the model (select "Every Tick" for greater accuracy), the dates of the test period, and visual mode in order to see the progress of the strategy in real-time on the chart.

You can optionally click on "Expert properties" to change some settings. In the "Testing" tab, you can define the account's deposit amount and currency. The "Positions" field is not really useful. The second part of this tab is for the optimizer of the MT4 strategy.

MT4 Test

In the "Input parameters" tab, you can change the parameters in the "Value" column. The remaining columns are used for the strategy optimizer.

MT4 backtest

Click on "initial value" in the strategy tester's window to launch the test.

Interpreting the results of an MT4 backtest

When testing is complete, you can access the results from the tabs at the bottom of the strategy tester's window.

The report tab displays a detailed analysis of the results. You can save it by right-clicking on the table.

Results of MT4 backtest

The quality of the modeling is an important element that allows you to verify the accuracy of the data used for the test. Generally, the quality does not exceed 90% unless you can afford to purchase very reliable data.

You can also analyze the results using the following tabs:

Performance graph

Backtest graph

Transaction details

Backtest results

The journal to see if there are any errors

Backtest journal

 

To improve the parameters of an EA, visit the Optimise an MT4 Expert Advisor page