You attached the EA, the Experts log spat out this, and the EA refused to trade:

MetaTrader 5 — Experts log
ERROR[5800] Failed to load 'models\eurusd.onnx' OnnxCreate returned INVALID_HANDLE

ERROR 5800 is MQL5's generic "I tried to create an ONNX session and it didn't work." The message itself is unhelpful — it can mean six different things. The good news: each cause has a fast, specific diagnosis. Walk through these in order.

Cause 1: file path is wrong

The most common cause, by a wide margin. OnnxCreate takes a path relative to <Terminal Data Folder>\MQL5\Files\, not relative to the EA, not absolute. Two failure modes:

Diagnosis

In MetaTrader 5, click File → Open Data Folder. Navigate into MQL5\Files\. Confirm your .onnx file is exactly where you said. If your code says "models\eurusd.onnx", the file should be at MQL5\Files\models\eurusd.onnx.

Fix

Two clean approaches:

Cause 2: invalid or corrupt .onnx file

The file exists at the right path, but it's not a valid ONNX model. Two scenarios:

Diagnosis

Open the file in Netron — the free ONNX visualizer. Drag the .onnx into the browser tab. If Netron renders the graph, the file is a valid ONNX model. If Netron throws an error, the file is broken — re-export from Python.

If you can't reach Netron, a quick sanity check in Python:

verify_model.py
import onnx model = onnx.load("eurusd.onnx") onnx.checker.check_model(model) print("OK — opset:", model.opset_import[0].version)

If check_model raises, the file is invalid. Re-export.

Cause 3: opset version unsupported

ONNX models are tied to an opset version — effectively, "which version of the ONNX op spec was I built against." Recent PyTorch defaults to opset 18 or higher; the ONNX Runtime in MT5 supports up to opset 19 in Build 5572. If you exported with opset 20+ (using PyTorch nightlies or experimental features), the runtime can't load it.

Diagnosis

The Python snippet above prints the opset. Or in Netron, click on the model background — the right panel shows opset_import.

Fix

Re-export with opset_version=17 explicitly. This is the safe default for MT5 in 2026:

PyTorch export with safe opset
torch.onnx.export( model, dummy, "eurusd.onnx", opset_version=17, # MT5-safe input_names=["input"], output_names=["output"], dynamic_axes={"input": {0: "batch"}, "output": {0: "batch"}}, )

More on opset selection in the opset guide.

Cause 4: GPU initialization failed silently

Sometimes the file is valid and the path is right, but the GPU initialization fails in a way that prevents the whole session from loading — and the only visible symptom is ERROR 5800.

The classic case is CUBLAS_STATUS_ARCH_MISMATCH: GPU below Turing, cuBLAS refuses to initialize, the whole session creation fails, and you see ERROR 5800 in the log (with the underlying cuBLAS error a few lines above).

Diagnosis

Scroll up in the Experts log from the ERROR 5800 line. Look for any line containing CUBLAS, CUDA, or cublasCreate. If there's one, the failure is GPU-related — not file-related.

Fix

Force CPU with ONNX_USE_CPU_ONLY:

force CPU to bypass GPU init
ExtHandle = OnnxCreateFromBuffer(ExtModel, ONNX_USE_CPU_ONLY);

If the session now loads, the cause was GPU. See the CUBLAS fix for the longer story.

Cause 5: file permission / Tester sandbox

The Strategy Tester runs EAs in a sandboxed agent process with its own filesystem view. A file in your live MQL5\Files\ may not be visible to the Tester.

Diagnosis

Does the EA work on a live chart but fail with ERROR 5800 only in the Strategy Tester? It's the sandbox.

Fix

The cleanest fix is to embed the model with #resource — embedded resources travel inside the compiled .ex5 and work in both live and Tester. If you must keep the model as an external file, also place a copy in MQL5\Tester\Files\ (the Tester's separate file root).

Cause 6: ONNX runtime didn't download

Build 5572 changed the ONNX Runtime DLL from "bundled with MT5" to "downloaded on first use." On a brand-new MT5 install, the very first OnnxCreate call may stall while the runtime downloads — or fail entirely if the machine has no internet or a firewall blocks the download.

Diagnosis

Is this a fresh MT5 install? Has any ONNX function ever run on this machine before? If no to both: the runtime isn't on disk yet.

Fix

  1. Confirm the machine has outbound HTTPS access. Some VPS providers firewall everything not on a whitelist — check with your provider.
  2. Restart MT5 and let it sit for 60 seconds before attaching the EA. The first download can take 5–20 seconds.
  3. If still failing, manually check the Terminal\Bases\Default\ directory inside the MT5 data folder — the ONNX runtime DLL should be there. If not, contact MetaQuotes or check the platform logs.

The checklist

When ERROR 5800 appears, walk through these in 5 minutes:

  1. Is the file where you said it is? (open the data folder, look)
  2. Does Netron open it? (if not, re-export)
  3. Is the opset 17 or lower? (re-export if higher)
  4. Is there a CUBLAS line above the 5800? (force CPU)
  5. Is this in the Strategy Tester only? (embed as resource)
  6. Is this a fresh MT5 install? (let the runtime download)