XGBoost is one of the strongest baselines for tabular market features, and it deploys to MetaTrader 5 through ONNX just like LightGBM and scikit-learn. Like other tree models, it runs on CPU inside MT5 — no GPU required — which makes it a practical filter to pair with a rules-based EA.
Note
Tree ensembles (XGBoost, LightGBM, random forest) do not use CUDA inference in MT5. GPU acceleration in Build 5572 applies to neural-network ONNX graphs. For trees, CPU is expected and fine.
Install
You need xgboost plus the ONNX converters:
pip install xgboost onnxmltools onnxconverter-common onnxruntime
Train a model
import xgboost as xgb
model = xgb.XGBClassifier(n_estimators=200, max_depth=4)
model.fit(X_train, y_train) # X_train: float32 feature matrix
Convert to ONNX
Use onnxmltools with an explicit float input type. Pin the opset to 17 for MT5:
from onnxmltools.convert import convert_xgboost
from onnxconverter_common.data_types import FloatTensorType
initial_types = [("input", FloatTensorType([None, X_train.shape[1]]))]
onnx_model = convert_xgboost(model, initial_types=initial_types, target_opset=17)
with open("xgb.onnx", "wb") as f:
f.write(onnx_model.SerializeToString())
Mind the dtypes (the int64 trap)
Feed the model float32 features, not int64. A classifier also emits a label plus a probability tensor — decide which output your EA reads and confirm its name in Netron. This mirrors the scikit-learn int64 trap.
Use it in MQL5 (CPU-only)
Load it like any ONNX model, but keep inference on CPU with ONNX_USE_CPU_ONLY — there is nothing for CUDA to accelerate in a tree ensemble. See the OnnxCreate / OnnxRun reference.
Validate before shipping
Run an ONNX Runtime parity check against the XGBoost prediction on the same input; if they match on the desktop, any MT5 discrepancy is a shape/dtype/normalization issue, not the model.
Frequently asked questions
Does XGBoost use the GPU in MetaTrader 5?
No. Tree ensembles run on CPU in MT5. Set ONNX_USE_CPU_ONLY; CUDA acceleration in Build 5572 targets neural-network graphs, not gradient-boosted trees.
Which opset should I use for XGBoost to ONNX?
Target opset 17, the MT5-safe default in 2026, via target_opset=17 in convert_xgboost.
Running this live?
See which prop firms allow ONNX-driven EAs, or compare MT5 brokers for running an ML EA.