How to control MT4 from python? [closed]
Asked Answered
M

3

5

I'm using a MetaTrader4 Terminal and I'm experienced python developer.

Does anyone know, how can I connect MT4 and Python?
I want to:
- connect to MT4
- read USD/EUR data
- make order (buy/sell)

Does anyone know some library, a page with instructions or a documentation or have at least idea how to do that?

I googled first 30 page but I didn't find anything useful.

Mythology answered 17/8, 2017 at 16:8 Comment(0)
L
4

There are several ways to do that but the best is to use WebSocket. as WebSocket provides two-way communication, it will be easy to fetch data using MT4 EA and send them to the WebSocket. You can record every Tick from EA and send it to WebSocket. The WebSocket should be opened by your Python script. You will be able to command the EA from python script as well. There will be a bi-directional data stream from EA to Python. There is a WebSocket library available for MQL you can read the MT4 WebSocket Library post and for python, you can just go through the Python WebSocket from RedHat.

Linton answered 22/8, 2019 at 4:56 Comment(1)
You have to change Python Websocket link with the correct one (websockets.readthedocs.io/en/stable), actually edit you response doesn't work for me. ThanksNehemiah
B
2

As of to-date, I recommend https://github.com/darwinex/dwxconnect, it enables anyone to write trading strategies in any programming language and trade them via MetaTrader 4 or 5 without having to code algorithms in MQL.

The only thing I found missing in the above recommendation was ability to get custom indicator data from MT4/5 to the preferred programming language. I did find https://github.com/khramkov/MQL5-JSON-API which allowed this. However MQL5-JSON-API was a bit complex for my taste or rather required a lot more effort to implement. How this helps

Barbie answered 6/8, 2021 at 12:23 Comment(0)
C
1

Several options:

  • exchange with files (write data from mt4 into a file for python, another folder in opposite direction with buy/sell instructions);
  • 0MQ (or something like that) as a better option.
Cavetto answered 18/8, 2017 at 7:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.