Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Data Exchange Between Matlab and Third Party Software like Metatrader 4

121 views
Skip to first unread message

Franco

unread,
Jun 22, 2010, 6:02:04 AM6/22/10
to
Hey there,

I have used simulink for control system simulation before in my engineering studies a while ago, so my knowledge about matlab is limited.

The past four months I have been busy with forex trading as a hobby of mine, and I started out with metatrader 4 and the metaquotes language to write trading software.

The problem with metaquotes language is it is very basic. You cannot do complicated calculations with it without writing hundreds of lines of code. That is where I decided to start learn Matlab from scratch.

Now my question is this: I want to write the shell of the trading software in metaquotes language. The metaquotes code will call functions from matlab to do the calculations. So matlab will only be used to do the calculations.

What is the easiest way to make this happen? How can I send information to matlab, do the calculations, and send it back to metatrader 4 ?

I know I need to compile the matlab code into a .dll file and import it into the metaquotes language file, but I don't understand this concept and how it is supposed to work.

I have read an article about doing it with csv files, but I don't think that will be good enough for me. It needs to be dynamic. Metatrader will send the latest price data to matlab, matlab will do the calculations and send the answers back to metatrader. That is what I need, and it needs to be instant.

Also, can simulink be used for such an application or does it need to be matlab and a .m file ?

I know this question is a bit broad so if you need any more info to help please ask.

Thanks for your time and help

Regards
Franco

Ashish Uthama

unread,
Jun 22, 2010, 8:11:11 AM6/22/10
to
Integration needs to go both ways.
What kind of interaction does Metatrader allow with other softwares? Does
it let you call a C/C++ DLL functions? Or perhaps it provides a COM
interface which can be called by MATLAB?

If you want Metatrader to be the 'main' software, calling into MATLAB. You
can look at these options:

#1. Compile MATLAB logic into a DLL using the MATLAB compiler. Program
Metatrader to invoke the functions in this DLL.
This also has the added advantage that you depoly the solution on machines
which dont have MATLAB.

#2. Use the MATLAB engine.
http://www.mathworks.com/access//helpdesk/help/techdoc/matlab_external/f29148.html
(again assume a C/C++/Fortran calling environment). If Metatrader lets you
write plugins in C/C++/Fortran(!), then this might be an option.

#3. If Metatrader allows for a COM plugin, use MATLAB's com interface.

On the other hand, you could think of MATLAB being the 'main' program.
You'll have to write logic in MATLAB to call into Metatrader for its part
in the solution. This might work if Metatrader has say a COM api for
MATLAB to use.

You should be able to find most of the info for the above here:
http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/bp_kqh7.html

You mentioned CSV files. I am guessing that this means you can do have
Metatrader read/write data into CSV files. You could leverage this for a
producer-consumer relation with MATLAB. Have both of them poll a directory
for input/output files. Say Metatrader will always put files to be
processed into this directory as in.csv and wait till a out.csv is created
in it. MATLAB could poll for in.csv, read it in, process the data, delete
in.csv and create out.csv.

Franco

unread,
Jun 22, 2010, 4:07:22 PM6/22/10
to
"Ashish Uthama" <first...@mathworks.com> wrote in message <op.vepas...@uthamaa.dhcp.mathworks.com>...


Hey there, thanks for the reply!

As far as I know Metatrader allows function calls from dll files by importing dll files. I am not sure which dll files metatrader can call, but I have read that it works with C++ compiled files.

Here is an article that explains how interaction between matlab and metatrade can be achieved using the Virtual Matlab Machine:

http://articles.mql4.com/833

To be honest, I don't have a clue what is going on in that article, and how to practically use it. They do talk about "wrapping" DLL files but don't really understand what that means. I have never worked with DLL files before so I am a bit ill informed when it comes to this topic.

Basically what I want to do is send a bunch of data to Matlab from metatrader (like in an array), let Matlab do the calculations, and send the results back to metatrader.

A sort of function call will do the trick, for instance if I call the function FindHighValue(array), matlab will find the highest value, and return it to metatrader.

I will read through the articles you gave me.

Thanks for your help!

Ashish Uthama

unread,
Jun 22, 2010, 4:54:16 PM6/22/10
to
I had a quick look, they are using the MATLAB engine interface
(http://www.mathworks.com/access//helpdesk/help/techdoc/matlab_external/f29148.html)

The engine interface can be used by C/C++ code, so they compile the C/C++
code into a DLL (Dynamic linked library) which is what the metatrader
platform then calls. Think of the DLL as the C/C++ glue between MATLAB and
Metatrader.

It looks like the article has some examples and steps. You might want to
give that a spin while using the above link as a reference. If you run
into issues, post in this group (mention 'MATLAB engine', I dont think
'Virtual MATLAB' is commonly used here to identify this interface).

Camilo

unread,
Sep 22, 2014, 9:06:17 PM9/22/14
to
Hey Franco .. Finally Did you achieve that you want? because I've finding the same thing .. Can you give a hand?
0 new messages