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

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


You can try MetaApi https://metaapi.cloud cloud service which provides REST API and WebSocket API access to both MetaTrader 4 and MetaTrader 5 accounts.

Official REST API documentation: https://metaapi.cloud/docs/client

SDKs: https://metaapi.cloud/sdks (javascript, python and Java SDKs are provided as per April 2021)

It supports reading account information, positions, orders, trade history, receiving quotes, and accessing market data.

The service also provides copy trading API https://metaapi.cloud/docs/copyfactory and API to calculate forex trading metrics on a MetaTrader account https://metaapi.cloud/docs/metastats.