MetaTrader 4 Strategy Tester Tutorial

The Metatrader 4 platform contains an integrated Strategy Tester which can be used for backtesting Expert Advisors. This provides a way in which you can test out the strategy against historic market data. It it also includes the facility to optimize the settings of the expert advisor which will allow you to find the best combination of settings to trade with.

The most important variable in determining the accuracy of your tests will be be the quality of the data that you use. Incomplete or inaccurate price data will,  perhaps unsurprisingly, lead to incomplete and inaccurate results.

The purpose of this MetaTrader 4 strategy tester tutorial is to take you through the each of the steps that you will need to complete in order to generate a successful backtest. Now is also a good time to reiterate that the results you get will not necessarily be reflected in the results you see when you come to live forwarding testing your EA.

However what a backtest will provide is a ‘indication’ of potential performance and the opportunity to optimize your EA. This will let you try it out with different parameters and across different curency pairs in order to find its best performance.

Getting Started

Firstly you need to ensure that MetaTrader is able to process data correctly and secondly that the data used is of the best quality available to you.

Open up your MetaTrader platform and start by going to Tools menu/ Options. Then under the charts tab go to to the  ‘Max bars in history’ setting and enter 9999999999 (ten 9′s). This will default MetaTrader to display the maximum available history bars for testing purposes.

Then click on Ok to come out of this menu. You are now ready for the second step: Downloading the data.

The History Centre

Historic currency prices in MetaTrader are stored in the History Center. Here you download or import market price data to run your backtests against.You can access this by navigating to Tools/ History Center from the main MetaTrader tool bar menu.

metatrader-history-centre

To download data for the currency pair you want to test, first highlight the currency pair and select the 1 Minute (M1) option. Start the download by clicking the Download button. You will need to repeat this step for each currency pair that you intend to backtest against.

The data that is download will be served by your broker. The caveat here is that the integrity of this data will depend on the quality of the data that the broker stores. It is common for this data to contain ‘gaps’ and inaccuracies. Gaps are simply periods where data is ‘missing’ while inaccuracies tend to arise as the result of the way in which the data is calculated on ‘closed bars’.

This will inevitably degrade your results.

Getting hold of complete data is the preferred option. However not only can this be expensive, it can also make for a time consuming exercise in setting up the data and the subsequent testing. The trade off of course is that you will be able to produce more accurate results from your testing.

One of the best free sources of data available  is from Alpari UK. Although they no longer allow data downloads from their website, you can still gain access to this data via their demo accounts.

For most people trading with expert advisors this data will be more than sufficient to provide them with a way of performing a quick benchmark of past system performance.

Backtesting The Expert Advisor

In order to start backtesting your Expert Advisor you need to open up the Strategy Tester from the View menu in the MetaTrader terminal. The window that opens is where you will configure the parameters for your backtest.

 

metatrader-expert-advisor-test-settings

Setting up the EA for testing is straightforward enough. You simply need to select the parameters for your test from the following options available:-

Expert Advisor - The Expert Advisor to test

SymbolThe currency pair to test the strategy against

Model - Select ‘Every Tick.’ This gives you the most accurate modelling quality

Use Date - Tick this option and select the date range to run the test over

Visual Mode - Only check this box if you want a visual walkthrough of the test

Optimization - Leave unchecked for now

In order to get the most accurate results it is important that you use the ‘Every Tick Model’ and 1M (minute) tick data. This provides the lowest granularity of price data and will generate the most accurate simulation possible.

Once you have selected the parameters for your test click the Expert properties button.

metatrader-test-inputs

In the new dialogue box that opens you need to select the tab titled Inputs. Here you will find the parameters in the EA that you can run your tests again. If you want to change any of them you can do so by adjusting the input under the column headed Variable. (Note you don’t need to select any checkboxes here in order for the settings in the Value column to be used).

Once you are done click on OK to begin the test.

Backtesting an EA can take anywhere from just a few minutes to several hours to complete. The exact time will be dependent on the settings used, the timeframe of the test and the processing speed of your computer. It therefore makes sense to test over short periods of time to begin with. A few weeks or months would be good for example. This will give you an indication of performance before you commit to testing over extended periods.

Interpreting Your Metatrader Backtest Results

Once your test is complete you can access the results from the tabs at the bottom of the Strategy Tester window.

The most important of these is the Report tab. This gives you an overall summary of the test. As a snapshot it is useful in providing an instant indication as to whether the strategy settings are going to fly or not.

metatrader-backtest-results

The key things to note in this Report are:

Modelling quality – This helps verify the quality of the data used for testing. Unless you are using high quality data (usually paid for) you are unlikely to see more than a 90% modelling quality. This is an OK level and what we use at FX System Trader. If your modelling quality is significantly less than this figure it is advisable to find a better source of M1 tick data.

Total net profit – Here you can see the actual profit produced by the strategy settings over the selected testing period. This figure is made up from the Gross profit – Gross loss

Profit factor – The ratio of gross profit to gross loss. Higher is better, anything above 1.5 is good.

Absolute drawdown – The drawdown on your initial test deposit. A high drawdown figure will increase the likelihood that your account will be blown.

You can further analyse the results by making use of the Results and Graph tabs at the bottom of the screen.

The Results tab details each trading position taken. This is useful for drilling down results over particular time periods and making sure that the strategy is working as expected. The Graph tab offers a simple visual indication of your account balance across the course of the test period.

Congratulations! You have completed your first back test! You should how have an indication of the trading performance of your EA over the test period.

Now that you have a baseline of the performance the next stage is to Optimize your Expert Advisor.

Top Of Page

About the Author

FX System Trader is