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

 

hi, very good job!

The mql5.dll  work with EA  mq4?

 Have you example?

 

 
Look this example for MLQ4 - working with sockets without using DLL.
 

Thanks for this!

but for x64 version u must change my_rand() rutins

//--------------------------------------------------------------------------//
unsigned long long rand64()
//--------------------------------------------------------------------------//
{
        return ( static_cast<unsigned long long>( rand() ) << 32 ) | rand();
}

something like this.




 

very nice work !

i will writing tool with now for testing this! 

 
Do you have also a dll with bidirectional socket conversation?!
 

The solution work very fine on MT5 32bit.

I have tried to compile the socket_mql5.dll for 64 bit but it do not work. Can someone give me a socket_mql5.dll 64 bit which is OK.

 

Thank you

Jürgen Berger 

 
JuergenBerger:

I have tried to compile the socket_mql5.dll for 64 bit but it do not work. Can someone give me a socket_mql5.dll 64 bit which is OK.

Now the project has been updated and is available for 64-bit version. Please test.
 

how can i implement a "recv" function on this project?

...and receive data inside of mql5 for execute others functions? 

 
Automated-Trading:

Working with sockets in MQL5:

Author: Andrey Voytenko

PERFECT !

 
This is still brilliant! But has anyone succeeded in backtesting an EA connected via sockets in this way using the strategy tester? If so, how?
Reason: