How to Backtest Your Expert Advisor on MetaTrader 4 - XAUBOT

How to Backtest Your Expert Advisor on MetaTrader 4

How to Backtest in MetaTrader 4?

When you have decided to use automated trading solutions, you need to consider any precaution and go through all the due diligence to make sure that the process of trading is safe, secure, and not overly exposed to unnecessary risks. In the case of Expert Advisors (EAs) with the trading platform MetaTrader 4, there is a particular cautionary step that you can take known as Backtesting. This process of testing will help you obtain valuable insights into the performance of an expert advisor prior to having used it with your own real assets. In this article we are going to take a deep look at the process of backtesting and how you can carry it out yourself. 

 

What is Backtesting in MT4?

 

As the name suggests, backtesting refers to a process of testing in which an expert advisor is tested with the help of historical market data – hence backtesting. In this way, you can use such historical data and see how your expert advisor would have performed had it been under those conditions. You can see how it is clearly a significantly important step to be carried out before you actually use the expert advisor with your own assets. 

Backtesting in the MetaTrader 4 environment is made possible with the help of a feature of this platform that is known as Strategy Tester. This feature is made specifically so that users can backtest their expert advisors and also provides users with useful features such as setting up the parameters of the backtesting and ultimately providing users with a report on the results of the test so that they can use the report for optimization of the expert advisor. 

Strategy Tester In MT4

Setting Up Your EA for Backtesting in MT4

 

Prior to the process of testing itself, there are certain prerequisites that you need to observe and accomplish. Naturally, it begins with having your expert advisor installed on MT4 so that you are able to backtest it, all the way to opening the tester feature of MT4 and choosing the parameters for testing. 

 

Install the EA on MT4:

    • Open MetaTrader 4 and go to the File > Open Data Folder.
    • Navigate to MQL4 > Experts, then copy your EA’s .mq4 or .ex4 file into this folder.
    • Restart MT4 to load your EA into the Navigator pane.

 

Open the Strategy Tester:

    • To access the Strategy Tester, press Ctrl + R or go to View > Strategy Tester.
    • At this point you should be able to see a panel at the bottom of MT4.

 

Select Your EA:

    • Then you can see a dropdown menu called Expert Advisor.
    • Pick the expert advisor you want to test from the list. 
    • Choose the currency pair and timeframe you want to backtest. 
    • A good recommendation is to test your expert advisor on the time frame and also the trading pair which are most compatible with its algorithm. 

 

Set the Model for Backtesting:

    • One last stop in the general settings that are related to backtesting in MetaTrader 4 is to choose which model of backtesting you want for this process. There are following options available for this purpose: 
      • Every Tick: the reason this model is called every tick is because it uses tick data. This is the most accurate model for backtesting on MT4. But you also need to know that the “every tick” model is also the slowest. 
      • Control Points: the next best option in terms of accuracy is the “control points” model, which uses approximate tick data. This model is a bit faster and it is considered to be ideal for those expert advisors that are not too sensitive about all the price movements. 
      • Open Prices Only: lastly, we have the “open prices only” testing model which offers the fastest results. But of course, there is also the downside that this model only considers the opening price of each price bar, i.e. the beginning of each price bar, hence its fast speed of execution in testing. 

 

Configuring Backtesting Parameters

 

Once you have done away with all the basic configurations of the testing process, it is time to configure the actual parameters of backtesting. Here are the most important parameters that you need to set for backtesting your expert advisor. 

  • Date Range: this refers to the period of time which you want to apply as the testing time span. While there are certain considerations to keep in mind when setting this factor, it is very important to choose in such a way that it encompasses various conditions in the market. So, the date for the historical data had better include both bearish and bullish periods. 
  • Initial Deposit: here you need to specify that amount of your account’s initial deposit for the testing process. 
  • Leverage: more often than not the trading process in forex involves using leverage. So if you want to see how your expert advisor would work with leverage, you can set the amount or ratio for leverage in this section.  
  • Visual Mode: while a lot of the configurations that you use for the backtesting process is obligatory, this feature is completely optional. Here you can choose whether you want to be presented with a visual representation of the testing process whereby you are shown all the trades that were executed on the trading chart as a visual playback. 

Running the Backtest

 

After all the configurations that you have been through relevant to the backtesting process, it is time to actually begin this test and expose your expert advisor to historical market data. To begin the process of testing you can simply click on START in the strategy tester section of MT4. 

Once the testing has started, you can clearly see four tabs as Result, Graph, Report and Journal. As the test goes on, more and more data will keep piling up in those areas. Once the test is done you can naturally use these tabs to obtain the results and begin the process of interpreting the results for later optimization of your expert advisor.  

Of course as the names suggest, each tab will be able to present you with a different kind of result data. The graph tab will show you the graph of your account equity or capital under the trading process by the expert advisor in the form of a curve, which you can use to clearly detect where your capital has risen or fallen as a result profitability or loss. You can also see the degree   of drawdown with the help of the graph. 

But perhaps the most useful tab is the report tab. In this tab you can see a lot of detailed information about various factors involved in the testing process. These include criteria such as the total profit and drawdown. 

 

Interpreting Backtest Results

 

As we mentioned in the last section, once the testing process is over, you are presented with important information relating to the results of the test.  The following are those that require the most attention from you in order to achieve the best manner of EA optimization. 

  • Total Net Profit: as the name suggests, this metric shows you the total amount of profit that has been accrued during the testing process by the EA. 
  • Drawdown: on the other hand, the drawdown rate refers to the total amount of loss that has been aggregated as a result of losing streaks in the process of trading (backtesting). If the figure for drawdown is high, then it is clearly indicative of the fact that your expert advisor is either not good at-risk management or needs further optimization to enhance risk management. 
  • Profit Factor: this ratio refers to the proportion of trades that end in profit compared with those that end in loss. As such, if the figure is higher than 1.5 or 2, then it is generally regarded as an optimal ratio for profit factor and a sign of profitability in the long run. 

As you will see, there are also other variables and factors that you can obtain from the results that are given after backtesting in MT4, but these were the most important ones that require the most attention from you likewise. 

 

Optimizing Your EA

 

Naturally, when the process of backtesting is done and over, the next step is to use that data to optimize your expert advisor. There are various ways you can go about that action, including doing so manually and getting into the settings and configuration of the EA yourself. 

Another route is to use a built-in feature of the Strategy Tester feature of the MetaTrader 4 itself. There is an option in the testing area titled Optimization which can help you achieve a much better degree of optimized performance using your expert advisor. The way this feature works is by running the expert advisor with multiple modes of configuration. This will yield potential, highly optimal configurations of the Expert Advisor. 

To activate this feature, you only need to check the box for Optimization. 

You can still define various factors and criteria that are involved in the performance of the expert advisor, including but not limited to factors such as the range for stop loss, take profit, and also your preferred lot sizes. 

When the Optimization feature is checked and then you run the backtesting process, you will receive additional results titled Optimization Results and Optimization Graph. Both of these can help you find out the best parameters that help achieve better results in the testing process. 

Common Backtesting Pitfalls to Avoid

 

In order to be able to optimize your MT4 expert advisor, you first need to have results that are reliable themselves. Naturally, you base the optimization process on the results that you obtain from backtesting the EA. So, you need to make sure that the results are as accurate as possible. There are certain pitfalls that ought to be avoided because they will render unreliable results. The following are among the most important of these: 

  • Over-Optimization: this situation occurs when you optimize the parameters for backtesting way too much. This will cause the results of the backtesting to be artificially perfect. Naturally, in such a situation the results cannot be relied on for the purposes of optimizing your expert advisor. 
  • Not Considering Different Market Conditions: something that you ought to keep in mind about financial markets, especially the forex market is that conditions are almost never stable. They are constantly changing. So, if you do not factor for possible changing conditions in the market, the results will again be less than reliable. 
  • Using Low-Quality Data: as we discussed above, the data that you feed the testing process is extremely important. So if you use low quality historical market data for the backtest, the accuracy of the performance of your EA under the testing process will be lowered. 

Moving from Backtesting to Forward Testing

 

After the process of backtesting and the following optimization period are both over, there are other maintenance steps that you need to take in order to make sure you obtain a long-lasting profitability from your expert advisor. There is a process known as Forward Testing

In this process of testing, as the name suggests, you do not use historical market data – hence forward. Instead, you would use real time market data. But using real time market data without having to expose your assets to risks. This is only achievable via demo trading and using a demo account where you would be able to trade with virtual currencies with almost real-time data and only a slight delay between the time they occur in the market and when they are fed to your demo account. In this process of forward testing, you can further make sure that the current optimization of your expert advisor is able to handle the current conditions and price movements in the market.

Leave a Reply

Your email address will not be published. Required fields are marked *

17 − 6 =

×