Libraries: Working with sockets in MQL5

 

Working with sockets in MQL5:

This library will allow you to tranfser realtime quotes from MetaTrader 5 to external server application.

The TCP protocol is used, it allows to transfer the data not only locally, but globally all over the Internet. The Winsock2 library (ws2_32.dll) is used for working with sockets. The direct calls of the library functions is impossible, because MQL5 doesnt allow to work with pointers and pass complex data structures as parameters of DLL functions. The library socket_mql5.dll, written in C++, is an intermediate wrapper, connecting the Expert Advisor and sockets library.

The interaction of MetaTrader 5 with external server application is presented at Fig:

Scheme of the interaction with MetaTrader 5 client terminal

The minimal set of the functions for one-way transfer (SocketOpen, SocketWrite, SocketClose) is implemented in socket_mql5.dll library.

An example of an Expert Advisor, connected to server and used to transfer the realtime tick data to external server application is included.

The archive contains:

  • An Expert Advisor
  • The socket_mql5.dll library (C++ source code is written in Visual Studio 2008)
  • The TCP server and TCP client (Delphi7 sources)

Author: Andrey Voytenko

Data transfer from MetaTrader 5 to server application

 

Thank you so much!


 

There are some changes and additions to the project. I ask all those who have already downloaded the project file to update it.

 
This is only for one currency pair, but how to implement it for multiple currency pairs ?
 
gisip:
... how to realise it for several currency pairs ?

To do this, the socket advisor must be placed on the charts of those currency pairs for which you want to collect tick information.

Not the most elegant solution. But I am ready to listen to suggestions for improving the project.

 
avoitenko:

To do this, the socket Expert Advisor should be placed on the charts of those currency pairs for which you want to collect tick information.

Not the most elegant solution. But I am ready to listen to suggestions on how to improve the project.

For MT4 it seems clear how - through DDE server, but how on MT5 I ask everyone.

Maybe someone has some ideas ?

[Deleted]  
gisip:

For MT4 it seems clear how - through DDE server, but how on MT5 I ask everyone.

Can anyone have any ideas ?

It all depends on the advancedness of the server, the complexity of the network protocol and the task to be performed....

First you need to define the task, then develop a network protocol (it may be necessary to work out the structure of the server database).

 
Interesting:

It all depends on the advancedness of the server, complexity of the network protocol and the task to be performed....

First you need to define the task, then develop a network protocol (you may need to work out the structure of the server database).

Without any tricks, just a stream of quotes, as primitive as in MT4 through DDE server.
 

If you have patience, I will finish the File Mapping data exchange project. It will be just what you need.

 
avoitenko:

If you have the patience, I will finish the File Mapping data exchange project. It will be just what you need.

Will I have to put an advisor on each pair I want to receive data on?
 
gisip:
Will I have to set up an Expert Advisor for each pair I want to receive data on?

I have not yet done the transfer of quotes the way MT4 does via DDE, because MT4 is an automation server. I do it this way: MT5 is a client, and if you want to know the current_prices, you send a request and get the result. This works for all currency pairs active in the market view window.

You can also in this project send all quotes in one package. For example, in an Expert Advisor, on a timer every second, receive data and check before sending that the new data is not similar to the already sent data, for each currency pair, i.e. a change in the data for Ask or Bid will be considered a new tick.

This website uses cookies. Learn more about our Cookies Policy.