Every ONNX model carries an opset version — the version of the ONNX operator spec it was built against. Newer opsets add operators and improve existing ones, but consuming runtimes have to catch up. Use opset 17 for any model you export today for MetaTrader 5 use. The reasoning, the compatibility matrix, and the upgrade path are below.

The recommendation

Pin opset to 17 in your export call. It's the highest version that's broadly supported by MQL5 Build 5572's ONNX Runtime while still supporting all the modern ops you actually need (transformer attention, LayerNorm fused, etc.).

opset 17 in every exporter
# PyTorch torch.onnx.export(..., opset_version=17) # tf2onnx python -m tf2onnx.convert ... --opset 17 # skl2onnx / onnxmltools convert_sklearn(..., target_opset=17) convert_lightgbm(..., target_opset=17)

Why not higher?

Higher opsets exist (18, 19, 20+ as of 2026). The problem is the consuming end — MT5's bundled ONNX Runtime may not yet have full coverage of the newer ops. Symptoms of opset-too-high:

Opset 17 (released October 2022) is mature, broadly supported, and covers everything retail trading needs.

Why not lower?

Pre-17 opsets miss useful operators. Specifically:

If you're stuck supporting an ancient consumer for some reason, opset 14 is the lowest you'd realistically target. But for MT5, there's no reason to go below 17.

Checking the opset of an existing model

check_opset.py
import onnx m = onnx.load("model.onnx") print("Opset(s):", [(op.domain or "ai.onnx", op.version) for op in m.opset_import])

Or in Netron: click on the empty graph background, look at the right panel for opset_import.

Re-converting a model to a different opset

If you have a model that's at opset 20 and you need opset 17, the cleanest fix is to re-export from the original training code. If you don't have the original code, onnx.version_converter can sometimes down-convert:

opset_convert.py
import onnx from onnx import version_converter m = onnx.load("model.onnx") m17 = version_converter.convert_version(m, 17) onnx.save(m17, "model_opset17.onnx")

This works for many graphs but not all — some ops in higher opsets have no direct equivalent in 17, and the converter will refuse. The reliable answer is always to re-export from training code.