Exporting MQL5 Indicator Buffers for Python Backtesting
Summary
The article presents a workflow for using an MQL5 custom indicator in Python backtests without reimplementing its calculations. An MQL5 script creates an indicator handle with iCustom(), waits for history processing with BarsCalculated(), copies selected indicator buffers and matching price bars, and writes the aligned data to a CSV file. A Python pandas script then loads the export into a time-indexed dataset.
It explains several implementation details: iCustom() calls need fixed argument counts, so a dispatch block handles different parameter counts; asynchronous calculation requires polling, including retrying transient negative bar counts; and explicit string formatting avoids locale-dependent decimal separators. Warm-up values marked by the indicator as EMPTY_VALUE are exported as blank fields for pandas to read as missing data. The article includes a demo indicator and an end-to-end verification script, but its stated constraints include limits on parameter and buffer counts, reliance on cached history, a fixed wait timeout, and omission of some price fields. This is a data pipeline, not evidence of strategy profitability.
Key ideas
- Exporting buffers from the terminal keeps Python backtests aligned with the actual MQL5 indicator implementation.
- iCustom() and CopyBuffer() provide indicator access, while CopyRates() supplies matching price bars.
- The exporter waits for asynchronous calculation and handles transient negative BarsCalculated() readings.
- Explicit CSV formatting avoids locale issues, and warm-up sentinels become blank fields that pandas can parse as missing values.
- The implementation has fixed parameter and buffer limits and depends on cached terminal history.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.