Skip to content
All library documents

Exchanging Data Between Python Models and the MetaTrader Strategy Tester

Article MQL5 articles

Summary

This article outlines a file-based messaging design for connecting Python machine learning models with MQL5 Expert Advisors during Strategy Tester runs. Because network requests are unavailable in the tester, the author proposes exchanging CSV files through a shared folder. Python acts as the server and MQL5 as the client; an initialization file communicates the host, port, and whether the terminal is testing or live, followed by a confirmation file before message exchange proceeds.

The design aims to support regression and classification models while retaining access to the tester for strategy logic, custom indicators, and trade management. The article describes helper methods for serializing headers and rows, and gives a small transfer-speed example using repeated files. Disk-based communication is acknowledged as a source of latency compared with sockets, though considered adequate for the proof of concept. The examples are static and require adapting data fields to each strategy; the author also cautions that the illustrated price regression is basic and unsuitable for live trading as presented. The article is an architectural overview, with implementation details deferred to later work.

Key ideas

  • The Strategy Tester’s network restrictions prevent direct WebRequest communication with Python models.
  • Shared CSV files can provide a simple interprocess messaging channel between MQL5 and Python.
  • An initialization handshake can tell the Python process the terminal environment and confirm readiness.
  • Data formats must match the strategy’s inputs, and format changes require compatible code on both sides.
  • Disk-based transfer may add processing delay, and the described architecture remains a proof of concept.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.