Backtests

Haikal Rahman

 

Our main interest with Expert Advisor (EA) is to have a winning strategy over the long term. There is that famous phrase: that nobody in the financial market has a crystal ball. It is no use trying to predict the future of the market, because unfortunately, it is impossible until the present moment.

We need to be realistic to accept that our strategy will have ups and downs regarding financial returns. The 100% winning strategy is a utopia. However, it is important to know how good our strategy is. There is nothing better than using past data to gauge how it performed under various market conditions. So testing our strategy at past time periods is called a backtest.

Fortunately, when it comes to backtesting MetaTrader 5 provides a collection of simple and useful features to extract as much information as possible from the performance of our EA.

Now that we already have an EA (MM_CROS_RSI.exe5) multi-strategy programmed and working properly, let's do the backtests.

Backtest in MetaTrader 5

Let's open MetaTrader and go to the field Navigator -> Expert Advisor consultant and look for our newest EA. Once found we should right click on it and then on Test.



This will give us a new field in MetaTrader called Strategy Tester, in the settings tab we have the following panel of possibilities:

With these features we will be able to choose the financial asset for the backtest:

The graphical time:

We have the option to choose how the formation of our candles are simulated by MetaTrader.

For this way of generating prices in candles, let’s go to the main options most used:

  • Every tick or Every tick based on real ticks: MetaTrader tries to simulate real price ticks in the formation of candles. This option leaves the backtest more accurate, but requires more computational resources once inside a candle the MetaTrader tries to reproduce the formation of real ticks. It is worth noting that ticks are not real are just a simulation (a possible representation of reality). This article clarifies the functioning of this simulation:https://www.mql5.com/en/articles/75.
  • 1 minute OHLC: In this type of candle formation MetaTrader generates only 4 price values: - open, - High, - Low, - Close. This option requires much fewer computational resources compared to the tick option.
  • Open price only: This is the least costly option computationally, because it only uses a price to represent a candle.

In our backtests we will always leave the option Forward marked No (see the figure below). This option is useful when we are doing strategy optimizations and want to use optimization methods such as Walk Forward Analysis (WFA). This type of study is beyond the scope of this book. If you want to know more about it, you can buy the other e-book (How to Properly Optimize Investment Robots in MetaTrader 5

The type of execution with or without Delay is interesting so we can simulate the conditions in which the servers are and the speed of our internet. Latency refers to the time required for routing orders to be properly executed.

We have the possibility to choose the financial from the initial deposit as well as the possibility to leverage investments (in the case of the figure below 1: 1 without leverage).

For our backtests the Optimization field should be disabled:



We should choose the data period for the backtest.

And check the option to view the backtest:

Let's now go to the Input (Parameters) tab of the Strategy Tester.

In this field we can put the setup necessary for the realization of our backtests. At the moment, what interests us is just the Value column, highlighted in low red. The other columns (highlighted in green) are used as parameters for EA optimization.

In the Agents tab we have information regarding the computational power of the machine that we are using to do the backtests and optimizations. A backtest is usually computationally inexpensive. However, when we are doing optimizations (many backtests are required) we will need a lot of resources and therefore this Agents tab will be important to us.

We can make a log to use multiple processing cores in the cloud and thus increase our computing power. The use of these extra cores is very affordable. With a few dollars we can make hundreds of thousands of optimizations.



After setting the parameters correctly for the backtest, simply go back to the Settings tab and hit the Start button.

Analyzing the Backtest

As soon as you press the Start button, the following window appears:

So we have a screen to visualize what is happening with the backtest. We can control the speed with which new candles (candles) appear, from the highlighted buttons (red) of the figure above.

You can also have the prices of each candle and indicator (green area highlighted), just place the mouse over the desired element on the screen.

In the Toolbox we have four tabs (Trading, History, Operations and Journal) where we can track records regarding our trades operations of our EA.

In the Toolbox in the Operations tab we can follow the records with each of the sales and purchase operations. Something very useful is that we can give two clicks on some of this operation and the graph will automatically show the operation in question.

The Toolbox History tab shows a bit more detail. We can quickly see profitable (green) and lossy (red) operations from colorful highlights.



Finally, the Operation tab shows the progress of each particular negotiation. We have the information regarding the entry price, our available financial margin and how the trade is progressing, whether with gain or loss.

Performance Charts

During the backtest or after the end we can follow the evolution of our capital in the Graph tab that appears in the Strategy Tester.

However, after the end of the backtest, a new tab called Backtest appears. This tab provides a summary of the operational statistics of our strategy. In it we can see the profit Factor of the operation (ratio between gross profit and gross loss), recovery factor, drawdown or retraction, total trading, number of short positions and bought with gains and losses, sharp index among others.

We can visualize bar charts informing about the schedules, the days of the week and the month where we have more entries in the traders.

You can track the frequency of profits and losses: by EA operating hours, days of the week, and months of the year. We also have information regarding the maximum time set and the minimum duration of a position.

However, as we can see, MetaTrader 5 gives us a very thorough review of our backtest.

 

Sumber : Rafael F. V. C. Santos

Haikal Rahman
Bisnis Digital - FE Unimed
Komentar