How to send/receive data to/from MetaTrader Ternminal 4 with JAVA (or anything!)

Jay Povey picture Jay Povey · Sep 20, 2016 · Viewed 21.7k times · Source

I have been working on an algorithm ( Not mine, I am just modifying it ) that predicts when to buy and sell on the FOREX market. I need to be able to open and close orders, dynamically update parameters of the orders ( such as stoploss, maximum stop etc. ) and receive real time tick data.

I have been researching for well over a week, and have no success.

The closest I have gotten is using JavoNet and Mt4 Api

I managed to import the DLL into java and use a MQL4 function, which was AccountBalance(), however this has returned 0.0, which was not the account balance, I messed around with the code and the settings on MT4 client but still no luck.

Q0: Can anyone please point me in the right direction?

I am new to automated FOREX trading but from what I understand there is a broker somewhere with a MT4 server and I connect to that server with my MT4 client on my windows machine.

Q1: If this is the case, do I need to make an API work with the server side instead of my client side?

All these DLL's I have tried so far have been used with the MT4 client software on my machine.

I have also been doing some reading on the FIX-Protocol and ZeroMQ.

Q2: Can these help me achieve my goal in any way (instead of creating some bridges between JAVA and MT4 DLL's)?

Answer

user3666197 picture user3666197 · Dec 1, 2016

A0: yes, forget straight about REST and synchronous, blocking chains in FX-trading domain

A1: well, not a typical way. MetaTrader Server is a proprietary suite of systems on the Broker-side and theirs API are not disclosed to allow some 3rd party integrations against.

enter image description here

A2: FIX-Protocol is the industry standard LP-interfacing lingua franca. In case you have contracted relations with your institutional trading provider, incl. the FIX-Protocol GWY-port, this may provide you an A-level access to the Market and to integrate your trading tools against. If this is the case, forget about MT4 instrumentation, as prime-time cadences are far beyond the MT4 Terminal localhost processing architecture ( multiple events with a sub-millisecond TimeDOMAIN resolution are common, whereas MQL4 does not provide any direct support for multithreaded-concurrent / better parallel programme scheduling designs ). FIX-Protocol events are simply off-the picture above, being far left, "before" the graph starts from 1st [ms] column.

ZeroMQ may help liberate your further designs from MQL4 limitations. May like to read my other posts on distributed systems, where MQL4 / ZeroMQ / ML-AI-predictors / GPU-processing infrastructures appear.

Anyway:

Enjoy the Wild Worlds of MQL4/MQL5


Interested? May also like reading other MQL4, ZeroMQ distributed processing and low-latency trading posts