Walk Forward Analysis for Metatrader 4
Walk Forward Analysis for Metatrader 4 is a very interesting tool that we have in EA Studio. It is a little bit more advanced, a little bit more complicated. But if you are a beginner trader, just go through the lecture so you will have an idea about it and later on, you can come back to it and learn it in more details. My name is Petko Aleksandrov, and I will teach you how to use it.
So if I have a strategy, doesn’t matter what strategy, let me quickly generate some strategies over here. Just randomly without having Acceptance criteria, so I can have an example. You see hundreds of strategies already calculated.
And when we see the 100 strategies calculated, we need to click on refresh so the new ones will show on the top because in the collection we see always the top 100 strategies. So I will take any random strategy, just which I like, and here let me refresh it one more time. This strategy has just a few trades, anyway, the equity line is good.
Walk Forward Analysis for Metatrader 4 – the tool to prove a strategy is not over-optimized
I will take the first one, it’s not really important what strategy we’ll use. There are some Drowndowns and this is one of the things that I want to show you and explain in the Walk Forward. So when we have a strategy, doesn’t matter if it’s generated, did we build it by adding different entry and exit conditions, we can perform the Walk Forward Analysis for Metatrader 4.
What it means, this validation, it just gives us an idea if the strategy is over-optimized or not. And it doesn’t change the strategy. When we test with the Walk Forward Analysis for Metatrader 4, with the Monte Carlo, with the Multi Market, these tools just give us different signs if this strategy is over optimized or not.
And what is over optimized guys? I will talk a little bit about the optimizer as well. Now every strategy has indicators with different parameters. Right? And as I showed already, when we are changing the parameter, the equity line changes.
Optimizing the strategy is risky.
What we have is normally the optimizer, we have it as well in Meta Trader, we can optimize the strategies. So if I optimize the strategy I will click on start, the balance chart is changing. And normal is changing to better strategy, smoother strategy, because the Expert Advisor Studio here finds the better parameters for this strategy.
You see there is the value which was the initial value over here, the minimum and the maximum range from where we want to go and the step. Which means that it will test all variations with 74, 75, 76, until 114. It will find the best one and it will do it for all of the rest.
And in the end, we will see these parameters which are best for this strategy and you can see the equity line is so much better. Now the problem is that when we optimize the strategy in this way, it doesn’t matter if it’s here or is it in Meta Trader, we have the risk to over-optimize the strategy. This means that we will find the best parameters for this period of time here, for our historical data.
Parameters are fit to the Historical data/
So it is like we find for the Stochastic, for the Aligator, for the RVI, for the Envelopes, the best parameters to see such a nice equity line and the best Stop Loss and Take Profit. You see if I change it now down to 70, you can see there is a change. It’s getting worse. With 80, it’s getting better.
And if I increase it to 80, it’s getting better. And if I increase it to 90, it will get a little bit worse because this parameter of 80 was the best one found for this strategy. Now when we optimize a strategy, we are in the risk that after we place the Expert Advisor for trading, it will start losing or it will not perform the same as with the backtest.
Because one more time, these parameters were found to be best for this period of time. So with these robustness tools, we want to test the strategies, if they are over-optimized and if we can depend on them. And there is one more thing that I need to say before I explain the Walk Forward Analysis for Metatrader 4.
In Sample and Out of Sample options.
When we are generating strategies, we have this Out of Sample option, which I will explain in just a few words very simply. Let me remove all the generated strategies and I go over there. So I will run the generator now but instead of In Sample, I will use for example 20% Out of Sample.
What that means is that the generator will use 80% of the historical data, from this same historical data that we have exported from the broker, but it will use only 80% of it. OK? And with the other 20, it will simulate trading. So what it will do basically, it will generate the strategies using the 80% of the historical data and with the rest twenty, it will simulate trading.
So it will be something like if we have placed the strategy some time ago, like 20% ago the whole period. And you will see it now very visually over here. You can see the balance chart is divided. We have this white zone which is called In Sample and then here we have the Out Of Sample.
The generator tests the strategy for unknown data.
And you see actually a very nice strategy was just shown over here. And if I click on it you will see the entry and exit condition. So going one more time to the collection, 80% of the time the generator used to create the strategy and after that for the rest 20, it was testing the strategy.
And this first strategy actually showed a great profit. You can see the second one again shows a profit, even here was not really good in the 80%. And then here. And you see some strategies are actually losing. So this Out of Sample is very interesting because it shows us how this strategy would perform for the last 20%.
Let me delete now the strategies into the collection. And I will go to the generator and I will run it again with the same strategy properties. And as generator settings, I will do it In Sample. So I will use the whole period.
I will click on the generator and you will see how many strategies immediately will be calculated there. Alright? Let me click on the first one and I will go to the Walk Forward Analysis for Metatrader 4. You see it has a very nice balance chart and I will go to the Walk Forward Analysis for Metatrader 4. And what you will notice here is that it is divided into different segments. And I will click on start and it will start the Walk Forward Analysis for Metatrader 4
Walk Forward Analysis for Metatrader 4.
It uses this initial historical data to optimize the strategy. And then for the first segment, it simulates trading. You see this is the original line here, the original equity line and the orange one is the one that is simulated trading.
After that it will include this segment and the previous data, it will make optimization of it and it will show simulated trading for the next segment. You can see here below the Purple Line is the optimization and the Green Line is the actual test. So one more time it starts from the beginning, it optimizes the strategy for this period of time and then it simulates trading for the first segment.
After that with these new parameters, it optimizes the strategy but including this segment. And then it will optimize it for the whole part and then it will run an optimization on the next segment. After that, it will include it and then it will perform simulation on the next segment and so on till the end.
Before and after optimization.
And you see there is not really a dramatic change over here with these parameters. But what you see is that before optimization, the fourth segment was having a loss and it’s this one over here.
And after the optimization, it is actually profit. So all of the parts are with profit after the optimization. And the Gain is the difference between the two, After Optimization and Before Optimization.
In the end, you can see that even the original line is a little bit better. But here, we can say, that the five elements, the five segments, are positive and this shows that this is validated and the validated is from here.
Criteria for validation.
I have selected to use a small profit of 10. In options, you can change the number of segments from 1 to 12. And you can change the Out of Sample from 30 down to 10, 20, 40, 50, I keep it as default in 30. And then there are the steps.
So same as with the optimizer, what steps to have for the parameter. So, for example, if it is plus-minus 20, it will check the momentum from 0 to 30. OK? Minus 20 plus 20, it will be from 0 to 30.
And for the rest is the same. Now if I go to the collection and one more time I show you all of the strategies when we look at the strategies we don’t know which one is over optimized. We don’t know where we have the risk from over optimization.
The idea of the Walk Forward Analysis for Metatrader 4.
The idea is that it gives us a sign if the strategy is over optimized or not. For example, I will take one strategy, again randomly. I will optimize it. I will click on start, I will optimize the strategy and it will find me these best parameters for all of the indicators.
It will show me this very nice balance chart or the equity line. And let me just wait a little bit to complete the optimization and I will show you what is the result when we do the Walk Forward Analysis for Metatrader 4 over-optimized strategy. Because especially when we are using optimization, with step 1, we are over optimizing the strategy.
We find these very best parameters for this period of time, for these indicators, for this asset for this time frame. And it finds these best parameters but actually, I lost it when I switched so I will do it one more time. It will optimize very quickly.
What I wanted to say is that when we do optimization especially with step 1, we will over optimize the strategy most probably. Because we are fitting the best parameters for this time frame, for this asset, for this historical data that we are using. And when we have such a strategy with such a great equity line, these are normally the strategies that you will see on the market.
The over-optimized strategies are being offered on sale.
People are selling these over optimized strategies. And what happens after you buy such a strategy, you make a backtest and you say whoa! Great profit line I will make money right now with this Expert Advisor.
And when you place it on the Meta Trader and you start actual trading you will see losses. Because when we over optimize the strategy, the chance of this strategy to fail in the future is huge. And by using the robustness tools, we want to recognize these strategies. Alright?
Now if I go to the Walk Forward Analysis for Metatrader 4 with this strategy and I click on start, you will see what will be the result. It will show me worse result with this strategy than the original line. Because the strategy was over optimized for the whole period and what Walk-Forward does, it optimizes the strategy for a small period of the historical data then simulates trading.
Then it includes the first segment, optimizes again and simulates trading. And then it will include now the second segment and it will simulate trading on the third segment and you will see that probably it will be a worse result. Because one more time the strategy was over optimized for the whole period.
The strategy’s performance is poor with simulated trading.
Which doesn’t mean that in the future it will continue profiting and this is just a proof of it. That when we have simulated trading, the strategy performs worse. Alright? Let me stop it now. You see the 4th segment was worse and if I continue, the 5th would be worse as well:
One more time, when the strategy is over optimized and when we are running the generator, we have the chance actually to hit on over optimized strategies. So when we are using the Walk Forward Analysis for Metatrader 4 and if it does not pass this validation, then this gives us a sign that the strategy is over optimized. And we don’t want to trade over optimized strategies.
We want to trade stable strategies that we can expect to perform well in the future. Of course, if it validates the Walk Forward, it is never a guarantee that this strategy will continue. But it is something on our side. OK?
And then when we combine it in the Monte Carlo and the Multi Market which I will show in the next lectures, we have much bigger chances on our side. And one more time we say that it is validated when we have a small profit. I selected this to be my validation criteria. You can add any validation criteria from the button Add validation criteria. Alright, guys?
The Walk Forward Analysis for Metatrader 4 shows whether the strategy was over optimized.
So really to summarize this lecture, the Walk Forward validation gives us an idea if the strategy was over optimized. Because if it was over optimized, the Walk Forward Analysis for Metatrader 4 will fail as I showed to you. It will show worse results than the original equity line.
Just because it is optimizing each part and then it’s simulating trading. Then it is optimizing again including this recent period and then simulating again. Then it’s optimizing again and so on and so on. So if the strategy was over optimized for the whole period, the Walk Forward will not be able to get better results in the different segments. OK? I really hope this makes sense. As I said in the beginning, it’s a little bit more advanced.
It could be a little bit more complicated. I am expecting some more improvements actually on the Walk Forward Analysis for Metatrader 4 from the Forex Software Company which developed this software, as I have information from them. And I hope it will become an even better tool to filter the strategies and to see which strategies are over optimized. I mean just to ignore them. Alright?
Thank you very much for watching this lecture, don’t hesitate to ask me questions in our forum. I will answer you always in details.
Cheers guys. Bye.