Today, I would like to show you several different ways that you can use to backtest Expert Advisor. I show some of them in my courses but in this lecture, I will show you a few more which I recently used and they work really well for me.
Table of Contents:
It doesn’t really matter which method you will be using, the results will be very similar and you will choose nearly the same Expert Advisors every time when you’re testing many EAs.
Backtest Expert Advisor in Expert Advisor Studio
So for the beginners what’s the idea?
With EA Studio, we create many Expert Advisors and we test them to see which are the Expert Advisors that make the most profit on the current market conditions.
So the first method I will show you is called Out of Sample, and this is available in EA Studio. If you click on the Generator settings, there is Out of Sample.
The Out of Sample is a really great method because it allows us to test the Expert Advisors while we are generating them.
For example, if I want to generate strategies for EURUSD on H1 chart, I have my strategy properties of 0.1 lot, minimum 10 pips, and maximum 100 pips for the Stop Loss and the Take Profit range.
And then in Generator settings, we have Working minutes – how long we want the Generator or the Reactor to be working.
Out of Sample in the first method to Backtest Expert Advisor
Then we have the Search best where we can select how we want the software to arrange the strategies into the Collection.
Usually, I keep it to Net balance so on the top I will see the strategies with the most profit. And then we have the Out of Sample.
So if I click on it, you will see that I have 5 different options to backtest Expert Advisor – 10%, 20%, 30%, 40%, and 50%, and the 6th option is the In Sample.
So what is that? Let’s generate some strategies very quickly selecting 20% Out of Sample. The Acceptance criteria I will remove, I will remove Monte Carlo validation as well, and I will click on Start.
What I want to see are some strategies very quickly into the Collection. Here they are. I will stop the Generator. What you notice is that there is this green period for each strategy. And this is what we call Out of Sample.
So all the historical data that we have, in our case, is from the 15th of July, 2015 until the 15th of July, 2020, 5 years of historical data.
This means that the complete period is 5 years. And I have selected 20% Out of Sample which means that the Generator uses 80% of these 5 years, of this historical data. And in the recent 20%, it backtests the strategy. Or in other words, it simulates trading.
Historical data
This is really nice because it’s a real simulation, let me click on the strategy and there is the Out of Sample monitor which will show us exactly the dates. So In Sample, we have the beginning of the historical data, July 2015 until July 2019. You can see it in the picture below.
And then Out of Sample is July 2019 and July 2020. This is very easy because we have exactly 5 years of historical data, 20% out of it is 1 year. Or in other words, it means that the Generator has used the first 4 years from the historical data to generate the strategy and then it simulated trading during the last 1 year. Or it did a backtest Expert Advisor on an unknown data.
And you can see it’s a profitable strategy during the last 1 year. And below, we have more details about the In Sample part and about Out of Sample part, and then we have the complete backtest.
So this is the first method that you can use to test the strategies, or to backtest Expert Advisor, and you are simulating trading back in time.
It works really nice by the way. And you can change the period or the Out of Sample to 10% or a higher number. This is the first method that you can use, and that I use when I create strategies using the Out of Sample in EA Studio.
Data Horizon (2nd method to Backtest Expert Advisor)
Now, the second method is quite interesting because if you have noticed the In Sample, it has 10%, 20%, 30%, 40%, 50%. And if I go back to the strategy and I go to 10% Out of Sample, that would be about 6 months. I will be testing the strategy for 6 months.
What if you want to backtest Expert Advisor for just 1 month? This is possible with the Data Horizon. We have the start date on the 15th of July, 2015, and I can set Use end date limit just a month ago.
So I can put it on the 15th of June, 2020. What that means is that the Generator will use the data except for the last 1 month.
And if I go back to the Reactor, I will remove these strategies that I have generated previously. And you can see the 15th of July, 2015 until the 12th of June, 2020.
Probably the 13th and the 14th of June are over the weekend. This is why I have set the 15th but it starts from 12th.
Not probably, I’m sure this is the reason. So I have removed from the historical data the recent 1 month. Now, let me again generate strategies quickly so I can show you what exactly I’m doing. And I already have some strategies for the Collection.
I remove the recent 1 month from the historical data
I will wait to see at least 15 to 20 strategies. It works a little bit slower now because I have the other 3 Reactors working simultaneously. 20 strategies. I will stop now. Now I will go to Data, Data Horizon, and, one more time, I have removed the recent 1 month from the historical data.
What I will do now, I will change the Data Horizon to the recent 1 month so it will be 15th of June, 2020 until today which is already 16th of July, 2020. And this means that I have only the recent 1 month now as Data Horizon. And I will go back to the Collection and I will click on Recalculate. That method of backtesting Expert Advisor simulates Demo or Live trading.
This way, I will see how these 20 strategies performed during this last 1 month. I have some correlations to be resolved and here it is. And don’t really look at the results because I have run the Generator just for less than a minute.
But, for example, looking at the first 2 strategies, what I have here is the first strategy had 2 trades for this month and they were on profit.
If I click on Report and I go to Journal, I have 2 short trades and both had $61.80 as a profit. What about the second strategy?
Better to have a few positive trades
It had 9 trades during the month.
And then if I go to the Report, I can see exactly what were the trades. Some decent trades over here. So this is how you can backtest Expert Advisors for Forex trading with EA Studio using the historical data, and it’s a really quick method to do that.
Just remove the recent 1 month, and then recalculate the strategies for this 1 month.
The 3rd Method to Backtest Expert Advisor
The third method is the most common one and this is what I show in most of my courses. Let me go back to Data Horizon, I will bring it back to the way it was, 15th of July, 2015.
I will not use the end date limit. I go back to the Collection, I recalculate the strategies that I generated quickly, and here they are. Now, what is the third method to backtest Expert Advisor? The most common way to test Expert Advisors is to place them on MetaTrader with EA Studio.
It’s very quick because, with one click, you download the strategies. So when you have many Expert Advisors, you can put them on MetaTrader and leave them trading for 1 month on a virtual account. And then with the Magic numbers, we see which are the top performers following the results in FX Blue, MyFXBook, what I show in my other courses.
Have 2 MetaTrader platforms installed on your computer
And this is really a great method to test many Expert Advisors by placing them on Meta Trader. But as you know, each Expert Advisor works on a separate chart. So sometimes it’s a little bit of work. For example, if you are trading with 99 Robots like what I demonstrate in my Automated Forex trading course, we need to have 99 different charts opened and then we need to place 99 Experts.
It takes some time. For some people, it’s a lot of work. For me, it’s not because I’m used to it and it happens quite quickly. But for this method, you need to leave your Meta Trader open all the time. And something very important, if you are testing Expert Advisors on a Demo account to see which are the top performers to place on a live account, make sure you have 2 Meta Trader platforms installed on your computer.
Don’t switch between Demo and live account because if you are in Demo, you put many Expert Advisors, they start trading, and then you switch to a live account in the same platform, you will disable the Demo account and the other way around.
If you are in a live account and you switch it to Demo, you will disable the live account. So if you have live and Demo account, you need to have 2 different platforms. So this is the third method, the one that I show in most of my courses.
Backtesting Expert Advisors might be a lot of work
But, one more time, it takes a little bit more work to place each Expert Advisor on a separate chart. And if you are testing hundreds of Expert Advisors, it is a lot of work and this is what I do. But this is my job so I don’t complain about it.
The fourth method which saves me a lot of time, and this is what I will show you in this course, is to generate the strategies and then I download just the Collection. From there, I wait for 1 month. For 1 month I don’t do anything.
I just wait, prepare my next strategies, I record courses, I travel a lot recently, basically, nothing to do with this Collection. So usually, with this method, I do not backtest Expert Advisor in the past but I wait 1 month for the new unknown data. I gust generate strategies for different assets.
And then I will download the Collection and I will do nothing for 1 month. Why? After 1 month, I will add the data for the last month, I will download it from the Forex Historical Data App, and then I will recalculate the strategies in the Collection.
This is a real future testing for the strategies. I don’t know what will be the data in the next 1 month. Nobody knows that. But I’m generating the strategies now and I will save them as Collection, this is the easiest way to go. After 1 month, I will add this new data in EA Studio and I will recalculate the strategies.
It is easy to do all of that with EA Studio:
How to Backtest Forex Expert Advisors – the only way to test a strategy
Now, I will show you how to backtest Expert Advisor when you place them on the MetaTrader platform. Now, what backtest means is that you can actually see the results for this Expert Advisor for this strategy on MT4, over the past. And this is possible with MetaTrader because we see the charts back in time.
This lecture is free and it is part of the complete MetaTrader course called MetaTrader 4 Forex platform: Start trading with a pro trader
What I showed you with the other platform right here, trading the strategy manually, is because I wanted to show you how these strategies work:
- where exactly is the entry,
- where exactly is the exit,
- the Stop Loss,
- the Take Profit etc.
Historical data and EA Backtesting
But imagine here if I press the HOME key on my keyboard, I will go back to the beginning. This means the maximum chart I see back in time.
And if I take the cross here, this is 9th of January, 2018, so imagine I go 1 year back to follow every signal and every confirmation, it will take me a long time and I cannot do it so precisely. So what we can do with MetaTrader is actually to perform a backtest.
What do we see when Backtesting Forex EAs:
- entries for the trades
- exits for the trades
- the exact time the orders were executed
- trades that we were having with the strategy, for all of the historical data.
We say this is historical data. The chart back in time.
If you don’t see much historical data you should press the HOME key on your keyboard and hold it. Because I have already done that, it’s not moving. But normally if you have just installed a MetaTrader and you press HOME key it will move quickly. Just like this, and it will load you as maximum as possible.
Have much data while conducting a backtest
So when we do backtesting Forex EAs, it’s good to have as much data as possible. And what you need to do in order to perform the backtest, is just right click and then go to Expert Advisors and then go to MT4 Strategy Tester or you can press F6 as well. You see a small window comes up where we have the symbol and we have the Expert Advisor. We don’t need to change anything right here:
And then you have model, open prices only, you have three options normally with MetaTrader:
- every tick,
- control points
- open prices only.
This is how we create our strategies to open the trades on the open of the bar as I have explained why.
That is why here, as a model, you need to select open prices only. This is if you want to select a date, from which to which date to test the strategy. Or if you untick it, you will be using the whole data. The whole historical charts that you have with your broker that is. And then here you have visual mode so I will first remove it and then I will show you what the difference is if we use it.
And then on the right side, you have the period, so it’s on H1 and then you have the spread. You can enter any spread or you can leave it to current. Now, one of the other reasons that I have decided to show you on this platform is because here, my spread is a little bit bigger with this broker.
Why I perform backtesting with Expert Advisors on different brokers
If I go to spread, you will see that it’s just a little bit above one pip for the major currencies, which for me is high spread. But for all the Expert Advisors for all my courses, I always test the Expert Advisors on a few different brokers to make sure that they’re working properly for different brokers. Because obviously, you, as a trader, will take it and you will place this Expert Advisor on some other broker, so I always make sure that it works on a couple of different brokers well.
And of course, I cannot test it on all brokers because as we said at the beginning of the course there are thousands of brokers but I always test it on few brokers to make sure they work properly. So here as a spread I normally leave it to current spread. If I press on start you will see very quickly the backtesting Forex test is done.
And I go to results and here you can see all the trades that were opened and closed, the profit, the losses that we have, the balance on the right side, what it was was it a sell, what happened after that Take Profit was hit, then another sell Stop Loss was hit, then another sell Take Profit was hit and so on. If you go to the graph, you will see the equity line of this Expert Advisor. So here you can see that we have so far very good equity line for this Expert Advisor.
Use a Demo account first.
Of course, as I’ve mentioned it is never a guarantee that the performance will continue. That’s why the best thing to do is to test these Expert Advisors on Demo account. And if you like their performance you can try them on the live account. But one more time this is your own risk that you’re taking, your own responsibility.
The purpose of the lecture is just educational
I provide these Expert Advisors for you, guys, just to give it a try, to practice trading with Expert Advisors and see if you will like it. Then with the Backtesting Forex report, we have some more statistics as profit factor, which is the ratio between the net profit and the net loss. And then we have the absolute drawdown, total trades. So you see there was an execution of 581 trades with the backtest, which is a pretty good number I can say to depend on this strategy.
So, there was the execution of 581 trades during the backtest. We can say this is a robust strategy because if we were having only 10, 20, 50 trades, it would be a very small number to depend on this strategy. And there are other statistics here that I’m not going to read all of them. Then in the journal, there are some more details about each open trade.
Backtesting Expert Advisor in visual mode
So now, I said that I will do a backtest with a visual mode so we can see the difference. And here we have a scale from which we can change the speed. So let’s leave it to the middle and I will press start which means it will perform another backtest.
As you can see, it shows us the backtesting Forex test very slowly where the trade was opened. For example, here we have a buy order. Where was the Stop Loss, here was the Take Profit hit, another order etc. And if I just move it a little bit to the right it will go a little bit faster.
So here you can see how it is moving. How the chart is moving, what happened in history, where the trades were opened, where was the Stop Loss, the Take Profit. Just the Take Profit was hit and another trade was opened. And normally, when we use the visual mode it opens another chart. So it’s not over the EURGBP where I have started the backtest.
It opens another visual chart and if I just make it to the right to the maximum you will see how quick it is and it does the backtesting Forex strategy test. It shows you the indicators but as we said, if we are trading with the Expert Advisors, we don’t need to place the indicators over the chart. Just at the end of the visual backtest it shows us the indicators.
The visual mode gives an idea of how active the strategy is.
And here again, if I go to the results, to the graph you will see the graph. So the visual mode gives us an idea, how active is the strategy, how many trades were opened, and you see if I just go back there are small arrows. When we have a long trade we see a green arrow, and then where it was closed.
And then we have a short trade with a red arrow, and then here the Stop Loss was hit. So here when we have a Stop Loss hit or a negative trade, we see this red line and when we have this profitable trade, like here, we see a blue line. I don’t know if it is really visual but you can see there is one blue line, as well here there is a blue line and so on.
And then here, there’s another red line, so here the trade was open for quite a long time and then other trades are here. The visual mode gives us a better idea about the strategy, you can play around with it it’s very interesting. I will close it and I will do a backtesting Forex test for the others as well.
So this was for EURGBP, I will do it for EURUSD as well. I will go to Expert Advisor, strategy tester…so you can see when I go from the chart where the Expert Advisor is, we have everything set here; the chart, time frame, the Expert Advisor, nothing really to do. Let me slow it down a little bit so you can see how this strategy will work. I will just start moving it a little bit to the right.
Backtesting the trading strategies is fast because the code of the Expert Advisors is well written
Here it is, you can see the trades are opening, closing, opening, closing and let’s make it really quick. You can see it performs the backtest very quick because the coding of the Expert Advisors is very good. There is nothing unnecessary in the code which makes the backtest very quick.
And in the results and the graph you can see the graph of this strategy for EURUSD and here is the report and here is the journal. And I will make a backtest as well for a GBPUSD. Right-mouse, expert advisors, strategy tester and I will make it a little bit to the left first.
I press on start and you will see how the price is moving. This Expert Advisor, if you remember the strategy, it has a signal and then it has two other indicators which are confirming the trade. That’s why you see there are not so many trades like the other Expert Advisors, but only when the other indicators confirm the new trade.
Backtest Expert Advisor with your broker data as every broker has different historical data
Let’s make it quick and we will see the results. Here, the indicators that were used are displayed and I go to results, then to graph and you see another very stable graph that I have. So to make it one more time clear, when I am building these strategies, these Expert Advisors, I am using the historical data of one broker.
Then I do backtest on a couple of more brokers. I do this to make sure that the performance of the Expert Advisors remains profitable. So it is good to make a backtest on your broker when you place it because every broker has different historical data. This is very important.
The different brokers provide different bid and ask price, they provide different spread which forms different candlesticks. It could be a very small difference, guys, but with algorithmic trading, it is not a small difference. That is why it is good to make such a backtest to see the performance of your broker.
Expert Advisors from the market are very expensive.
But one more time, the course is for educational purposes. I provided these three Expert Advisors so you can actually get free Expert Advisors. Because, if you want to buy Expert Advisors from the market they are very expensive. Also, basically, you don’t know what you are buying. Backtesting EAs does not guarantee future profitable trading.
So here, I have explained what exactly the strategy is, where exactly the trade is opened, where exactly it is closed and as well I have shown you how to place them over the chart and how to perform Expert Advisor backtest in MT4. One more time the EA backtest is not a guarantee that this strategy will continue trading profitably in the future. And that is why I am trading with many Expert Advisors over different currency pairs, different assets, cryptocurrencies, commodities, stocks but mostly I am trading Forex.
I am testing hundreds of Expert Advisors on a Demo account. I am doing a lot of backtesting and I choose which ones to use on my live accounts. And if any starts to lose, I just replace it with another one. One that I have already created, backtested and tested on all Demo account. Alright?
Test the different ways to backtest Expert Advisor and see which one works for you.
And I will see which strategies performed the best during this 1 month and those strategies, I will be trading. This is really a time-saving method and I’m using it more recently and I will demonstrate it to you in the 30 Best Strategies course.
In the course, I will show you the whole process and how exactly I’m trading with the strategies, and how easy is to backtest Expert Advisor.
Thank you for reading the lecture and if you have any questions, post them below in the comments or in our trading Forum.