A mt4 and python bridge

 

The reason to create this tool

Metatrader is a trading platform mainly for Forex trading. This is a great tool running on client machines with the abilities to back-test their self-defined strategies. The performance is close to C++ since the client’s EA is kind of a VC++ application running on the windows machine. The language users are using to construct their EA is called MQL 4/5, it is powerful and extensible since user can plugin their favorite DLL modules as a library. Yet, the limitation is still obvious as you can imagine that there are not many DLL libraries for EA to get alone with.

Due to the libraries limitation, I created a bridge EA that can exchange data between MT and python. The communication channel is built on top of the raw windows socket.

Extra limitation and system overview

Here is the system overview. There are a couple of modules which you can divide them into public and private. Those private modules are in grey color. They hold all the socket programming implementation and handles the communication protocol.

The rest of the modules are public. They serve 2 purposes. The first reason is that I cannot include DLL in the private modules since they are supposed to upload to the MT market where it is not allowed to link to any DLL due to some security issues. The second reason is that user can modify the EA input parameters in the public modules so that they can enjoy the back-testing system provide by the MT.

How to use it

  • You will need to download the proxy EA from the MT market. link
  • You will also need to install the related python library: link

You will need to compile the proxy EA locally and run it with allowing the DLL usage. Once you have correctly create your python EA based on the example from the pysailfish library, the connection from MT is established, market data will be pushed from MT to python. Then, you can do what you want to do in the python EA.

Compare with the official python library

Official python library link.

  • The official support is only for MT5. My tool is targeted to MT4
  • My tool keeps the ability of MT back-testing system

This is how my tool provides a better solution.

Comments