Australian (ASX) Stock Market Forum

Converting Metastock EOD data to MT4 history files for MT4 charting

Joined
12 February 2014
Posts
138
Reactions
25
Thought I'd follow up on my last thread with a similar one, which involves charting Metastock EOD data in MT4. So basically what you do is say you subscribe to an EOD data provider such as dataHQ or Premium Data etc. Once your Metastock data is downloaded/updated, you run my perl script from Metatrader 4 history folder and it will convert all the Metastock Fn.xxx files to _Symbol.hst files so that you can chart them in MT4. Of course the catch is you have to install perl (not a big deal!).

I will explain the process in detail in following posts. For now I have attached the following files:

1) ms2mt4.pl - Executable script.
2) MS2MT4DLL.dll - DLL (brains).
3) MS2MT4Remove.bat - Tidy up script, removes all _Symbol.hst files.

Note: Please remove .txt extension as .pl and .bat extensions are not allowed.

Cheers,

Andrew.
 

Attachments

  • MS2MT4Remove.bat.txt
    31 bytes · Views: 351
  • ms2mt4.pl.txt
    486 bytes · Views: 319
  • MS2MT4DLL.dll
    509 KB · Views: 281
Okay, once you have downloaded your EOD Metastock data from a data provider, hopefully it should look similar to something like this:

MS2MT4_Step1.PNG

Take note of where your MS files are located as you will need to modify my ms2mt4.pl script and change the path of the variable "$metastockdbpath" to this location. As highlighted below:

MS2MT4_Step2.PNG

There is a need to use the backslash character "\" twice as it is a special character and the path must end with two backslashes.

Once you have done that, if you haven't already done so, move the files I attached in first post to the directory where your Metatrader 4 demo account history files are stored like so:

MS2MT4_Step3.PNG

After that, all you need to do is execute the perl script ms2mt4.pl either by double clicking on it, right clicking or using the command line. What you should see is the following:

MS2MT4_Step4.PNG

and finally, in your MT4 history folder, you should see something similar to the following:

MS2MT4_Step5.PNG

Now you should be able to open up each stock as an offline chart in Metatrader 4 (File/Open Offline).
 
Just wondering if anyone knows what database format DataHQ or Premium Data will be using in future (say 2-5 years). Anyone got any information on this?

They currently use the Metastock Database format which has been around since I believe 1985. But now that Metastock have dumped their own database after nearly 30 years, do these data providers have any future plans for an alternative?

It's an interesting topic because sooner or later 64 bit platforms will be the norm and these data providers will have to maintain the Metastock Database using 64 bit applications to keep up with the times. Do they have 64 bit applications for this?

A Metastock database contains a master, emaster and xmaster file, which all contain the names of the stocks and an index to corresponding .dat or .mwd files among other things. The .dat and .mwd files store all the quotes for a stock in microsoft binary floating point format. On top of this, I believe only 65535 quotes can be stored, which is still plently for EOD data. For EOD data, I believe a quote record currently contains DATE, OPEN, HIGH, LOW, CLOSE, VOLUME & OPEN INTEREST.

One minor problem with storing data in floating point format is there could be a slight loss of accuracy in some fields. For example the Volume of some highly traded US stocks could lose a precision if it is over I think 10 million or 100 million due to only being able to store 5 or 6 significant digits, but practically speaking, this is not a big issue.

Metatrader history files use double precision, but there is no master file so you have to iterate through each file to get a symbol list. What genius format will these companies use and how will they handle share splits and what not if and when they decide to change database formats?
 
Dear,

Thank you for this great work. I am facing a problem when I try to open ms2mt4.pl file. An error massage at line 18 as shown in this picture still appears.

Untitled.png

I have win7

Thank you
Mosh
 
Dear,

Thank you for this great work. I am facing a problem when I try to open ms2mt4.pl file. An error massage at line 18 as shown in this picture still appears.

I have win7

Thank you
Mosh

Hi Mosh,

I think this error is occuring because the perl script can't find the dll MS2MT4DLL.DLL, which must be put in the same directory as ms2mt4.pl. I reproduced the error message "Can't call method Call..." by renaming the dll and re-running the script.

If you have done that correctly then you might be using the 64 bit perl installation. I have heard from other people on the forum that you can't use 64 bit installations with 32 bit dlls, so 64 bit perl probably treats my 32bit dll MS2MT4DLL as a non existant dll. Hence the error message. To check your perl installation, open up command prompt and type "perl -v". I'm not quite sure if you can install both a 32 bit and 64 bit version of perl on the same operating system. I've only been using the 32 bit version.

Once you fix the above up, I see another error in the definition of variable $metastockdbpath, it is defined as

$metastockdbpath = "C:\\Users\\Administrator\\Desktop\mt4\\Daily\\Tadawul\\";

you are missing a second backslash just before mt4, so after you fix the first problem you will probably get another error complaining about the directory path.

This directory path you've specified seems interesting because it looks like you are storing your metastock files inside a metatrader directory which is fine. Are you sure these are Metastock files? Does this directory have an emaster file in it?

Cheers,

Andrew.
 
Thank you so much.

My MS files are in "mt4" folder. I have done all what you have said but the problem is still the same, see this pict.

View attachment 60487

You are right, I am using 64bit but the perl that I am using is working for 64 and 32 bit. I think the problem is the in the DLL file. I do not think it work in win7 64 bit.

I have tried to find a way to come over this but I could not.

any Ideas ??

Thank you
 
Mosh, from the image I see when you type "perl -v" you get

MSWin32-x64-multi-thread

Mine has -x86 instead. That's all I got. I don't know enough about calling 32bit dlls from what seems a 32/64 bit installation of perl. I'm using ActiveState Perl v5.16.3 (-x86).

Here are some suggestions :)

1. Install XP on an old crappy computer then install only 32 bit perl on this computer and see if you can get things to work. Then maybe install this version of perl aswell on your current computer and see if it still works.
2. Ask someone very knowledgable about calling 32 bit dlls functions from your currently installed version of perl.
3. Try another 32 bit scripting language to pass the dbpath into function "int MS2MT4_MAIN_DLL(char *dbpath)" and post into thread :).
4. Wait for somebody smarter than me (like Jabatus :D from Argentina) to post how they got it to work (if at all) on your version of perl :)

Do you have a 32 bit version of excel? Maybe I could write a vba macro to call the function.

That's all I got right now, I got nothing. What a pain in the ......

Cheers,

Andrew
 
Hi Mosh,

I have attached MetaTrader Script file MS2MT4.mq4. You need to put this in the ...\MQL4\Scripts directory and copy the file MS2MT4DLL.dll to the directory ...\MQL4\Libraries. Last time I checked, Metatrader4 was a 32 bit application so that means it can only use 32 bit dlls, so hopefully this should work, although you are not going to get any error messages if it doesn't (unless you put the dll in the wrong directory, which will generate an error message in the experts tab in the bottom terminal pane). When you run the script in Metatrader4, it should dump all the *_xxx.hst files in the root Metatrader directory where the file terminal.exe is located. Then you need to move these files to where your history files are currently stored and you should be able to open them up as an offline chart.

For more information on setting things up, see my Metatrader scan thread in:

https://www.aussiestockforums.com/forums/showthread.php?t=28721

Note: You have to edit the variable metastockdbpathStr in script MS2MT4.mq4 to where your metastock files are stored and don't forget to COMPILE :D.

Hopefully this works :)

Cheers,

Andrew.
 

Attachments

  • MS2MT4.mq4
    1.3 KB · Views: 144
Thought I'd add the equivalent python script "ms2mt4.py" (attached below) to perl script "ms2mt4.pl". This script runs with the 32 bit python installation and is to be placed in the same directory location as 32 bit dll "MS2MT4DLL.dll". As with the perl script, this python script equivalently uses the functionality of the 32 bit dll "MS2MT4DLL.dll" to create the MT4 history files. Hopefully this helps people that are having trouble with 32 bit perl, but it does mean you have to install 32 bit python, so you only need to try it if you are having problems with the perl script :eek:

Note: You will need to change variable metastockdbpath to where your metastock files are stored as explained in previous posts :)

Please remove .txt extension from attached file "ms2mt4.py.txt"

Cheers,

Andrew
 

Attachments

  • ms2mt4.py.txt
    778 bytes · Views: 100
(64bitDLL) Converting Metastock EOD data to MT4 history files for MT4 charting

I have been working on my first ever 64 bit dll for this thread. If you have 64 bit python/perl installed, try my 64 bit attachment MS2MT464_20150509.zip. When you extract it, you will find the 64 bit dll has the same name "MS2MT4DLL.dll" as the 32 bit dll. This makes life easy as you don't have to modify the python/perl scripts. Just copy over the 32 bit dll. Ofcourse you have to have 64 bit python/perl installed on your computer.

Let me know if this works as I'm new to 64 bit programming and it works on my 64 bit computer :iamwithst

Cheers,

Andrew.
 

Attachments

  • MS2MT464_20150509.zip
    226.7 KB · Views: 162
Guys if you are using OS like Win 8.1 , you need to run the terminal.exe on win7 or winxp sp-3 mode.
Had a tough time figuring it out. Good luck
 
i have error message
error accessing to master files in dbpath
can any one help please


!/usr/bin/perl
#
# mS2mt4.pl by Andrew Code
#
# This program calls main function in MS2MT4DLL.dll which converts
# EOD Metastock Fn.dat files to MT4 hst files
#

use Win32::API;

$metastockdbpath = "C:\\Users\\doctoresam85\\Desktop\\emarket last price\\";

################################################################################
# Main Code

$function = Win32::API->new('MS2MT4DLL', 'int MS2MT4_MAIN_DLL(char *dbpath)');

$return = $function->Call($metastockdbpath);
 
i have error message
error accessing to master files in dbpath
can any one help please
.
.
$metastockdbpath = "C:\\Users\\doctoresam85\\Desktop\\emarket last price\\";
.
.

Does Folder "emarket last price" contain the files "master" and "emaster"?

Cheers,

Andrew.
 
Yes but thank you i get data from other site it now work great thank you for replay and i am sorry for not editing the post thank you sir
 
Top