Skip to content

MetaTrader 4 version

MetaPortAPI for MT4 (MetaPortAPI.ex4) speaks the same protocol as the MT5 version: the same REST paths, websocket streams, legacy TCP commands, request parameters and reply tags. Code written for one works with the other, except for the few differences below, which come from what MetaTrader 4 itself offers.

  1. In MetaTrader 4 open File → Open Data Folder.
  2. Copy MetaPortAPI.ex4 into MQL4\Experts and restart MetaTrader 4 (or right-click Expert Advisors → Refresh in the Navigator).
  3. Drag MetaPortAPI onto a chart. On the Common tab tick Allow live trading and Allow DLL imports.
  4. The Experts tab shows listening on TCP 81. Try http://127.0.0.1:81/v1/quote?symbol=EURUSD.

For live accounts put your license file in MQL4\Files\MetaPortAPI.lic.

Area MetaTrader 4
TICK_HISTORY, CALENDAR_LIST, TRACK_MBOOK Not available — MT4 has no tick history, economic calendar or market depth. They return ERROR_ID 4014.
QUOTE MT4 ticks have no milliseconds: TIME ends in .0. FLAGS is always 6.
Timeframes The nine MT4 timeframes: PERIOD_M1, M5, M15, M30, H1, H4, D1, W1, MN1.
ORDER_SEND DEAL and ORDER both hold the new order ticket. TYPE_FILLING and ASYNC are ignored. On brokers that refuse SL/TP on market orders, the order is opened first and SL/TP are set straight after.
ORDER_CLOSE (partial) MT4 moves the remaining volume to a new ticket. The reply’s ORDER holds that new ticket — use it for further changes.
TRADE_HISTORY Built from the terminal’s Account History tab: right-click it and choose All History to see older trades. A closed order gives an IN and an OUT deal, both numbered with the order ticket.
TRACK_TRADE_EVENTS Events are sent as {"MSG":"TRACK_TRADE_EVENTS","EVENT":"ORDER_OPENED","TICKET":123,"ORDER":{...}}.
CUSTOM_INDICATOR PARAM1–PARAM4 are passed as numbers, or as text when they are not numeric. The indicator must be in MQL4\Indicators.
EVENT When
ORDER_OPENED A market order was opened.
PENDING_PLACED A pending order was placed.
PENDING_FILLED A pending order was triggered and is now open.
ORDER_MODIFIED SL, TP, price or expiration changed.
ORDER_PARTIALLY_CLOSED Part of an order was closed (old ticket).
ORDER_REMAINDER_OPENED The remaining volume after a partial close (new ticket).
ORDER_CLOSED An order was fully closed.
PENDING_DELETED A pending order was deleted or expired.

ORDER holds the order in the same format as ORDER_LIST (open and pending orders) or TRADE_HISTORY (closed orders).