Training a Random Forest on Historical Bars and Deploying It in MQL5
Summary
This article walks through a workflow for preparing MetaTrader 5 historical data in Python, creating a next-period direction label, fitting a Random Forest classifier, and evaluating predictions with precision and a rolling time-series backtest. It then describes exporting a model for use in MQL5, where an Expert Advisor prepares market inputs, requests predictions from an ONNX model, and can act on signals when a new bar appears.
The examples use OHLC and tick-volume features and hold out the latest observations for an initial test, followed by expanding historical training windows. The article is instructional rather than a rigorous performance study: the supplied text gives no reported precision value, profitability, costs, or risk-adjusted results. Its target construction and evaluation need careful review before practical use, since a next-hour direction label alone does not establish a tradable edge, and the article’s descriptions contain some inconsistencies about the target data.
Key ideas
- Historical MetaTrader data can be loaded and explored in Python before model training.
- A binary target is created by comparing a future price with the current close.
- A Random Forest is fitted on price and tick-volume predictors and assessed with precision.
- Rolling expanding-window evaluation simulates training on past data and predicting later periods.
- The model is then integrated into MQL5 through ONNX inference and new-bar trading logic.
- Predictive accuracy alone does not establish profitability or account for trading costs.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.