Ready to go further
Next: test a rule on data it has not seen
The backtesting guide covers time-ordered splits, costs and untouched data, the checks any model has to pass.
What is included
- What it is, in plain words
- The formula or mechanism, with exact arithmetic
- How it hits grid, martingale and DCA bots
- A check you can run before you switch a bot on
Who it is for
- People who run or plan to run a trading bot
- Anyone reading a backtest or a bot sales page
- Readers who want the numbers, not the pitch
- Not advice, and not a signal service
Key facts
- Machine learning trading means using a model, fitted to past data, to produce a signal such as buy, sell or stay out. The model is a fitted formula. It does not understand markets.
- A model can find patterns faster and in more variables than a person. It cannot tell a repeating pattern from noise, and price data is mostly noise.
- Two failures dominate: overfitting (the model memorises the past) and leakage (the model is given information it would not have had at the time).
- Worked example on made-up noise data: 40 random models, the best on 150 training days scored +0.118% a day and then -0.044% a day on the next 50 test days (calculated by us on 29 Oct 2026, exact for this seed).
- A better model does not fix a missing edge. Test on data the model never saw, include costs, and paper trade first.
What a model does
A machine learning model takes inputs, called features, and produces an output. A feature might be yesterday's return, a moving average gap or the time of day. The output might be a number, such as a forecast of tomorrow's move, or a class, such as up or down. The model is fitted by adjusting its internal numbers until its outputs match past examples as closely as possible.
That is all. There is no understanding of why prices moved. If the link between features and the next move was real and repeats, the fitted model may carry some of it forward. If the link was chance, the model carries chance forward, and it looks just as confident either way.
What a model can and cannot do
- It can search many features and many shapes of relationship far faster than a person, and apply the same rule without tiring.
- It can be a useful part of a bot, for example to rank candidate trades or to estimate how volatile the next period may be.
- It cannot know the future. It only extends what the past data contained.
- It cannot separate signal from noise by itself. A flexible model with enough settings fits both.
- It cannot adapt to a change nobody put in the data, such as a new rule, a new kind of participant or a crash with no earlier example.
- It cannot make a rule profitable after costs if the raw edge is smaller than the spread and slippage. See slippage.
Why overfitting and leakage dominate
Price data has a very low signal-to-noise ratio. A flexible model fitted to it will find shapes that are not there. This is overfitting, and the more features, settings and models you try, the more the best result flatters you.
Leakage is a different mistake with the same look. It is when information from after the moment of the decision gets into the features or the labels. Common ways: scaling or normalising a column using the whole data set, building a feature from the same day's close and trading at that close, or shuffling rows in time before splitting. The result is a model that looks accurate in testing and has nothing to stand on live. See look-ahead bias.
A worked example: a train and test split
Everything here is made up and is pure noise by construction. We generated 200 daily returns with no pattern in them. We then made 40 "models", each of which is just a random long-or-short call for every day. By design none of them has any edge.
We split the days in time order: the first 150 are the training days, the last 50 are the test days. We scored each model by its average daily result (call times return, in percent) and picked the one with the best training score, as a careless search would. Then we looked at it on the test days.
| Model | Training days (avg %/day) | Test days (avg %/day) |
|---|---|---|
| Best on training (model 19) | +0.118 | -0.044 |
| Second best on training (model 34) | +0.093 | +0.023 |
| Third best on training (model 18) | +0.088 | -0.043 |
| Average of all 40 models | -0.005 | -0.019 |
Calculated by us on 29 Oct 2026, exact for this seed. The winner on the training days looks like a find. On the test days it has no reason to repeat, and it scored -0.044% a day. Across all 40 models, 18 finished above zero on the test days and 22 did not, which is what coin flips give. The training score was the best of 40 tries, and the best of many tries is large by chance alone.
Three points about the method. The split is by time, never by shuffling. The test days are looked at once; if you look, change the model and look again, they become training data. And the cost of trading is left out here, which only makes real results worse.
How it hits bots
- Grid and martingale bots are sometimes sold with a model that picks the range or the multiplier. The model was fitted to a history in which that choice worked, and the tail loss that ends these bots rarely appears in a short history.
- EAs that advertise a neural network or AI filter usually give no description of the training data, the split or the number of versions tried. Ask for them. See expert advisors.
- Retraining on a schedule means the model chases the recent past. If the pattern was noise, each retrain finds a new noise pattern.
How to check a model before any money
- Split by time. Fit on the early data, validate on the middle, keep the last stretch sealed until the very end.
- Fit scalers and every other transform on the training part only.
- Count the models, features and settings tried, and treat the best result as the best of that many.
- Compare against a plain baseline such as a simple rule or buy and hold. A model that cannot beat the baseline after costs adds nothing.
- Run a Monte Carlo check on the trades, then forward test and paper trade.
What this page does not tell you
It does not say machine learning cannot work. It says a good backtest from a model is weak evidence, and the checks above are the minimum. The numbers are made up and nothing here is a method to trade.
Keep Going
Related Tools and Guides
Keep exploring
FAQ
Frequently Asked Questions
Can machine learning predict the market?
Not reliably. A model can find patterns in past data, but price data is mostly noise and any pattern found has to repeat to matter. That has to be shown on data the model never saw.
What is overfitting in a trading model?
It is a model fitting the noise in its training data, so it scores well on the past and badly on new data. More features and more tries make it worse.
What is data leakage?
It is information from after the decision time getting into the features or labels, for example scaling with the whole data set or using the same bar's close to trade at that close. It makes tests look far better than live results.
How should I split data for a trading model?
In time order, never shuffled: train on the early part, validate on the next, and keep the last part sealed until the end. Look at the sealed part once.
Is a deep learning model better than a simple one?
Not by default. A bigger model has more room to fit noise. Compare every model with a simple baseline after costs.
Are the numbers on this page real?
Example numbers are made up to show how the maths works, and the page says so. A figure only counts as exact when the page says it was calculated on a stated date. Nothing you enter in a calculator leaves your browser.
Can I use this to decide whether to run a bot?
It can show whether a bot's numbers hold together and how much an account can lose. It cannot say what the market will do, and it is not advice. Use it to ask better questions, then read the terms of your own broker or exchange.
Is this financial advice?
No. It is general education. The example data is made up noise and nothing here is a recommendation.
Know the Risk Before You Run It
Free calculators and guides, added every week. Leave your details and we will email you when new ones go up.
Trading carries a risk of loss