Metatrader Expert Advisor robustness


Dear students, I continue now with the
robustness of the Expert Advisors with the Meta Trader platform.
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. OK? So we want to find the strategies that are robust, that show
backtests with nice results but have chances to continue trading profitably
in the future. I will show you how to avoid the over optimization with the
Meta Trader platform in this lecture. Now let me put this 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. OK? So I have the 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. You will see the window that pops up below. And what we have here,
we have this 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. 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. OK? Until today
which is 4th of March, 2019. OK? 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 the backtest was. 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. 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. OK? 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 an 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. OK? 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. OK? 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 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 Expert Advisor really randomly to show you how you can
check the robustness with the Expert Advisor. OK? 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. OK? 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. 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. OK? 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. 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. OK? 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. OK? 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
Expert Advisor. OK? 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. OK? 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. OK?
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. So you see the difference, it was 11,519 now it’s 10,372. OK? 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.
OK? 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. OK? There is a chance that it will, but most probably it will
fail. OK? 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. OK? 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.
OK? 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. OK?
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. OK? 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. 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. OK? Thank you very much for watching the
lecture and I will continue straight away with the next one. Cheers

Leave a Reply

Your email address will not be published. Required fields are marked *