Discussing the article: "Building a Trade Analytics System (Part 2): How to Capture Closed Trades and Send JSON in MQL5"

 

Check out the new article: Building a Trade Analytics System (Part 2): How to Capture Closed Trades and Send JSON in MQL5.

We build a lightweight bridge that captures closed trades in MetaTrader 5 and sends them to an external backend over HTTP as JSON. It uses OnTradeTransaction for event detection, reads details from deal history, assembles a JSON payload, and posts it via WebRequest. A local Flask API is used to test the flow, delivering a working path to move trade data outside the terminal.

After setting up an external backend, the next challenge becomes clear: MetaTrader 5 cannot automatically capture closed trades and send them to an external system. Trade data remains inside the terminal unless you export it manually or access it via scripts. This makes it difficult to build a consistent, event-driven data pipeline.

In Part 1, we established the backend foundation by defining the system architecture, creating the data model, and preparing a versioned API to receive trade data. However, that backend remains idle until a mechanism is introduced on the terminal side to supply it with structured trade information.
This article addresses that gap. We develop a lightweight Expert Advisor that listens for trade closures. It extracts relevant data from MetaTrader 5, formats it as JSON, and sends it to the backend via HTTP. The focus is strictly on capturing and transmitting closed trade data reliably and repeatably.

Author: Chacha Ian Maroa