Metatrader Expert Advisor – the way to trade automatically and avoid emotions while trading
Metatrader Expert Advisor and its robustness is what we will talk about in this article. This is a free lecture from the Algorithmic trading strategies Top 10 USDCAD EAs course.
What is Robustness?
Basically, when we are doing the backtest, we see the result for this strategy in the past for some period of time. We are testing this strategy for some period of time and we see a backtest. Now, if you see a very nice backtest, this doesn’t mean that the strategy will continue profitably in the future. So we want to find the strategies that are robust, that show backtests with nice results but with chances to continue trading profitably in the future.
I will show you how to avoid the over optimization with a Metatrader Expert Advisor in this lecture. Now, let me put this Metatrader Expert Advisor back on the chart. I will drag it one more time over here:
And I will click on OK and here it is. So I have the Metatrader Expert Advisor over the chart and I want to backtest it. I will right-click and I will go to Expert Advisors and I will go to Strategy Tester.
These Expert Advisors use the opening of the bar.
You will see the window that pops up below. And what we have here, we have this Metatrader Expert Advisor, this currency pair. As Model, I will use Open prices only because the Expert Advisors that I’m using and those that I will include in the course, as we said, are using the opening of the bar.
What means Open prices only when backtesting Metatrader Expert Advisor?
- the Backtester will execute the trades on the opening of each bar
- the closing price of the previous bar is very close but not the same
- this method is most reliable when using EA Studio strategy builder
- the brokers do not provide tick data, that is why it is good to use Open prices
This is the moment when they check if the entry conditions are there. And what we will use below is the data from…what we have here is 2017, 30th of October. Let’s make it from the beginning of last year. So we’ll go to the 1st of January.
Until today which is 4th of March, 2019. So we’ll be testing it for one year and three months. Alright? It is on M15. We will use the current spread that we have at the market for the moment.
So I will click on Start and you will see how quick was the backtest. This is because the code of these Experts Advisors is really good, nothing complicated or nothing unnecessary there. That’s why it works extremely fast with Meta Trader.
You can see all opened and closed trades for any period.
And if I go to the results you will see all trades that were open and closed. You can see this is 2nd January 2008, in the first, there was a sale, then we have another sale, sale. And here is the result and the balance and you can see all the trades that were opened with this strategy for the last 1 year and 3 months.
Sorry, actually 2 months because we are at the beginning of March 2019. So 1 year and 2 months, we can say, it’s a 14 month period. If I go to the graph, you will see we have this normal graph, we can say, for a Metatrader Expert Advisor.
It goes up and down. There are some drawdowns but not huge ones. There is some stagnation of course. But finally, we are on a profit.
And now when we are talking about over optimization, this is what exactly we don’t want to see. One straight line which will show you only profit, profit, profit, profit, and nearly without any losses. And these are the Expert Advisors we want to avoid, where we have the perfect parameters for the strategy to show you this great backtest.
What stagnation of the equity line means with a Metatrader Expert Advisor.
I want to see in my trading, Expert Advisors that are having this curve line where we have up and down, up and down, but it goes up. Now I have selected here just a random, normal Metatrader Expert Advisor for the USDCAD where the equity line goals in a profit, goes down. You see there is a huge period here in stagnation.
What the stagnation means is for a long time the price didn’t succeed to reach a better profit than the previous point. So, for example, here it reached this point and you can see after that for a long time until here it did not make a better profit than this moment over here. So this whole thing is called stagnation.
But I just took this Metatrader Expert Advisor really randomly to show you how you can check the robustness with the Expert Advisor. So here are the settings of this Expert Advisor, and finally, the result, what we have is 11,105. This is starting with $10,000 of account.
You see if I go to export properties it is testing with $10,000 of account. Here are the inputs. Now one of the oldest methods, I can say, in testing robustness with Expert Advisors is to change some of the values and see if the result will stay similar or not.
What changing the parameters will do to the Metatrader Expert Advisor.
For example, here we have a Stop Loss of 94 pips and Take Profit of 55 pips. Now let’s make this Stop Loss 4 pips lower.
I will do it 90 and I will click on OK. Alright? Now I will click on Start again and I will see what the result is.
You see the line is pretty much the same. What we have actually is a better result. You see I have 11,201. Alright? So this means that with this Stop Loss the strategy was even a little bit better.
But what it means actually for me is that the strategy is not over-optimized. Changing a parameter didn’t change crucially the strategy. Now let’s change the Take Profit as well.
I will do it Take Profit of 60 instead of 55. I will click on OK and I will do the backtest again. You see the graph, it’s pretty much similar. Here you can notice that the stagnation is a little bit bigger I think, a little bit more of a drawdown here.
What is an over-optimized strategy?
- Metatrader Expert Advisor that was fit to the past Historical data
- The parameters of the indicators are optimized for the tested period
- There is a huge chance that this strategy will fail in the future
- Robustness testing is a must to avoid trading with over-optimized strategies
And the results, what we have is 10,895. So now it is getting actually worse when I changed this parameter. But one more time it didn’t change crucially, I’m having very same equity line.
And what would be an over-optimized strategy is when we change some of the parameters and we see a totally different result. And I will show you such a strategy right now. Let me remove this one from the chart.
Right-click, Expert Advisors, I go to Remove and then I will drop another strategy and the Meta Trader. I will go to File open, Data folder, MQL4 and I will go to Experts and let me delete this one so I don’t make a mistake which one I’m backtesting. Here it is, I will double-click on it and I will compile it.
One more time you can compile it from the folder on the Navigator from right over here. If I just click right mouse and refresh, this will still compile the Metatrader Expert Advisor. I will drop it over the chart and here are the parameters
for this strategy.
I will click on OK and you see it is attached on the chart. Now I can change the Expert Advisor from here but actually, I deleted the old one, so I have only this one. Anyway, if you do it for the first time, one more time you go to Expert Advisors and you click on Strategy Tester and it will be the one that is attached on the chart.
So you see if I click on Start, I will have the equity line which is pretty nice. Actually even better than the previous strategy. But if I go to Settings and I go to Expert properties and I go to Inputs, let’s say I will change here some of the parameters of the indicators.
For example, RVI is 40. I will change it to 45. Actually, let me see first what the result was exactly with the backtest. So the graph is good, the result is 11,519. Alright? Let me write it down on my next screen, 11,519.
I will go to Settings and I will change some of the parameters, for example, RVI, I will change it to 35 and I will click on OK and I will perform the backtest. I will go to the graph and you can see what a different graph I have. Still positive, what we have as a result is here, it’s 10,372.
The Backtest of a Metatrader Expert Advisor.
So you see the difference, it was 11,519 now it’s 10,372. Let me change some other parameters. So here it was 40, let’s increase it, let’s make it 45 instead of 5 lower.
I will go to 5 higher and I will click on OK, I will click on Start and I will go to the results graph. Now you can see what I’m talking about. I see a negative equity line. Just a change in one of the parameters and what we have as a balance is 9,462.
So this shows me that this strategy was over-optimized. These properties that I had, exactly with the 40, exactly the Stop Loss and Take Profit exactly with the other parameters, it was over-optimized. So when I click on Start and I do the backtest I see a very nice equity line.
But this is because these parameters for these indicators were fit to this testing period. And we cannot depend that this strategy will perform well in the future. Maybe it will. There is a chance that it will, but most probably it will fail.
The indicators were set to show a good equity line with the Metatrader Expert Advisor.
Because the indicators, the parameters’ indicators were set in such a way so it will show me a good equity line during this test period with these parameters. Exactly with these parameters and one more time let me change something else to demonstrate it once again. For example, I will change the average true range from 47 to 50. Very close number.
I will click on OK, I will click on start and I will go to the graph. You can see it’s losing again. So this is one of the best ways in Meta Trader that you can check if your Expert Advisor is over-optimized, no matter whether you buy it from the market, you take it from somewhere, it is always good to perform a few backtests with different parameters to make sure that you are not going to trade with over-optimized strategy.
With a strategy that was fit to this trading period that you’re testing, or it could be actually for the last 10 years, or even for the 20 years it doesn’t matter, it could be any period. I just selected the last one here from 2018 till now. Alright, guys? This is how you can check if your strategy was over-optimized with Meta Trader.
Make only small changes to the parameters.
Just change in the Expert properties some parameters. Not too much, as you saw just with 2, 3 points or 5 points up and down and if you see a dramatic change in the equity line this will show you that probably this strategy is over-optimized.
Thank you very much for reading the lecture! This is a free lecture from the course Algorithmic trading strategies Top 10 USDCAD EAs.
If you have any question, feel free to drop it in our Forum and I will make sure to answer as soon as possible. Also, in the Forum you will meet fellow traders which will share heir experience with you. This a great place where traders exchange ideas, test Expert Advisors together and benefit from each other’s experience. The Forum is free to access and everyone with a registration on our website can access to it, and write questions. Everybody is welcome to join!