MetaTrader 5 Backtesting

MetaTrader 5 Backtesting: Strategy Tester Tutorial

In this lecture, I will show you how to perform backtesting on MetaTrader 5 using the build-in Strategy Tester tool. I will do the backtest with a strategy for Tesla stocks that I have been using in our stock trading course. Lets’s get started on the MetaTrader 5 Strategy Tester.

Backtesting Stock Market Strategy on MetaTrader 5

MetaTrader 5 Strategy Tester
MetaTrader 5 Strategy Tester

I have the indicators over the chart. The EA is attached to the chart as well. But what actually I need to do is to go to View and hit on the MetaTrader 5 Strategy Tester. A new window will open below the toolbox with a few tabs, one is Settings. And this is from where we need to set it up.

And it’s very easy. Usually, it should fill automatically according to what we have on the chart. If it doesn’t, you need to select your symbol from there, the Expert that you want to test, and what is the timeframe.

Setting a symbol on MetaTrader 5
Setting the Symbol on MetaTrader 5

And then if you want to use the entire history that you have or if you want to select any custom period to perform backtesting on MetaTrader 5, you can do that as well. Just hit on the custom period from the Date dropdown. And these two boxes will become editable. So I will go back just to Enter history for the purpose of this backtest.

set the metatrader 5 backtesting period
Setting the backtesting period in MetaTrader 5 Strategy Tester

And then we have the option to do some forward testing, which I’m not going to do in this MetaTrader 5 backtesting tutorial.

Modeling in MetaTrader 5

Then below is the Modeling. We have Open prices only if the strategy works on the opening of the bar and this Tesla stock trading strategy works on the opening of the bar. So when the new bar opens, the trading strategy checks for entry and exit conditions. So I will leave it this way.

If you want to test any other strategy that uses a stick or does some math calculations, you should be selecting a different option. But for the purpose of this MetaTrader 5 backtesting guide, I will stick to Open prices only.

Optimizing the strategy

Below Modeling, you have the initial balance. You can start with any amount. You can go for 10,000, you can go for 100,000. The Leverage that you are using, you can change from here. And then, the last option is to use optimization or not to use optimization. So basically here I will not be using optimization in this MetaTrader 5 backtesting example.

Be careful when you are optimizing strategies because you can over-optimize them.

When you are doing optimization, simply you will force the optimizer to find the most appropriate parameters for your strategy based on the tested period. And we have the risk of over-optimize the trading strategy or making it kind of too perfect or too good to be true. So I really don’t suggest you do optimization unless you have experience with it.

Visual mode

Then I have the option to check or uncheck visual modes. But let me check it and I will click on the Start button at the bottom right side of the screen. A new tab will open, and it will show us the results from the backtesting or our strategy on MetaTrader 5. And it does visual trading and I can decrease or increase the speed from right over there. And if I tap on Trade, I have over 1 million pips.

Then in History, we can see clearly where the Stop Loss was for all of the positions we started in this case from 2010. This is how much data is available with the broker that I have selected over the chart. And one more time, I’ve mentioned this already in many of my lectures, if you want to pull historical data from your chart, you just need to press the Home key on your chart.

MetaTrader 5 Strategy Tester Visualization
MetaTrader 5 Strategy Tester Visualization

Just go to the symbol and press the home key and it will load as maximum data as you have. And this is good to be done before you actually perform the MetaTrader 5 backtesting.


Next to the History tab, is the Operations tab. From there I can see where the trades were actually opened, at what price. So in 2010, the price of Tesla was $3-4. And if I scroll slowly down, you can see how the price increased. These are all the trades that were executed with this particular Expert Advisor.

Now, one thing that I find as a disadvantage in MetaTrader 5 compared to MetaTrader 4 is, that in MT5 we have two separate tabs for History, or here we can see where the Stop Loss was. The Tesla strategy doesn’t use Take Profit.

History and Operations tabs are separate in MetaTrader 5
History and Operations tabs are separate in MetaTrader 5

And in a separate tab, we have the open price and the Stop Loss. So it’s not on one tab, as it is on MetaTrader 4, which makes it a little bit more confusing if you’re using it for the first time. Depends on what you want to do but if you want to compare one trade, you need to go from one tab to another one, which is not really very comfortable.

MetaTrader 5 backtesting results

This is how we perform strategy backtesting on MetaTrader 5 using the Strategy Tester visualization. But if you want to see actually what was the performance, you need to go to Backtest. And here you will see some statistics that we have from the strategy, such as balance, drawdown, expected payoff. We have a Profit factor of above 1.81, which is pretty good. So the Profit factor is all the profits divided by all the losses.

MetaTrader 5 backtest results
MetaTrader 5 backtest results

And we have some more statistics below, which I’m not going into details about. But MetaTrader 5 has more backtesting statistics compared to what MetaTrader 4 offers. And of course, very interesting as well is the Graph tab. There we can see what is the graph of the trading strategy. And obviously, in recent months, the market was very volatile for Tesla. We have some more movements and some more results. You can see that actually, it did a fantastic profit during these volatile times.

Tesla trading strategy graph
Tesla strategy graph

MetaTrader 5 vs EA Studio Backtesting

Now, I prefer to backtest the trading strategies with the Expert Advisor Studio because it’s much easier. I don’t need to switch between so many different tabs. And it’s more professional software.

Expert Advisor Studio Strategy Editor
Expert Advisor Studio Strategy Editor

We see the strategy itself. So here it is. You see the entry indicators, Moving Averages, the Alligator. We have the moving average crossover as an exit indicator and the balance chart is just the same if you compare it, it’s just on a different size window. But let’s compare a few trades.

So if I click on the Balance chart of the strategy and then go to Journal, this is where I see all the trades that happen. As you can see all the data is in one place, not in different tabs.

Let me go to the last page in the Journal and I will just look at the most recent trades. So let me make the MetaTrader 5 Strategy Tester visualization a little bit smaller. And I will look, for example, any of the trades. Let’s pick randomly something that will be easy to recognize.

The Journal in EA Studio
The Journal in EA Studio

On the 20th of April, in EA Studio we have at 5 PM a buy order and the Stop Loss was 680.55. On the 20th of April at 5 PM we have a buy or open long and the price was 730.75 and the Stop Loss was 680.55. Let me go to Operations in MetaTrader 5 and I will look for the trade right over here. There could be a small difference in the opening price because of the spreads but is the same trade. It matches, it open at the same time.

Comparing the results in MetaTrader 5 Strategy Tester and EA Studio
Comparing the results in MetaTrader 5 Strategy Tester and EA Studio

And if you look at the next one, what happened next is we had the closing of the trade at 21:15 which here is recognized as a sell. Because obviously when we buy, the closing of this position is a sell order. So in MetaTrader 5 Strategy Tester, it is displayed as a sell. And it was at the price of 715.57. Here the closing is at 715.57. So it matches.

The final result from the backtest

And probably something you may notice is if I switch from History to Operations in MetaTrader 5, I don’t see the backtesting results. Which is the most important thing when we are backtesting. That’s one of the reasons I prefer to use the backtester on EA Studio. As well on EA Studio, we can see very clearly the indicator chart, where the trades were open and closed.

And this is super useful when you have a strategy. For example, let me scroll randomly around this Tesla strategy. Here it is. I have a short trade and open here and it was closed over here. Then right here I have another short trade starting from here, closing right over here. Then we have a losing short trade.

You can see how much statistics we have and as well in the Journal are all the trades that open and close.

Results from Tesla strategy backtesting in EA Studio
Results from Tesla strategy backtesting in EA Studio

So if I compare backtesting in MetaTrader 5 and Expert Advisor Studio, obviously I prefer to use EA Studio because it is a professional tool for backtesting and analyzing strategies. However, MetaTrader 5 offers a good backtest to see that it matches with EA Studio, the professional software I use.

MetaTrader 5 backtesting disadvantages

Just a few disadvantages, probably because I’m used to the EA Studio and I am more used to MetaTrader 4 because I’ve been using it for many years. For Forex trading, it’s a little bit difficult to follow the trades in MetaTrader 5 because they’re on different tabs.

And in the main page in MT5 where we have the Settings, we have the inputs of the strategy, we have the backtest statistics, one more time, in MT 5 there is more data compared to what MetaTrader 4 offers. So that’s an advantage of MetaTrader 5 compared to MetaTrader 4.

And then we have the graph and the optimization if you decide to optimize the strategy. One more time, I’m not suggesting it to do this, especially if you’re a beginner, because you are taking the risk to over-optimize the strategy.

Final words

But to make it super simple here at the end of this lecture, if you want to perform strategy backtesting on MetaTrader 5 with your broker, this is how you can do it.

Go to View, open the MetaTrader 5 Strategy Tester, and set it up. All you need to set up is the Expert, the Symbol, the Time frame, and the Modelling, which in this case with the EA Studio strategies, we use Open prices only. Then you can hit on Start and you will see the MetaTrader 5 backtest and the graph or simply said you will see if this strategy was profitable until the moment.

Why I say “was”? Because we tested on historical data, it doesn’t guarantee that this strategy will perform profitably in the future. But as I like to say, it is much more compared to if we don’t have a trading robot to backtest. If we have just a manual strategy, we don’t have that. We cannot clearly see if this strategy was profitable from 2010 until the moment in April 2021.

So this is how the backtesting works with the MetaTrader 5 Strategy Tester. And you saw the difference with EA Studio. So if you have any questions, let me know in the comments below. I will do my best to answer you. If you have hard times backtesting a trading strategy on MetaTrader 5, you better send us some screenshots so we can help you out.

Thanks for reading and have a great day.

Shopping Cart