Export a supported Python strategy to MQL5
Which parts of a Python strategy survive translation into an MQL5 Expert Advisor?
Compare signal timing, supported order types and risk rules between Python and generated MQL5 source, then run the Expert Advisor in MetaTrader?s tester. A source check cannot prove trade-for-trade execution fidelity in the destination platform.
The smoke test does not compile MQL5 or establish parity for arbitrary graphs; only supported kernels with named refusal and coverage may be described.
A Stochastly graph can produce Python and MQL5 files from the same intermediate rule. Custom Python signals cross to MQL5 when their syntax fits the supported compiler subset.
Start with the strategy graph
The exporter reads the strategy node, direction and supported execution rules from the graph. A shared intermediate expression tree renders the Python and MQL5 targets; the Python file is not translated into MQL5 line by line.
A Custom strategy node is different. Its Python source goes verbatim to the Python target. For MQL5, a compiler accepts a bounded signal vocabulary and names unsupported syntax in a refusal.
Read the refusal and coverage report
A kernel without a measured mapping is refused by name. Wired filters that change entries can block export; a signal rule with Session position rules is also refused.
The report separates file creation, measured signal coverage and complete-graph scope. Python signal execution is checked against the engine; MQL5 source is checked for defined identifiers, without an MQL5 runtime comparison.
Check parity on the destination
Compile the MQL5 file in MetaEditor. Export trade lists from the Python run and the MetaTrader tester for matching symbol, bars and settings. Pair trades by entry time and side, then compare entry price, exit time, exit price and exit reason; report unmatched trades separately.
The repository's Python execution test requires the same entry bar, exit bar, side and gross R for engine and generated Python trades, with zero tolerance and extra trades counted. That tolerance is not a measured Python-to-MQL5 tolerance: no repository test executes the MQL5 file in MetaTrader.
Investigate mismatches against spread, tick model, server time and session boundaries before interpreting net returns. Record commissions, stop and target settings and the first differing trade, since signal agreement alone cannot establish equal fills.
Frequently asked questions
Can any Python file be converted to an Expert Advisor?
No. Stochastly exports a supported graph or a Custom signal in the compiler's bounded vocabulary. Other Python constructs receive a named refusal.
Are Python and MQL5 exports identical in behaviour?
They start from a common rule for supported graph strategies. The Python signal has an execution check; the MQL5 file still needs compilation and destination testing.
Sources
Stochastly (n.d.). Export targets and known limits. Product documentation. Accessed 2026-10-03.
Stochastly (n.d.). Export to six targets. Product overview. Accessed 2026-10-03.
MetaQuotes (n.d.). Strategy Testing. MetaTrader 5 Help. Accessed 2026-10-03.
Primary source for Export a supported Python strategy to MQL5
Related
Backtest workflow
MQL5 Expert Advisor robustness test