josh redd EySEKaimdKo unsplash 4t1 2 - How to Backtest Expert Advisors the Right Way

How to Backtest Expert Advisors the Right Way

What Is Backtesting and Why Is It Necessary?

It can be assumed that a trading strategy is successful in terms of profitability both in the present and in the future only if it was successful in the past. Nevertheless, there is no guarantee that the strategy with positive historical results will continue to deliver desirable results in the future. However, it can be stated with high probability that if a strategy has not been successful in the past, it is unlikely to be profitable in the future. Therefore, there is a need to first test a given strategy using historical data before deploying it in real terms. This testing of a strategy based on past and historical data is commonly referred to as backtesting.

This means that backtesting is a method to see how well a strategy or model would have performed in the past using historical data. For this purpose, a high quality of the given historical data and its reasonable application for modeling is absolutely essential for realistic and trustworthy backtest results. We achieve this only by recording real ticks issued by the broker.

What Are Ticks and Why Do We Need Them?

A tick is a measure of the minimum upward or downward movement of a price, or a measure of the minimum price change, such as in currency trading. This means for forex trading, as soon as the forex rate in the chart changes by a certain minimum value, the change is indicated with a tick in the chart. In order to guarantee a modeling or backtesting of high quality, we need real recorded ticks of a broker.

Among other things, a modeling should consider the following points as much as possible to provide a realistic simulation.

  • Real ticks with 99% coverage (modeling quality)
  • Costs of the broker (commission, real and variable spread, swaps)
  • Slippage (time delay due to signal transmission and signal processing)

To illustrate the importance of real tick data, two backtest results of an Expert Advisor are shown below. All settings are identical except for the tick data. The first chart shows the results based on poor quality tick data (actually it is interpolated tick data in MetaTrader 4), the second chart shows the results based on real tick data. While the Expert Advisor appears profitable on the first image, the second image shows more realistic results indicating that the Expert Advisor is not profitable (at least in the time range tested). The need for high quality tick data is particularly evident here.

Backtest tick data high and low quality 01 - How to Backtest Expert Advisors the Right Way
Comparison between backtest results with high and low quality tick data

Where and How to Get High Quality Tick Data for Backtesting

MetaTrader 4 uses only random simulation of ticks when backtesting with tick data. An interpolation process uses bar price data together with the tick count to generate the prices for each tick. The image below illustrates the difference between interpolated (MetaTrader 4) and real tick data.

Real and Interpolated Tick Data - How to Backtest Expert Advisors the Right Way
Interpolated and Real Tick Data

The easiest way to get high quality tick data is by using third party software. Here, the following two programs are particularly worth mentioning: Tick Data Suite and Tickstory, both programs are only available for Windows. We have had the best experience with Tick Data Suite, so we now only use this software. In particular, we were convinced by the very high quality of the ticks, the very easy operation, the robust program execution and the many relevant setting options. With Tick Data Suite, we were able to most accurately match the modeled results of an Expert Advisor to the real historical results of the same Expert Advisor. Therefore, we can fully recommend it.

In particular, Tick Data Suite fulfills the points mentioned above for realistic simulations. Real tick data with 99% modeling quality, broker costs (such as commission, real and variable spread and swaps) and slippage are taken into account and can be optimized and adjusted to a specific broker.

Download of High Quality Tick Data (Using Tick Data Manager)

Once you have decided to use Tick Data Suite, you can try it for free for 14 days. To do this, a trial license must be requested. Then you can download the software, install it and unlock it using the license. The Tick Data Manager can now be used to download the historical tick data. At the first start you have to specify the location for the ticks. Depending on the amount of tick data, several GBytes of storage space should be available.

Under “Source” you can select the broker whose ticks you want to use. The most comprehensive tick data is available for the broker Dukascopy. Since we mainly trade with the Forex broker IC Markets and no tick data are stored for this broker, we use the ticks of Dukascopy and adjust the broker-relevant settings manually. The storage space for the currency we use and the complete time range since 2003 occupies about 40 GByte.

Tick Data Manager Main window 01 - How to Backtest Expert Advisors the Right Way
Tick Data Manager - Main window

Backtesting Under MetaTrader 4 (Setup of Tick Data Suite)

The key of realistic backtests lies in using high quality tick data and appropriate settings for the relevant broker you want to trade with. We present here our settings for backtesting Expert Advisors under IC Markets. For this, we use Dukascopy tick data, as it is one of the most comprehensive, and additionally adapt certain settings to IC Markets.

After downloading Dukascopy tick data of relevant currency pairs, we start a terminal of MetaTrader 4 and select “Strategy Tester” under “View”. As a model we use “Every tick”. As you can see, Tick Data Suite has implemented the “Tick data settings” button in the “Strategy Tester”.

MetaTrader 4 Strategy Tester 02 - How to Backtest Expert Advisors the Right Way
MetaTrader 4 - Strategy

Under “Tick data settings” –> “Basic” we use the settings shown below. Especially the two settings “GMT offset: +2” and “DST: US” are important here.

All tick data settings of Tick Data Suite must be adjusted for each currency pair and each terminal instance of MetaTrader 4 individually.

Tick Data Settings Basic 01 - How to Backtest Expert Advisors the Right Way
Tick Data Settings - Basic

Under “Spread” we decrease the “Spread multiplier”. We have to reduce the spread because IC Markets statistically has a lower spread than Dukascopy. This setting is especially important for scalpers. For EURUSD we use the value “0.6” (since May 25, 2021, before that: “0.5”), for all other currencies the value “0.7” (since May 25, 2021, before that: “0.6”).

Tick Data Settings Spread 01 - How to Backtest Expert Advisors the Right Way
Tick Data Settings - Spread

Under “Slippage”, the lower settings have proven to be reliable, but may vary depending on the location and performance of the VPS (Virtual Private Server).

Tick Data Settings Slippage 01 - How to Backtest Expert Advisors the Right Way
Tick Data Settings - Slippage

Under “Advanced” we use these settings. The first thing to note here is the value under “Commission”, which is “5” for us. Generally the commission at IC Markets is 8 USD per lot (round trip). But with our link you get a discount of about 40%, so the commission is only 5 USD. Additionally worth mentioning is the value under “Bars before data”, which should be increased, for example to “1000”. The rest of the values you can see in the picture.

Tick Data Settings Advanced 01 - How to Backtest Expert Advisors the Right Way
Tick Data Settings - Advanced

Under “Expert” the values for “Swap” are important. At IC Markets we have had good experience with the values “-20” for both “Long swap” and “Short swap”.

Tick Data Settings Expert 01 - How to Backtest Expert Advisors the Right Way
Tick Data Settings - Expert

Under “Margin” and “Misc” we have not changed anything.

Tick Data Settings Margin 01 - How to Backtest Expert Advisors the Right Way
Tick Data Settings - Margin
Tick Data Settings Misc 01 - How to Backtest Expert Advisors the Right Way
Tick Data Settings - Misc

Backtesting Under MetaTrader 5

In MetaTrader 5 you can use the original tick data of the broker by downloading it under “View” –> “Symbols” in the terminal. This data already contains information about spread and slippage, but brokers often have gaps in the coverage of the tick data, so here after the backtest you must first check to what extent the trades are realistic and accordingly remove periods of unrealistic trades from the results.

Hints and Tips for Backtesting

  • If possible, always perform backtests with constant lot size

If possible, always perform backtests with a constant slot size.We always backtest with lot size = 0.01. This has certain advantages over a variable lot size. Unfortunately, some Expert Advisors are based on dangerous strategies, where there is often no possibility to set a constant lot size and would also contradict the strategy. Advantages of a constant lot size are clearly in the evaluation and the comparability of the results. If, however, results are available depending on the balance, mainly the simulation results of the latter time range stand out and cover visually and statistically the results of the older time ranges. This makes it impossible to develop a “feeling” for the Expert Advisor's algorithm and additionally makes statistical analysis much more difficult.

  • Use “currency” and not “pips” for analysis

Analyze the results mainly in the unit “currency” and not in “pips”. In currency all the costs that the trade cost you are already taken into account, in pips they are not. This is especially important for scalpers and night scalpers.

  • Robustness and stability of strategies

To check the robustness and stability of strategies, they should be tested with different brokers (spread, slippage, cost of the broker). This way you can find out to what extent a strategy depends on the broker, respectively on the costs of a broker, the spread, the slippage or other circumstances. Furthermore, a strategy may even work with other highly correlated currencies, or at least not fail completely.

Highly correlated currencies
Highly correlated currencies

 

  • Possibilities and limits of backtests

Note that backtests are simulations and can only approximate reality. Therefore, it should be understood that there is no such thing as a perfect backtest. Every backtest will contain errors. What matters is the presence of a large correlation between simulated and real results. Therefore, after you have made real trades for a certain period of time, you should always simulate them with backtests. Only if the data here correlate with each other, you can trust the backtests for past or future time ranges.

  • Backtest of Scalpers

The shorter the time interval between opening and closing a trade and the fewer pips a trade covers, the lower the modeling quality.

  • Backtest of Night Scalpers

Overnight trading also reduces modeling quality, as the spread can become very large at night, depends heavily on the broker, and is highly variable. In addition, slippage can also increase sharply. Therefore, especially night scalpers often have a particularly poor modeling quality, so that the results must be viewed with caution.

Traders Comments
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

There will be moderation of all comments. Please also read our comment rules:

For open discussion, we reserve the right to delete any comment that is not directly on topic or has the sole purpose of disparaging readers or authors. We want people to communicate respectfully with each other, as if the discussion were with real people present. By submitting this form you agree to our Privacy Policy and the storage of your personal data.

Menu
0
Would love your thoughts, please comment.x
()
x