Top Menu

Feedburner

Right-Side Top Menu

MetaTrader History Data Importing and Converting Tutorial for Quality Backtesting

January 3, 2008 (Last updated on March 1, 2011)

Backtesting MetaTrader expert advisors on historical data is a good way to test a strategy. But testing on the limited data supplied with MT4 installation gives a very poor quality of testing (usually below 50%). So, how to achieve a 90% quality in backtesting of MT4 expert advisors? It’s not that hard really, just follow this simple tutorial and you will able to test any MetaTrader EA.

1. Download a new MetaTrader 4 installation and install it to a separate folder. Be advised that a good MetaTrader historical data take up a lot of disk space, so install it to a drive with at least 1–2 Gbytes of free space. For download MT4 installation I recommend official MetaQuotes site.

2. After you install your MT4, don’t run it yet. Go to the folder you have installed it to. Go the ‘history’ folder there and delete all folders there (the actual folders names inside the ‘history’ folder may be different from those on these pictures):
MT4 History Folder

Deleting Previous MT4 History

3. Run the newly installed MetaTrader and open a free demo account with whatever broker it will be offering to you (official MetaQuotes installation offers random brokers for demo account opening in its MT4). Login to your account and close all open charts (if any).

4. Adjust the MetaTrader options to allow larger charts (more bars in history):
MT4 History Options

Set MT4 Historical Bars Number to Maximum
Then close your MetaTrader.

5. Download a quality historical data for every currency pair you want to test your expert advisor on. I recommend Alpari History Center for this — download M1 data for each of the currency pairs you need. You’ll probably won’t need to follow the next steps listed here. Just follow the instructions listed on the Alpari’s historic data page and proceed to step 13 here.

6. Unzip the archive with M1 historical data somewhere. Rename it to comply with MT4 standard naming — i.e. EUR/USD M1 chart should be named EURUSD1.hst, GBP/USD M1 should be renamed to GBPUSD1.hst, etc.

7. Copy the renamed history file to your MetaTrader’s ‘history’ folder into your broker’s folder (overwrite if prompted):
Saving Downloaded MT4 History

8. Launch MetaTrader 4 again. Don’t open any charts on-line, open your downloaded M1 chart offline (example shown for EUR/USD chart):
Opening MT4 History Offline

Select M1 Timeframe

9. It might take some time for the actual chart to load, but it’s OK. Now you need to convert M1 history to every timeframe you will need. For this you need to use a period_converter script which is a standard feature of all MT4 platforms. Run it from the Scripts tab and set its ExtPeriodMultiplier input parameter to the number of minutes in the desired output timeframe. For M5 enter 5, for M15 enter 15, for M30 enter 30, for H1 enter 60, for H4 enter 240, for D1 enter 1440, for W1 enter 10080, MN isn’t convertible as there is no fixed amount of minutes in one month:
Convert Other MT4 Periods from M1

10. Wait for the script to finish its work (may take up some time; it’s more than 2 years of data after all):
Making Sure That All Bars Are Converted

11. Repeat steps 8–10 for all timeframes you want to get.

12. Repeat steps 5–11 for all currency pairs you want to test your MT4 EAs on.

13. Voilà! Now you can enjoy a 90% quality backtesting and test every expert advisor you want on the time periods of more than 2 years. Good luck with your trading!

81 Responses to “MetaTrader History Data Importing and Converting Tutorial for Quality Backtesting”

  1. xma

    very good manual! I have a queston.When I converted the 1H timeframe to 2H timeframe.How to choice 2H timeframe in strategy tester?I can select m1,m5,m15,m30,H1,4 daily but the 2H timeframe is not present in startegy tester,but i converted it and i see when i opening chart offline.
    Sorry for my english .

    Thanks

    Reply

  2. enivid

    First, thanks for using this tutorial. Second, it’s better create all timeframes from M1 timeframe. Third, unfortunately, there is no H2 timeframe in MT4, so you must use one of the standard timeframes…

    Reply

    Carl Reply:

    Yes, I would like to thank for posting this tutorial, its very detailed, informative and reliable

    Reply

  3. xma

    Thanks for your answer.
    I interesing the visual mode in strategy tester ,while i see what happening on every each tick .When i runing expert advisor on 1H timeframe i dont see what happening in my custom timeframe.Have you any idea what can i do ,to fix this problem?

    Thanks

    Reply

  4. enivid

    Sorry, I don’t use the visualization in strategy tester. Maybe there are no orders to draw?

    Reply

  5. xma

    When i using the strategy tester i must select a timeframe(I can not select my custom timeframe)
    I think so ,the only way that i see redrawing the chartis the visual mode.

    Reply

  6. xma

    I have a new problem:) I try to open the 1M history date but in chart windows write me with big font WAIT,and not happening anything .I make all as your manual .
    What i do wrong?

    Reply

  7. enivid

    Did you rename it as mentioned in the tutorial? Did you copy it to the proper history folder?

    Reply

  8. kingsley

    how can i put take profit in my software. pls

    Reply

  9. Andrei

    kingsley, What software are you using?

    Reply

  10. William

    databank.alpari.org is down at the present

    Reply

  11. Andrei

    William, I hope it will get back up soon.

    Reply

  12. bouarf

    thanks a lot for this tutorial :o)
    last version of metatrader propose wti chart! also brent chart. unfortunatly, the fistory for these new charts (and other new charts) is very poor. i’m looking on the web where i could find a web site, as Alpari History Center who provide these datas. if i find one out i will post it here ;)
    thanks again

    Reply

  13. Tolex

    has some one been able to find another history center? alpari databank is still down, pls HELP !

    Reply

  14. Jerry

    Yo! I tried Alpari 1-Min data, it’s real bad, too much missing 1-min bars!!!
    jb

    Reply

  15. Kevin Tan

    Great! These info are what I need! Thanks. However, I believe alpari databank is still down.

    Reply

    babnz48 Reply:

    http://www.forextester.com/data/datasources.html

    Reply

  16. Skywalker

    Alpari databank is up now…enjoy!!

    Reply

  17. Martin Eshleman

    Thanks for the great and detailed info. However, I am unable to download the history zip file from Alpari download center. I can\’ download any of them. Does anybody know an alternative download site? Also, does anybody notice that when testing with Meta quotes history that the longer back you go to test an EA the more losing trades the tester says are made? When testing for only a month back you get more accurate results. Two months back it gives you less accurate results, 3 months back even less accurate,etc….. And the farther back you do the testing the bigger the time gaps are that the EA doesn’t trade! Any help will be appreciated. Thanks!

    Reply

  18. G4nX

    This info is very useful, but I can’t download history data from alpari data center, it’s looks like they are down or there is a reason that the data is only for members ?
    I get the word “Forbidden”, any other history data center ?
    Thanks…

    Reply

  19. LWMcQ

    How long should backtesting take? I’m running my first try at it now. Trying to run on data from 1/1/2008 thru 12/31/2006 on M30. It’s been running for 14 hours and appears to be only about 3/4 done. Running on Windows XP, Pentium 4, 2.20 GHz, 1 GB of RAM. If it runs this slowly, on 1 test, can’t imagine how long an optimisation would take.

    Reply

    Andrei Reply:

    That depends on the EA you are testing and the amount of output it produces to the Experts log. Usually, it takes so long only if there are many error messages are generated.

    Reply

  20. Lukasz

    Thanks for a great tutorial. I’ve been spending so much time recently to setup MT4 with good testing data and your guide helped me to understand this better. However, after following all steps I’m getting 82.79% modelling quality, and there are numerous “unmatched data eror” messages when starting the test. Why so? I downloaded M1 data from Alpari and converted all timeframes. Is this because Alpari data is not of high qualifty? My EA works on a daily timeframe. It is really flustrating to setup all of this properly. I have an impression that MetaQuotes is not interested in improving this aspect of their software. Thanks.

    Reply

  21. Andrei

    Lukasz,
    “Unmatched data” errors happen because of the errors in the initial M1 data. Try using some other period or just don’t mind those errors if there are not many of them they won’t influence the results much.

    Reply

  22. Lukasz

    Andrei, but I’m getting the same error even if the M1 data is correct. I explained this in more detail on MQL4 Forum:
    http://forum.mql4.com/20934#154236

    Reply

    Andrei Reply:

    Lukasz,

    On what timeframe do you receive these “mismatched” errors? If it’s not M1, where did you get your data for the higher timeframes? Also, which Model for testing do you use?

    Reply

  23. Lukasz

    Please see this also:
    http://forum.mql4.com/20973#154246

    Reply

  24. Lukasz

    Andrei,
    I’m testing my EA on a D1 time frame (every tick model). I found out that there is a bigger issue (checked build 222 and most recent 223) – the modeling quality is not constant for the same test. It is not repeatable. Please see my recent post:

    http://forum.mql4.com/20973

    Reply

  25. Andrei

    Lukasz,

    Actually, when you run the tester, it tries to download some data. I am not sure when it does and when it doesn’t but in my experience if I have all M1 data for the period and the higher timeframes are converted from this M1 data there is no difference in the subsequent runs if I explicitly set a period.

    Reply

  26. Lukasz

    Andrei,
    I’n my subsequent tests I verified that even though the data is complete for the tested period, I’m still getting “n/a” for the modeling quality. Can you tell me which build of MT4 are you using and where you obtained the data? If you’re using Alpari, can you please try running a test from 2001.01.01 till 2009.01.01 on EUR/USD (very tick, D1 time frame)? I’m thinking about getting data from MetaStock. Thanks.

    Reply

  27. Lukasz

    Andrei,
    I found out that tester downloads EURUSD1.hst file again from the broker (this is one of the two files that got updated under the MT4_HOME/history/.) EURUSD1440.hst got also updated but the file size is the same. I even narrowed the testing period to 2003.01.01 – 2008.01.01. This is the problem. I guess this happens when testing period is D1.

    Reply

  28. Lukasz

    I explained here how to reproduce:

    http://forum.mql4.com/21059

    Reply

  29. Lukasz

    Andrei,
    I finally solved this mistery. Please see my followup to the above initial post. Basically, every icon in the history center must be double clicked on to get these higher timeframes recalculated properly. What a relief.

    Reply

  30. Lukasz

    Actually, I take this back. The tester still downloads data from the broker which causes mismatched data errors. I will try to download, then delete broker’s account to see if this prevents downloading any data.

    Reply

  31. Arjun

    How do I convert Daily data to get Monthly data?

    Reply

    Andrei Reply:

    You should convert Minute data to get Monthly. But I think using 30 as multiplier for the script will convert daily to monthly.

    Reply

  32. NicSD

    Has anyone found a site for EURUSD data as Alapri seems to be down?

    Reply

  33. Hernando Quevedo

    Hello,

    Alpari datacenter doen not work for me.

    I´ve found other sites to download historyc data, but I don´t know how to setup the download settings.

    Also I don´t know how to transform .csv or .txt files into .hst files.

    I tried to put the link to the 2 sites but the blog system does not allw me to put their urls.

    Best Regards

    Reply

    jc Reply:

    please send me the link to the historical data provider!?

    Reply

    admin Reply:

    MetaTrader 5 now has built-in quality historical data.

    Reply

  34. Hernando Quevedo

    www fin-rus com / analysis / export / default.asp

    www dukascopy net / english / ddf_main / rdata / ExportCSV /

    These are the urls of my previous post.

    Can anyone help me with this?.

    how to configure to correctly download the historic data in order to use it with mt4?

    also, how to transform csv or txt files into .hst files?

    Thanks in advance.

    Reply

  35. Andrei

    Here is another source for MT4 historical data:
    http://www.onecorpfx.com/historical_data.php

    Reply

    Charles J Reply:

    This link does not work – Do you know of any other sites that I can download historical data for EURUSD and it will work with METATRADER 4?

    Reply

    Andrei Reply:

    Try getting the data via the MT4 History Center (Tools→History Center)

    Reply

  36. Daniel Shilina

    Awesome! I am going to give this a try. I’ve been looking for a way to get historical data imported. I’m sure it will work. Thanks.

    Reply

  37. Dju

    Hi!
    Does anybody knows about other websites with history for CFDs?
    I’ve tried dukascopy and fin-rus but many bars are missing on different periods, it depends on the instrument.

    Thanks!

    Reply

  38. Soquell

    I have been using MT4 from Alpari UK Demo forover six months, would you recommend I do a clean install?

    Thanks for the excllent tutorial!

    Reply

    Andrei Reply:

    What for?

    Reply

  39. john

    Great Tutorial. This seems the best way to backtest a system.

    Reply

  40. obpolat

    hi. thanks for everything. i have a question. i made all from alpari. but june datas missing for gbpusd. please help. thx.

    Reply

    Andrei Reply:

    Try contacting Alpari. Or try redownloading and recompiling the data once again.

    Reply

  41. jc

    hi,
    where do i get the best historical data? Or where can i buy it for a low price?

    Reply

  42. MxMax

    you can get free data from here, hourly and daily… http://www.fxhistoricaldata.com

    Reply

  43. gökmen

    is it possible to import h1 datas only.i want to import from excel to meta.after preparing manually h1 datas in excel

    Reply

    admin Reply:

    Sorry but I don’t think so.

    Reply

  44. univetsity

    TKS your tutorial.I met a problem when practise this download process.I did the very well till step 8,I rename the datafile as EURUSD1.hst,but when I have tried to open offline chart,it didn’t run correctly.The “Open Offline Chart” shows the eurusd’s data with a strange name like”SD,20010102,M825242418″ and the offline chart will always show “UPdate Waiting”.Appreciating for you help!

    Reply

    admin Reply:

    Try downloading the data using Tools->History Center.

    Reply

  45. Edgar

    Seems that Alpari don’t offer anymore the download link for historical data.

    And from my MT4 i cannot download history from several years ago… any website where i can download historical data??? thank you

    Reply

    admin Reply:

    Try installing MT4 from some other provider and downloading history from there.

    Reply

  46. Joe

    FYI- I downloaded the MT4 client from MB Trading. It appears to have the historical information already in the client.

    Reply

  47. Jack

    Thanks for the incredibly helpful tutorial!! Question; I can’t get good historical data from the link above, any other good sites for this? Thanks!

    Reply

    admin Reply:

    It’s no longer required to download the history data manually. You can download it within the history center of your MetaTrader 4 platform.

    Reply

  48. Serg

    To get already dowload tick data from DucasCopy read this http://translate.google.ru/translate?hl=ru&sl=ru&tl=en&u=http%3A%2F%2Fforum.tradelikeapro.ru%2Findex.php%3Ftopic%3D843.0

    Glad to help you.

    Reply

  49. any active forex traders here??? - Page 19

    [...] – YouTube MT4 Backtesting Threads @ Forex Factory MT4 Backtesting | Alan's Forex Blog MetaTrader History Data Importing and Converting Tutorial for Quality Backtesting Personally I have moved to Forex Tester (Forex Tester – professional forex training software, [...]

  50. Using the Period Converter Script - Page 2

    [...] for M30, H1 … up tp D1 That's it GIVE UP export is easy import or make HST data is hard MetaTrader History Data Importing and Converting Tutorial for Quality Backtesting got the reason why strategy tester for EA that does not work too I only do manual entry I wanna [...]

  51. EXNESS brokerage - Page 19

    [...] yet to find. Please address me this source, thank you Hello jamsky! This link might help you MetaTrader History Data Importing and Converting Tutorial for Quality Backtesting If it doesn't please PM me and I will explain you everything in details. Best regards, [...]

  52. rajiv

    hi
    i saved “Dukascopy 99% correct” Eur/Usd tick data in CVS file after highly compressed 637-MB ,now upload it on a FileFactory!,,,,so if further any one need data from “Dukascopy” no need again &

    again download it from dukascopy and then convert in to CVS file . get it from those links

    1) Download all 4 files ,it makes 637 MB ,one file does not work need all 4 zip files.

    2) At extraction time It creates 5.5 GB of all 4-5 years at extraction time

    else u can download directly 5.6 GB data from ‘Dukascopy’ but its takes too much time.

    main link for 4 links.
    http://www.filefactory.com/f/489c514649b30933/

    Reply

    admin Reply:

    Thank you!

    Reply

    Rajandran Reply:

    Thanks Rajiv that could be more helpful. But the problem is because of huge data size.

    Reply

    rajiv Reply:

    637MB is not big its compressed form of 5.5 gb
    i create a post for that data here

    Reply

    rajiv Reply:

    http://oyeforex.wordpress.com/2012/01/08/dukascopy-tick-data/

    Reply

    Rajandran R Reply:

    Thanks rajiv. It is so helpful to do accurate backtesting

    Reply

  53. Devizovy Trh

    Thanks for great article and for comments too, especially Ducascopy tutorials. By the way I was wondering what do you think about Metatrader 5?

    Reply

  54. Junip

    Hi,
    Check here for historical data:
    http://www.histdata.com

    See ya!!

    Reply

  55. het

    It is described on Alpari site.
    But this procedure killed my MT. After downloading of historical data MT did not start more. A lot of time MT tried to do something “inside’, no any messages or warnings.. Looking like, softwatre tries to unpack or process data, but so long..Very bad/

    Reply

  56. Julian Wong, a.k.a. ForexPipMaker

    Obviously times have changed since this original post. Alpari doesn’t share their databank anymore except through the MT4 platform. Currently, I download via Dukascopy’s JForex terminal and convert the data – that gets 99% quality, but MT4 history centre download would be more convenient, even if worth 9% less. Via the history centre, is it only 1min and not tick data?

    Reply

  57. Thomas

    Hello, how I can convert bar OHLC 1min data ho higher time frame ?

    Thankx

    Reply

    admin Reply:

    You can use period_converter script for that. It is standard in MetaTrader 4. See step 9 in the tutorial above.

    Reply

  58. Summer

    Thanks for the article. Was searching online for why period converter seems to convert M1 to MN wrongly. I thought using 43200 will work, obviously I’m wrong. Do u have any idea where to get MN data?

    Reply

    admin Reply:

    As far as I know, it is not possible to produce MN data from M1 timeframe using that period converter script.

    Reply

  59. Espejito777

    Very good…

    Reply

Leave a Reply

required
required (will not be published)
optional

Subscribe to Monthly Forex Newsletter