- Symbol
-
XAUUSD (only BUY)
- Timeframe
- H1
Machine Learning in Trading (AI)
If you open articles on MQL5 about machine learning, you'll likely be amazed at how deeply algorithmic traders have advanced in this area. Hidden Markov models, deep neural networks, Gaussian processes, Bayesian optimization, clustering...But why do we sometimes achieve worse results using sophisticated methods compared to a simple moving average-based EA?
Why Simple Linear Strategies Are Sometimes Better Than AI
To understand this issue, let's look at a simplified example of how model training works in trading:- We take data from various indicators (such as RSI, MACD, iVolume) and feed it to the model.
- Then we tell the model when it should enter a SELL or BUY position. The model trains, evaluates itself — and everything looks great.
- A limited number of independent features (indicators).
In trading, it's not nearly as rich. We only have three core parameters:
- Price
- Time
- Volume
Imagine trying to cook 100 different dishes using only potatoes, salt, and water — not a lot of variety, right?
That’s exactly what happens when you try to feed the model 100 indicators.
and no, we can't just feed the model raw, non-normalized price data — like 3269.09 — in its original form. Imagine you're trying to learn something based on specific examples, but after training, you never see the same example again, and every time you're presented with a thousand entirely unique, non-repeating cases.
That's exactly what the model experiences if you give it raw price values. This leads to 100% overfitting — the model will simply memorize each unique moment instead of learning any real patterns.
Let’s Build an ML-Based Expert Advisor and Compare It to a Simple One
Let's create a machine learning-based expert advisor for trading the all-time favorite XAUUSD.As a feature, we'll use a simple price Slope function:
We’ll call the first EA Model_#0. This model was trained on data from 2015 to 2025.
The backtest results of Model_0 show nearly perfect trading: minimal stop losses and logical trades, all packed into a tiny model under 0.1 MB in size.
Next, we create a second model (Model_1), trained on data from 2015 to 2024, and test how it behaves on unseen 2025 data.
Model_1 performs great during its training period, but as soon as it faces new data, its effectiveness drops significantly:
(the red marks are the learning area)
Interestingly, when we disable SELL trades, performance improves — likely due to the strong bullish trends in XAUUSD. Yes, it's been working for more than a year, but it's already less productive.
BUY only:
Now let’s compare this to a simple linear strategy (call it Stenvall), created and published in 2021, which hasn’t been updated since.
Despite its average results, this strategy delivers stable performance year after year.
ML-based expert advisors can show beautiful backtests and impressive short-term results, but they often lack consistency on future data. In contrast, linear strategies may even outperform their past results thanks to their simplicity and resilience to market changes.
Why does this happen?
This is a difficult philosophical question, why complex things are often worse than simple ones.
Can say:
- Overfitting of complex models to historical data. Due to the lack of good features the model tries to catch even the tiniest patterns — ones that have no real predictive power.
- Complex structural signals are often temporary in nature.
- The resilience of simple strategies based on simple fundamental principles of the market, liquidity zones, support and resistance levels, and so on.
Conclusion
Does this mean machine learning isn't suitable for trading? Of course not. The goal of this example was to show that ML isn’t some magic solution that can look at raw data and tell you where to buy and sell. ML is a powerful tool — but one that requires the right approach.P.S.
Many important aspects — such as data normalization, labeling quality, or Feature Engineering — were left out of this article, since the main focus was on comparing simple vs. complex approaches.
There are many articles on MQL5 about ML, but they’re not always digestible for traders without a technical background. I just wanted to explain some complex topics in simple words, and I hope this article adds a bit of clarity.
The EA from the article is free to download and distribute.