Python → ONNX without the RuntimeError.
If you've tried to export a PyTorch LSTM and watched the export crash on a control-flow op, you're not alone — that bug has been live since 2019 and the workarounds aren't obvious. This silo documents the export workflow that actually lands a working .onnx file inside MetaTrader 5.
Every framework, every gotcha.
Export a PyTorch model to ONNX for MT5
The 2026 workflow with torch.onnx.export(..., dynamo=True), opset 17, and dynamic axes done right.
Export a PyTorch LSTM — the seq_len trick
Why dynamic seq_len with LSTM breaks the export, and the static-batch pattern that ships every time.
Keras CNN-LSTM to ONNX with tf2onnx
The exact TensorFlow 2.10 + tf2onnx pipeline that produces a .onnx MQL5 actually accepts.
read →LightGBM to ONNX with onnxmltools
Tree-based models for tabular features. The Python version pitfall and the input-name convention MQL5 needs.
read →dynamic_axes, explained
What goes dynamic, what stays static, and how the choice cascades into OnnxSetInputShape on the MQL5 side.
Which ONNX opset to target in 2026
Opset 17 is the safe default. Here's why, what opset 18+ unlocks, and what older opsets break.
read →A working environment.
Training a model on GPU is faster, cheaper, and avoids the most common "this took 18 hours and crashed" failure. If you don't have an NVIDIA card locally, the cloud is hourly and cheap for training runs.
Affiliate disclosure: some links above are affiliate links. We earn a commission if you sign up — the recommendations are independent. See our disclosure page.