Discussing the article: "Streaming MetaTrader 5 Trade Events to a Local HTTP Server Using WinINet in MQL5"

 

Check out the new article: Streaming MetaTrader 5 Trade Events to a Local HTTP Server Using WinINet in MQL5.

An MQL5 implementation sends trade lifecycle events to a local HTTP service through WinINet with a reusable session and per-request handles. The trade callback only enqueues JSON and returns, while a 500 ms timer drains the queue and retries failed posts, preserving order. A three-stage log policy keeps the Experts tab clear during downtime and summarizes recovery.

A trading system rarely operates in isolation. Risk dashboards, analytics pipelines, algorithmic bridges, and trade journals all need to know the moment a position opens or closes — without polling the terminal's History tab or scraping a log file after the fact. What they need is a push notification: the terminal itself announces each trade event to a waiting consumer the instant it occurs.

MQL5 provides OnTradeTransaction() for exactly this purpose — a callback that fires the moment a deal is confirmed on the account. The challenge is getting that notification out of the terminal and into another process in real time. MQL5's built-in WebRequest() function can send HTTP requests, but it blocks the thread until the request completes, which means a slow or temporarily unreachable server stalls the EA's entire event loop. It also requires the target URL to be whitelisted in the terminal's settings dialog, which is inconvenient for any deployment that needs to change endpoints.

This article takes a different approach: it calls Windows Internet (wininet.dll) directly from MQL5 using #import. This DLL ships with every version of Windows, requires no installation, and gives complete control over the HTTP pipeline. A persistent session handle is opened once and reused for the lifetime of the EA. A small in-memory queue decouples the trade callback from the delivery attempt, so OnTradeTransaction() always returns immediately regardless of what the server is doing. The result is an EA that serializes every position open and close as JSON and delivers it to a local HTTP server with retry on failure. It logs one clear message when the server goes down and another when it recovers. During an outage, it keeps the Experts tab readable by logging each newly queued trade instead of repeating the same error lines.

Architecture diagram

Author: Ushana Kevin Iorkumbul