MENU

Mastering the Art of Backtesting with MetaTrader

Backtesting is the process of evaluating a trading strategy or model by testing it on historical data. It involves simulating the application of the strategy or model to past market conditions and evaluating the performance of the strategy or model based on the results. Backtesting can be a useful tool for traders and investors to assess the potential risks and returns of a strategy or model and to determine whether it is likely to be successful in live market conditions.

There are a few different approaches to backtesting, including manual backtesting and automated backtesting. Manual backtesting involves manually applying the strategy or model to historical data and evaluating the results by hand. This can be a time-consuming and error-prone process, but it can be useful for getting a sense of how a strategy or model would have performed in the past. Automated backtesting involves using software to apply the strategy or model to historical data and evaluate the results. This can be much faster and more accurate than manual backtesting, but it may not be suitable for all types of strategies or models.

Backtesting can be an important part of the trading process, but it is not a foolproof method of evaluating a strategy or model. It is important to keep in mind that past performance is not necessarily indicative of future results, and that backtesting results should be taken with a grain of salt. In addition, it is important to consider the limitations of backtesting, such as the fact that it is based on historical data and does not take into account the effects of market changes or changes in the strategy or model.

Backtesting in MT4

The Strategy Tester in MT4 is a tool that allows you to test and evaluate the performance of an EA (Expert Advisor) on historical data. To access the Strategy Tester, go to the “View” menu and select “Strategy Tester” or press Ctrl+R. The Strategy Tester window will appear at the bottom of the screen.
There are several options that you can adjust in the Strategy Tester to customise your backtesting:

  • Expert Advisors: This tab allows you to select the EA that you want to test. You can choose from a list of EAs that are installed on your MT4 platform.
  • Symbol: This is the currency pair that you want to test the EA on. You can select a currency pair from the dropdown menu.
  • Period: This is the time frame that you want to test the EA on. You can choose from a variety of time frames, such as M1 (1 minute), M5 (5 minutes), M15 (15 minutes), etc.
  • Model: This tab allows you to set the backtesting period and specify how the EA should be tested. Under the “Model” dropdown menu, you can choose between “Every tick based on real ticks” and “Every tick based on M1 history”. The “Every tick based on real ticks” option is more accurate, but it takes longer to run. The “From” and “To” fields allow you to set the start and end dates for the backtesting period.
  • Inputs: This tab displays the input parameters for the EA, such as the lot size, stop loss, and take profit. You can adjust these parameters to see how they affect the EA’s performance.
  • Visual Mode: This option allows you to see the EA’s trades on the chart. When this option is enabled, the EA’s trades will be displayed on the chart as arrows.
  • Optimisation: This tab allows you to optimise the EA’s input parameters. You can specify a range for each parameter and the Strategy Tester will find the optimal values that resulted in the best performance during the backtesting period.

Once you have adjusted the options to your liking, click the “Start” button to begin the backtesting process. While the backtesting is running, you can monitor the progress in the “Journal” tab. Once the backtesting is complete, you can view the results in the “Results” tab.
Here are some things to look for in the test results:

  • Profit and loss: This is the most important metric, as it shows how much money the EA made or lost during the backtesting period.
  • Win rate: This is the percentage of trades that were profitable. A high win rate doesn’t necessarily mean the EA is good, as it could be making small profits on many trades and still not be profitable overall.
  • Risk to reward ratio: This is the ratio of the average profit to the average loss. A higher ratio means that the EA is making more profit on its winning trades compared to the losses on its losing trades.
  • Drawdown: This is the maximum percentage of the account balance that was lost during the backtesting period. A high drawdown means that the EA is taking on a lot of risk, which could lead to significant losses.

It’s important to keep in mind that backtesting results are not a guarantee of future performance. There are many factors that can affect the performance of an EA, such as market conditions, spreads, and execution speed. As such, it’s always a good idea to test an EA on a demo account before using it with real money.

By default, MetaTrader 4 (MT4) uses a simulated tick algorithm to generate prices for the innermost 1-minute (M1) bars. However, it is possible to import real tick data into MT4 using a separate application or script. EvoAI is a tool that allows users to quickly and easily access high-quality tick data for forex markets and import it into MT4. It also offers fast download and export speeds for added convenience. Download EvoAI

Walk-Forward Backtesting

Walk-forward backtesting is a method of evaluating the performance of a trading strategy or model that involves dividing the data set into training and testing periods. The training period is used to build the model or strategy, while the testing period is used to evaluate the performance of the model. The key difference between walk-forward backtesting and traditional backtesting is that the model is re-trained and re-evaluated at periodic intervals using new data. This process is repeated for each period in the testing data set.

There are several benefits to using walk-forward backtesting. First, it helps to ensure that the model is robust and able to adapt to changing market conditions. Second, it allows for a more realistic assessment of the model’s performance, as it takes into account the fact that real-world models need to be updated and re-evaluated over time. Finally, it allows for the optimisation of model parameters, as the model can be re-trained and re-evaluated with different parameter settings to find the best combination.

Overall, walk-forward backtesting is a valuable tool for evaluating the performance of trading strategies and models, and can help traders to better understand the potential risks and returns associated with their strategies.

Backtesting in MT5

To backtest a trading strategy in MetaTrader 5 (MT5), follow these steps:

  • Open the MT5 platform and click on “Strategy Tester” in the top menu.
  • Select the currency pair and time frame for the backtest.
  • Choose the expert advisor (EA) or trading strategy that you want to test from the “Expert Advisors” tab.
  • In the “Symbol” and “Period” fields, select the currency pair and time frame for the backtest.
  • In the “Model” field, select the type of testing you want to perform. The options are “Every tick based on real ticks” and “Control points based on open prices.” The “Every tick” option is more accurate but takes longer to complete, while the “Control points” option is faster but less accurate.
  • In the “Period” field, select the date range for the backtest. You can either choose a predefined range or enter custom start and end dates.
  • In the “Spread” field, select the spread that you want to use for the backtest. The options are “Current”, “Fixed”, and “Variable.” The “Current” option uses the current spread as of the start date of the backtest, while the “Fixed” and “Variable” options allow you to enter a custom spread.
  • In the “Optimisation” tab, you can specify any optimisation parameters for the EA or strategy. This allows you to test different combinations of parameter values to find the optimal settings for your backtest.
  • Click the “Start” button to begin the backtest.

Once the backtest is complete, the results will be displayed in the “Tester” window. There are several key metrics to look for in the results:

  • Profit: This is the net profit or loss for the backtest period.
  • Balance: This is the total equity in the account at the end of the backtest period.
  • Drawdown: This is the maximum decline in the balance from a peak to a trough.
  • Trades: This is the number of trades that were executed during the backtest period.
  • Win rate: This is the percentage of trades that were profitable.
  • Profit factor: This is the ratio of the total profit to the total loss for all trades.

By analysing these metrics and others, you can get a sense of how well the EA or strategy performed during the backtest period. It’s important to keep in mind that past performance is not necessarily indicative of future results, and that backtesting results should be taken with a grain of salt.

MetaTrader 5 (MT5) is able to take advantage of multiple CPU threads and networked computers to speed up the testing process, but it can be resource-intensive, especially for long-term tests that use a high number of data points (called “ticks”). This can lead to the consumption of a large amount of memory for each CPU thread. While this can be beneficial for some types of tests, it may not be practical or cost-effective for all users.

Installing Expert Advisors

To install an expert advisor (EA) in MetaTrader 4 (MT4), follow these steps:

  • Download the EA file to your computer. The file should have a “.mq4” or “.ex4” extension.
  • Open the MT4 platform and click on “File” in the top menu.
  • Choose “Open Data Folder” from the dropdown menu. This will open the MT4 data folder in Windows Explorer.
  • Navigate to the “MQL4” folder and then to the “Experts” folder.
  • Copy the EA file into the “Experts” folder.
  • Return to the MT4 platform and click on “View” in the top menu.
  • Select “Navigator” from the dropdown menu. The “Navigator” window will appear on the left side of the screen.
  • Expand the “Expert Advisors” folder in the “Navigator” window.
  • Right-click on the “Expert Advisors” folder and choose “Refresh” from the context menu.
  • The EA should now appear in the “Expert Advisors” folder. To attach it to a chart, simply drag and drop it onto the chart.

Alternatively, you can install an EA by double-clicking on the EA file in Windows Explorer. This will open the MT4 platform and automatically install the EA.

Keep in mind that not all EAs are compatible with MT4, and some may require additional setup or configuration before they can be used. It is also important to exercise caution when installing EAs, as some may contain malicious code or perform poorly. It is always a good idea to thoroughly research an EA before installing it and to use it at your own risk.

Expert Advisor Optimisation

To optimise an expert advisor (EA) in MetaTrader 4 (MT4), follow these steps:

  • Open the MT4 platform and click on “Strategy Tester” in the top menu.
  • Select the currency pair and time frame for the optimisation.
  • Choose the EA that you want to optimise from the “Expert Advisors” tab.
  • In the “Symbol” and “Period” fields, select the currency pair and time frame for the optimisation.
  • In the “Model” field, select the type of testing you want to perform. The options are “Every tick based on real ticks” and “Control points based on open prices.” The “Every tick” option is more accurate but takes longer to complete, while the “Control points” option is faster but less accurate.
  • In the “Period” field, select the date range for the optimisation. You can either choose a predefined range or enter custom start and end dates.
  • In the “Spread” field, select the spread that you want to use for the optimisation. The options are “Current”, “Fixed”, and “Variable.” The “Current” option uses the current spread as of the start date of the optimisation, while the “Fixed” and “Variable” options allow you to enter a custom spread.
  • In the “Optimisation” tab, specify the parameters that you want to optimise. You can choose from a list of predefined parameters or create your own.
  • Click the “Start” button to begin the optimisation.

The optimisation process will run through a series of iterations, testing different combinations of parameter values to find the optimal settings for the EA. When the optimisation is complete, the results will be displayed in the “Tester” window. You can use the “Results” tab to view the profit, drawdown, and other metrics for each iteration. You can also use the “Graph” tab to visualise the performance of the EA with different parameter settings.

To apply the optimal parameter settings to the EA, click on the “Expert Advisors” tab in the “Navigator” window and drag the EA onto a chart. In the “Inputs” tab of the EA’s properties window, you can enter the optimal parameter values.

Keep in mind that optimisation is not a guarantee of future performance, and that it is important to carefully evaluate the results of the optimisation before making any trading decisions. It is also important to note that optimisation can lead to overfitting, where the EA is optimised for a specific data set but performs poorly on new data. To avoid overfitting, it is a good idea to use a separate data set for optimisation and to test the EA on out-of-sample data.

EvoAI is a tool that can be used to optimise expert advisors (EAs) for the MetaTrader 4 (MT4) platform. One of the key features of EvoAI is its ability to optimise EAs much faster than MT4 by using all CPU cores.

In MT4, the optimisation process runs on a single core by default, which can be slow for complex EAs or for optimisation over a large data set. EvoAI solves this problem by using all available CPU cores to parallelize the optimisation process. This allows EvoAI to significantly speed up the optimisation process and find the optimal parameter settings for an EA much faster than MT4. Download EvoAI