The CNN-LSTM is the textbook deep-learning architecture for time-series price prediction: a 1D convolution extracts local patterns over a few bars, then an LSTM aggregates them over the longer sequence. It's the architecture you'll find in academic papers, retail tutorials, and a surprising number of production MT5 EAs. This article shows the end-to-end pipeline: model, training, export, MQL5 integration.
Caveat upfront: price forecasting is genuinely hard. The CNN-LSTM doesn't outperform a coin flip out of the box. The architecture is fine; the data, features, and labeling are what matter. We'll cover the parts that are usually wrong.
What's in this article
The architecture
Labels: what to actually predict
"Predict the next close" is the wrong objective — almost-perfect regression on price is trivial (next close looks like current close) and useless for trading. Two better choices:
- Predict the N-bar-ahead log return. A regression task, but the output is a return (signed) so a positive prediction means buy.
- Predict a binary direction (up/down) at N bars ahead. A classification task. Easier to threshold for trading.
The classifier approach is often more practical. The architecture above ends with a single output for return prediction; swap the last Linear to nn.Linear(lstm_hidden, 2) for binary classification.
Inputs and normalization
Reasonable feature vector for a 1-hour timeframe model:
- Log returns of close over last 120 bars (1).
- Log returns of high (1).
- Log returns of low (1).
- Log volume (1).
That's 4 features × 120 bars. Normalize each feature by its rolling mean/std over a 500-bar window so the model sees stationary inputs across regimes (see normalization article).
Export the model
The crucial bit for CNN-LSTM: seq_len must be static at export time (the LSTM trap). See PyTorch LSTM to ONNX.
Use in MQL5
What to expect
Realistic outcomes from a CNN-LSTM trained without genius:
- Direction accuracy 51–54%. Significantly above coin flip if the dataset is reasonable; not a money-printer.
- Profitability depends on costs. 53% direction accuracy with 1-pip spread on EURUSD H1 is barely break-even. On smaller spreads, profitable.
- Returns are autocorrelated. Many small wins, occasional larger losses. Sharpe is the metric to optimize, not raw accuracy.
Pair the CNN-LSTM with a regime filter (see market-structure classifier) for substantially better risk-adjusted returns than either alone.