A single train/test split is the most common reason an ONNX EA looks brilliant in backtest and dies live. Markets change regime; one split just tells you how the model did on one slice of history. Walk-forward validation tests the model the way it will actually be used: train on the past, predict the next unseen window, then roll forward.
Why one split lies
With a single 80/20 split you can tune features and thresholds until the test slice looks great — that is just a slower form of curve-fitting. You also risk lookahead: any normalization or feature computed over the whole dataset leaks future information into the past.
Anchored vs rolling windows
- Rolling: fixed-size train window slides forward (e.g. train 12 months, test the next 1, then shift by 1). Adapts to recent regime; less total data per fit.
- Anchored: train window grows from a fixed start; test the next slice each step. More data, slower to forget old regimes.
The loop
for split in walk_forward_splits(data, train=12*m, test=1*m, step=1*m):
model.fit(split.train_X, split.train_y) # fit only on past
scaler = fit_scaler(split.train_X) # scaler from train only
pred = model.predict(scaler.transform(split.test_X))
record(oos_metric(split.test_y, pred)) # out-of-sample only
Judge the model on the distribution of out-of-sample results across all folds, not the best fold.
Applying it to an ONNX EA
You do not retrain inside MQL5. Walk-forward happens offline in Python; each accepted window produces a new model you export to ONNX, version, and swap into the EA on a schedule. Keep the feature and normalization code identical between Python and the EA — the classic silent break is documented in the normalization bug.
What good looks like
Consistency beats peak. A model that is modestly profitable across most folds is more trustworthy than one that is spectacular in two folds and negative in the rest. Pair it with a confidence filter so the EA simply doesn’t trade when the model is unsure.
Frequently asked questions
Do I retrain the model inside MetaTrader 5?
No. Retraining and walk-forward happen offline in Python; you export each validated model to ONNX and load the versioned file in the EA. MQL5 runs inference, not training.
Rolling or anchored windows?
Rolling adapts faster to regime change and is usually the safer default for retail forex; anchored uses more data and forgets old regimes more slowly.
Running this live?
See which prop firms allow ONNX-driven EAs, or compare MT5 brokers for running an ML EA.