Download MetaTrader 5

Examples: Interaction between MetaTrader 4 and Matlab via DDE

To add comments, please log in or register
MetaQuotes Software Corp.
MetaQuotes Software Corp.  

New article Interaction between MetaTrader 4 and Matlab via DDE has been published:

Step-by-step instructions of how to organize data transfer from Matlab to MetaTrader 4 using DDE.

The mechanism of DDE (Dynamic data exchange) supported in MT 4 allows us to transfer data from one application into another directly through the computer's RAM. Matlab has the complete functionality to realize both the front end and the back end of DDE, so we would like to make the best of this opportunity.

MetaTrader 4 DDE server provides only the latest tick data. However, even considering such limitations, DDE is more preferable when, for example, working with quotes inside bars.

Like in the article of "MT 4 <-CSV->Matlab", I will describe the sequence of creating an exchange-organizing tool.

Don't forget to enable DDE server in the Tools -> Options -> Server tab in your MetaTrader 4 Client Terminal, and we can start.

Author: Dmitriy


Hello Dmitry,

Congratulations and very thanks for your articles and for sharing with us.

I recentely buy a program named ForexKiller. An exe file that loads from a file (saved from MT4) the last 10 prices and predict the signal to Buy or Sell.

Well, my question is, how may i write an EA to send to ForexKiller las 10 prices every time one bar starts (in one hour chart on MT4)???

And then, how may i access to the signal back to the EA???

Note: I talk in EA but it may be an indicator.

Once agains, thanks for you sharing information we learn a lot from your articles and examples.


Jose Costa

MQL4 Comments
MQL4 Comments  

>> DDEs
??? Attempt to reference field of non-structure array.

Error in ==> DDEs>pushSave_Callback at 167
timesStr = datestr(ticks.array(:,1)); % ñôîðìèðîâàòü string-ìàññèâ

Error in ==> gui_mainfcn at 96

Error in ==> DDEs at 42
gui_mainfcn(gui_State, varargin{:});

??? Error while evaluating uicontrol Callback



channel = ddeinit('MT4','QUOTE'); % initialization
pair = get(handles.editPair,'UserData'); % read the symbol name
rc = ddeadv(channel, pair,'newTick(x)','x',[1 1]); % establish connection
if (rc==1) % if the connection has been established,
disp('Connected'); % inform the console
handles.chann = channel; % save the channel ID in handles

Hi, thank you for your guide, I can get the Bid and Ask data through DDE. But how I can get other data? such as close, open, high,...

MQL4 Comments
MQL4 Comments  

Dear Dmitry,

Thank you for the great article. But since it is quite old probably something changed. I'm using the following script on matlab:

channel = ddeinit('MT4','BID'); % initialization
rc = ddeadv(channel, pair,'disp(x)','x',[1 1]);
if (rc==1)

After using this script i only receive Connected and then nothing. I came to believe that this is some compatibility issue. Might you know anything about it? Currently I'm running Windows 7 with Matlab 7.11.0 and MT4. Sadly, no data is coming :| Any ideas?


To add comments, please log in or register