backtesting trading strategies

Backtesting Trading Strategies with MetaTrader

Backtesting trading strategies

Hello traders. In this lecture, I will talk about backtesting trading strategies that you have created with Forex Strategy Builder Professional and you want to backtest on Meta Trader platform for your broker. The strategy that I’ll be showing is for the USDJPY.

It’s part of my Forex Trading Strategies From a Professional Trader + 5 EA course where I combine the most profitable strategies I have from my trading and from my courses. This strategy was initially created for the Algorithmic Day Trading + Top 10 USDJPY Expert Advisors course.

Now, the strategy trades on M5 and it uses higher timeframe filters. There are a few details that you need to know about how Meta Trader does the backtesting trading strategies. Some traders fail to backtest such Expert Advisors on Meta Trader and I will show you what is the problem with Meta Trader in this case.

So this strategy for USDJPY has the Ichimoku indicator on M5, this is the main timeframe.

backtesting trading strategies
The indicators

And it uses the Williams Percent Range as well. There are 2 MACD indicators that are for H1 and M30. These are higher or longer timeframe filters which means that the strategy executes the trades on M5 but it looks for confirmations on M30 and H1. There is Take Profit and Stop Loss as well.

Ambiguous bars in backtesting trading strategies

So here is the backtest that we see on Forex Strategy Builder Professional.

The backtest on FSB Pro

And with this strategy builder, we have 5 different backtesting trading strategies methods. First is Pessimistic, second, Optimistic. Then we have Shortest, Nearest, and Random.

backtesting trading strategies methods
The backtesting trading strategy methods

These are different methods that matter only when we have ambiguous bars. For beginner traders, we say ambiguous bars when we have a bar that has the Stop Loss or the Take Profit within the bar. And the backtest in Meta Trader cannot decide what is the outcome of this bar or this position.

It gives you an optimistic outcome which is something that I really don’t like. And it’s not a really appropriate approach from Meta Trader but this is how it’s working. If there are no ambiguous bars in the strategy, it really doesn’t matter. The result will be the same.

So even if I change the method, there is not any difference in the balance chart during this backtesting trading strategies or during the change that I do in the methods. Therefore, when you are backtesting trading strategies with Forex Strategy Builder Professional and if your strategy has ambiguous bars, you better check the different methods.

FSB Pro allows you export strategies for MT4 and MT5

But I always keep it on Pessimistic. So even if there are some ambiguous bars, the program will show me the bad outcome of these bars, and this way, I will not have any misleading backtest. Now, if you want to do a backtest on Meta Trader, first you will need to place the Expert Advisor.

If you have exported the Expert Advisor from Forex Strategy Builder Pro, you can do it from the yellow hat icon and there is the option – Export Expert Advisor for Meta Trader 4.

backtesting trading strategies
Exporting the Expert Advisor from FSB Pro

Or you can as well save it as an Expert Advisor. So once you export it, you will need to go to Meta Trader, go to File, Open Data Folder,

Go to File then Open Data Folder

MQL4,

backtesting trading strategies
MQL4

Experts,

Experts

and paste your Expert.

And then close the folder and click with right mouse over Expert Advisors tab in the navigator and click Refresh.

Right-click over Expert Advisors and click on Refresh

This will compile the Expert Advisor. This is for Meta Trader 4. If you are using Meta Trader 5, you need to modify and compile the Expert Advisor from the MetaEditor. You need to do that if you want to do backtesting trading strategies.

So after you have the Expert Advisor, you can drag it over the chart and you will see all the inputs from where you can enter the entry amount, the maximum position, if you want to add to the position or not if you want to close on the reduction or not. And then you will see all the parameters of the strategy. And when you hit on OK, the Expert Advisor will be attached over the chart.

backtesting trading strategies
Drag the Expert Advisor over the chart and you will see all the inputs

The Strategy Tester is where we do backtesting trading strategies on MetaTrader

Now, if you are backtesting trading strategies on Meta Trader 4, you need to right-click over the chart, go to Expert Advisors, and hit on Strategy Tester.

The Strategy Tester

This will open the Strategy Tester window below the chart and you will see the symbol, the period, or the timeframe. As for the spread, you can enter it manually or leave it as the default that Meta Trader shows. And then you have the Model option and you have the option to check the Use date option or not.

backtesting trading strategies
The Strategy Tester window

And this is the very important thing with the Expert Advisors that come from Forex Strategy Builder Pro. So as a model, there are 3 different options.

Model options

Every tick, which is not recommendable because there really isn’t tick data in Meta Trader. There is some, it comes from nowhere.

As you know, you cannot see it on the chart so it’s not really recommendable even if it says the most precise method. Then you have Control points, which is the option I’m using with the Expert Advisors from FSB Pro. And then Open prices only, which works best for the Expert Advisors with EA Studio.

The backtest is complete

So if you are backtesting trading strategies that come from EA Studio, make sure to use Open prices only. For this Expert Advisor, I will use Control points. And then I will click on Start. Immediately I see that the backtest is complete. But if I go to results and graph, there aren’t any results.

And what is the reason for that? That’s a question I receive quite often from the traders and my students. This is because I didn’t select to use date. And you really don’t have to. But in this case, we have to with this Expert Advisor and I will explain why.

Now, if I go back to the strategy, you will see that on the H1 chart, we have the MACD with period of 19, 12, and 9.

backtesting trading strategies
MACD on H1 chart

Which means that we need to have 19 hours for the first value to show in the Slow Moving Average in the MACD. Now, the problem here is that Meta Trader starts the backtest from the 100 bar.

And we are trading on M5 so if we have 100 bars times M5 or 5, this is exactly 500 minutes. Or in other words, we have 100 bars times 5 because we are on M5, which is 500. Divided by 60 (1 hour), we have 8 hours and something.

The calculation

I hope it’s now easier to understand

So in the 8 hours and something, we will not have value for the MACD on H1 because the MACD on H1 uses Slow Moving Average with a period of 19. So there are about 11 hours of difference and Meta Trader cannot really understand that 100th bar what is the value for the MACD. This is why we don’t see the backtesting trading strategies.

I really hope that I made it clear. But if I can try and say it in very simple words, Meta Trader is backtesting trading strategies from the 100th bar since the beginning. Since the beginning of the historical data. If I press the Home key on M5, you will see from where my historical data starts. From 2015, and now we are in 2020.

So I have a lot of data, more than 5 years. But the backtest starts after the 100th M5 bar. And on this 100th M5 bar, there is no result for H1 MACD because it’s a higher period. The solution is just to use a date. So, for example, let me go to the last year or you can select any other starting date.

When you place a starting date, there will already be value for this MACD indicator. Or I can go even further back to 2017 – 2016. It just needs to be a later date than the 100th bar on Meta Trader for M5. And I click on Start and I see that there is a difference this time.

Backtesting trading strategies with EA Studio is faster compared to FSB Pro

The backtest starts and I will see the results and the graph. Now, if you are backtesting trading strategies with FSB Pro and with EA Studio at the same time, you will notice that the backtest with EA Studio is much faster than FSB Pro. Why is that? This is because FSB Pro is a much more complicated software.

The Expert Advisors are more complicated. It’s a software that’s been developed for over 15 years and all the traders were requiring different indicators, custom indicators, higher timeframe filters (what I’m showing you). And all of that made the Expert Advisors heavy.

There are no mistakes in the code when you export the Expert Advisors. But for Meta Trader, it is very hard to make the backtest. It does it, already I have the first results. But it does it slowly. So if you are backtesting trading strategies with FSB Pro, don’t lose the time to do it with Meta Trader.

Better you do it with FSB Pro because any change that you do for the strategy, for example, if I change the Take Profit to 75 pips, not 80, I will see immediately the difference. Just a change, there is a difference immediately. And I don’t need to lose the time to do it on Meta Trader.

Save time for backtesting trading strategies with FSB Pro and not MetaTrader

So this is the reason why you might not see results when you are backtesting trading strategies with Meta Trader. One more time, this is because of the parameters and the indicators. And honestly, there’s not any sense that Meta Trader starts the backtest from the first 100th bar.

Because it’s losing 100 bars from the backtest and because there are some issues like this one which makes the traders think that the EAs don’t work on Meta Trader. They do. You can backtest them. Just place a starting date and you will see that there are no errors and you will see the very same results on Meta Trader as you see on Forex Strategy Builder Pro.

Thank you for reading. If you have any questions about backtesting trading strategies, let me know in the comments below. And if you like that video, please like and subscribe to our channel so you will see more of our free trading videos.

Have safe trading. Bye

Shopping Cart