Testing Expert Advisor

MetaTrader 4 backtesting introduction

Bcktesting allows you to simulate trading over a long period of time in just minutes. There is considerable debate over the accuracy of MetaTrader's strategy tester. At best, backtesting offers only a close approximation of how trades would be executed in real-time. But it's the best tool we have to rapidly test any strategy over a wide range of trading situations, and one that you should learn how to use well.

Open the Strategy Tester in MetaTrader by clicking the appropriate button on the toolbar or by selecting Strategy Tester from the View menu.

History data

Before backtesting or optimizing, it's important to make sure that your history data is complete and accurate, especially if you're using Every tick as testing model. If you see mismatched chart errors in your Journal log or if your modeling quality is less than 90%, your history data is insufficient to generate accurate ticks.

Open the History Center from the Tools menu or by pressing F2 on your keyboard. Double click the chart pair in the left column that you plan to backtest for. A list of time periods will appear below. Start by double clicking on 1 Minute (M1) to load the history data for that period. The backtester uses M1 data to generate ticks, so it is important that your M1 data is complete.

MetaTrader History Center

Click the Download button to download the full history data for that pair and period. You may receive a Download Warning message - hit OK to continue. The history center will commence downloading. Repeat this process for every other time period and pair that you plan to test with.

You can also import history data into the History Center, using accurate historical price data from Alpari. The Alpari databank has M1 data for over a dozen popular currency pairs. Download and unzip the history data to your hard drive. Click the Import button in the History Center window, and then click Browse to select the history data file (.hst).

Expert Advisor settings

MetaTrader Backtesting of Expert Advisors

To test any our Expert Advisor, first select it from the Expert Advisor drop-down box. Select the currency pair from the Symbol box and chart period from the Period box. For Model, you'll generally must select Every Tick. Check the Use Date option and select a range of dates to test for.

Click the Expert Properties button to open the Expert Advisor settings. Under the Inputs tab is where you'll enter the range of settings to test for. All the Expert Advisors have the following settings:

Expert Advisors Settings
  • Version - current version information. Please keep up to date your Expert Advisor.
  • TradesID - identification number of orders made by Expert Advisor. This option is very important. If you are running several Expert Advisors on the same account, please be sure that this option is different on each Expert Advisor. Otherwise the behaviour of Expert Advisor is unpredictable.
  • Risk - the percent of account balance used to open every order. This value is in percent format. For example 0.03 means 3% of your account balance. Please keep in mind that increasing this value is not recommended.
  • ProtectEquity - account protecting option. The logic of all Expert Advisors keep your account from eventual drop. If your Equity fall down to this value the Expert Advisor will be stop trading. The recommended option value is 80% of your initial balance. For example if you start with 5000$ account, you must set this option to 80% x 5000 = 4000.

Under the Testing tab, you can adjust the Initial Deposit. Press OK button to close settings dialog and then press Start button to begin backtesting. It can take anywhere from a few minutes to several hours. If it's taking too long, consider shortening the date range.

Expert Advisor Graph

Backtesting

Once the optimization is finished, open the Report tab to see the results.

Expert Advisor Backtest

A few statistics to take note of:

  • Total net profit - The Gross profit minus the Gross loss.
  • Profit factor - The ratio of gross profit to gross loss. Higher is better, anything above 2 is acceptable.
  • Absolute drawdown - The drawdown of your initial deposit. High drawdowns increase the likelihood that your account will be blown out.
  • Profit trades - Your overall win percentage.
  • Modeling quality - Only important if your testing model is Every Tick. If so, this should be at 90%. If not, follow the instructions above to update your history with accurate M1 data.

The Results tab at the bottom of the strategy tester will give you the details on opened and closed orders, including trailing stop, take profit and stop loss. Click the Open Chart button to get a visual representation of your results.