Discussing the article: "Exporting Custom Indicator Buffers to CSV for Python Backtesting Pipelines"
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Check out the new article: Exporting Custom Indicator Buffers to CSV for Python Backtesting Pipelines.
We build a CSV exporter for MQL5 custom indicators that preserves the exact values seen on the chart. The script creates the indicator handle with iCustom, waits for BarsCalculated, aligns buffers to CopyRates, and writes a locale-safe CSV that pandas loads with parsed dates and NaN for warm-up bars. It addresses compile-time argument limits, jagged-array workarounds, and EMPTY_VALUE handling, enabling reliable Python backtests without re-coding the indicator.
A trader who has built a custom indicator in MQL5 and wants to backtest a strategy around it in Python usually faces two awkward choices. The first option is to reimplement the indicator in Python. This risks drift from the MQL5 version: an off-by-one bar shift, different rounding, or different warm-up handling. Any of these can silently produce a backtest that does not match the chart. The second option is to trust that the reimplementation is exact and hope no discrepancy exists.
There is a third option, and it removes the risk entirely: let MQL5 compute the indicator, since that is the one place its logic is guaranteed correct, and export the resulting buffer values directly into a CSV file that Python can read. Whatever the indicator would have plotted on the chart is exactly what ends up in the file. No reimplementation, no drift, no guessing.
This article builds an MQL5 script that attaches to a custom indicator via iCustom(). It waits for calculation to complete (BarsCalculated()), copies selected buffers (CopyBuffer()), aligns them with price bars (CopyRates()), and writes a locale-safe CSV to MQL5/Files/. A Python script using pandas can load that file in a single call and merge it directly into a backtesting pipeline. The implementation separates row storage, the export pipeline, and the demo indicator used for testing into distinct modules with clearly bounded responsibilities.
Author: Ushana Kevin Iorkumbul