scikit-learn covers the "everything classical" half of the ML world — logistic regression, random forests, SVM, gradient boosting, k-means. All of these can be exported to ONNX with skl2onnx, the official scikit-learn-to-ONNX converter maintained by ONNX itself.
What's in this article
Install
Minimal example: random forest
Converting a full Pipeline (with normalization)
If you wrapped your model in a Pipeline with a StandardScaler (recommended), skl2onnx exports both as part of the same ONNX graph. The MQL5 side then receives raw features and the model normalizes them internally:
This is the cleanest way to handle normalization — bake it into the graph. The alternative (saving stats to JSON and re-applying in MQL5) is more code but slightly more flexible. Both work.
Dtypes: the int64 trap
scikit-learn's classifiers output two things: the predicted class (an integer) and the class probabilities (floats). By default, skl2onnx packages the probabilities as a ZipMap — a sequence of class-to-probability dictionaries. MQL5's ONNX runtime doesn't handle ZipMap well.
The fix is in the example above: options={id(clf): {"zipmap": False}}. This makes the output a plain 2D float matrix (shape [batch, n_classes]), which MQL5 reads cleanly. Without this flag, you'll get cryptic errors at OnnxRun time.
The other dtype issue: classifiers output an int64 prediction tensor. MQL5 reads it with vector<long> (signed 64-bit) rather than the more familiar float types. Check with Netron which output index is the class and which is the probability — you'll usually want the probability matrix only.
Loading in MQL5
Running this live?
See which prop firms allow ONNX-driven EAs, or compare MT5 brokers for running an ML EA.