Skip to content
All library documents

Training a Random Forest Price Forecaster for MetaTrader 5 with ONNX

Article MQL5 articles

Summary

The article walks through training a RandomForestRegressor in Python and deploying it in MetaTrader 5 through ONNX. It uses hourly EURUSD close prices, turns a rolling history of 100 observations into features, and labels each sequence with a later close price. A scikit-learn pipeline applies MinMaxScaler, RobustScaler, and PolynomialFeatures before fitting the forest, then evaluates predictions with R-squared and exports the pipeline for use by an MQL5 expert advisor.

The deployment section describes matching the ONNX input shape to the Python feature count and using predicted price direction to inform long or short trades. The example proposes take-profit and stop-loss settings, but the excerpt provides no performance results or validation details. It also contains inconsistencies between the displayed MetaTrader data column names and the training code's close-price references, and its random label offset is effectively fixed by the stated bounds. Treat it as an implementation outline rather than evidence of a profitable forecasting system.

Key ideas

  • A rolling sequence of close prices is used as the feature vector for regression.
  • The preprocessing and random forest are combined in one scikit-learn pipeline for ONNX export.
  • The Python feature dimension must match the input shape declared in MetaTrader 5.
  • The example maps predicted price direction to possible long or short actions.
  • The document gives no reported trading performance, and its code examples contain data-column inconsistencies.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.