MQL5 TUTORIAL – HOW TO AVOID NASTY BACKTESTING ERRORS

video
play-sharp-fill

In this video, we are talking about issues with the historical data that you need to use for your Strategy Tester. This is an Expert Advisor that is going to trade time based entries.

If you look at the settings here for the strategy test, you will see that I have selected the one-minute chart, but right now it only has data for hourly charts.

You see the time changing and now it’s 4 o’clock PM and now its 5 PM, this is 6PM lets speed that up little bit. This is the next day, this is 2PM, 3PM, 4PM, 5PM and suddenly at 6:45 PM it starts to count the minutes – you can’t see anything on the chart here.

The only thing you notice is that the candles are much smaller. This candle is from 6PM, that’s 45min earlier and we are on a one-minute chat. If you don’t know how to find errors like this it can drive you crazy, because 44 missing candles can make the difference between profit and loss.
In Metatrader 4, you would have seen this in the history files and you would have been able to press F2, but Metatrader 5 unfortunately doesn’t allow this anymore, so we just need to help ourselves and try to find the cause.
The Metatrader 5 help file contains the post about files and folders – this is the web version of it and if you scroll down you will find that there is a basis directory that contains the platform’s data bases grouped by servers.
So, let’s click on “View” and “Navigator”, we have a Metaquotes Demo Account that was included in the installation of Metatrader 5 and right now I am on the Roboforex Account and they say that within the default directory we should find a folder called: “History”.

And the folder stores history data for financial instruments. The “Default” folder here is what you see if you click on “File/ Open Data Folder” and actually here you will find a folder called: “bases” and within the “bases” folder we find the MetaQuotes-Demo and the RoboForex-MetaTrader 5 directory.
Let’s click on the second folder and here we will find another folder called: “history”, and here within the history folder you will see that we have different directories for each and every currency pair. Well, we use the EURUSD for 2016, so let’s switch to the EURUSD folder and here is a file called: 2016.hcc.

Now I will try to open it, but unfortunately, it’s not readable because it’s a compiled file. So, let’s delete that file, now it’s gone, start another test and Metatrader is doing exactly the same as before. On the next day at 18:45 it starts to count minute bars. So, obviously this didn’t change anything.
The next step is: to look into the MetaQuotes-Demo folder, here we will find another history folder. This one also contains a directory called: EURUSD, so let’s delete the file here and try it for the second time. I start the test and we have the same problem once again. Now, what is going on here?
Let’s have a look! I don’t see any history files for 2016 in the MetaQuotes-Demo folder but in the RoboForex folder for history files a new hcc file for 2016 has been created. So, let’s switch to the MetaQuotes Demo Account and start another test. And it does exactly the same as it did before.
Well, this is a fresh installation on another PC, let’s download the history from the MetaQuotes server for 2016 and this file is obviously much larger than the original version.

So, let’s copy that and paste it here and restart Metatrader 5 again. Once again, I need to connect to the MetaQuotes Demo Account, select my currency pair here and start the test, and this time it really works!
It took me about an hour to fix this error and when you think that you get insane looking for an error that couldn’t be there, maybe the cause is just a corrupt history file and that’s why I always tell everybody, it’s a good idea to test different brokers and to use more than one Metatrader 5 installation otherwise you wouldn’t be able to find the cause because this is a compiled file and we can’t see what’s inside!
Okay.
Now my Expert Advisor is working and now you know how you can avoid problems that are caused by corrupt history files and how to fix it.