Discussing the article: "Building a JSON Trade Report Exporter in Pure MQL5"

 

Check out the new article: Building a JSON Trade Report Exporter in Pure MQL5.

A refined MQL5 script exports trade history to a well‑formed JSON file in MQL5/Files/, reconstructing trades from deals by position ID and recovering stop loss and take profit via a two‑pass lookup that falls back closed to the originating order. It includes a dedicated JSON serializer and computes R‑multiple, pip profit, and duration. The result loads cleanly in Python, R, or Excel without custom parsing.

After a backtest or a trading day the terminal already contains everything needed for analysis - entries, exits, P&L, commissions, swaps, comments and magic numbers - but that history is trapped inside the History tab. Manual copying breaks structure and does not scale; the terminal's HTML is for reading and its XML is verbose and awkward to consume programmatically. The concrete task this article solves is: produce a programmatically readable report of closed trades (not raw deals) for a user-specified date range, with optional symbol and magic filters, written as a single JSON document that loads directly into Python, R or Excel without intermediate parsing. A practical requirement is to recover stop-loss/take-profit values when DEAL SL or DEAL TP are missing from the deal record by falling back to the originating order. The remainder of the article describes an MQL5 implementation that meets these requirements and writes the file into MQL5/Files/.

JSON trade exporter structural flow diagram

The exporter pipeline: closed trade history is read from the terminal, mapped to the JSON contract, reconstructed from deals with an SL/TP fallback check against the originating order, then serialized and written to a JSON file.

Author: Ushana Kevin Iorkumbul