Ready to go further
Next: see why the best of many tries misleads
The overfitting guide shows how trying many settings on the same data produces a winner by chance, with the arithmetic.
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
- Reinforcement learning has three parts: an agent that acts, an environment that responds, and a reward that scores each result. The agent learns to pick actions that earned the most reward.
- In trading the actions are buy, sell or hold, and the reward is usually profit. The environment is a replay of past prices, which does not react to the agent's orders.
- Reward design decides what the agent learns. Reward raw profit and it may trade constantly, ignore costs and take hidden risk.
- Worked toy example on made-up random prices: the best of 81 policies earned +5.90 points in training and -3.96 on a new series (calculated by us on 29 Oct 2026, exact for these seeds).
- Overfitting is the main failure. A flexible agent trained on one history memorises it, and that history is only one of many that could have happened.
The three parts, plainly
- The agent is the decision rule. At each step it looks at the state (some numbers describing the market and its own position) and chooses an action.
- The environment is everything the agent acts on. In trading it is usually a replay of past price data plus a simple model of fills and costs.
- The reward is a number the agent receives after acting. It is the only thing the agent is trying to increase.
Training repeats a loop: observe the state, act, receive the reward, adjust the decision rule so that actions followed by high reward become more likely. After many passes through the data the agent has a policy, which is a map from state to action. Some versions use a table of values, others a neural network. The idea is the same.
Why trading is a hard fit
- Little data. Games let an agent play millions of times. A price history is one path. Ten years of daily bars is about 2,500 steps, and nearly all of it is noise.
- No push back. In a replay your orders do not move the price, so the agent never learns about its own market impact or about partial fills.
- The rules change. The environment that produced the data is not the one that will produce tomorrow's.
- Delayed, noisy reward. A trade's result is mostly luck, so credit goes to actions that were not the cause.
Why reward design breaks it
The agent maximises the reward you wrote, not the result you meant. Raw profit ignores risk, so an agent can learn a policy that earns steadily and then takes one huge loss that the training data never contained. A reward with no trading cost teaches it to trade on every wiggle. A reward on closed trades teaches it to hold losers open. Adding penalties (for costs, for drawdown, for size) helps, but each penalty is a number you chose, and the agent will find the gap in whichever one you forgot. See drawdown and slippage.
A worked example: a toy agent on random prices
Everything here is made up. We generated two price series of 300 bars each, series A and series B, both random with no pattern. The state is whether each of the last two moves was up or down, so there are 4 states. In each state the policy chooses short, flat or long, which gives 3 x 3 x 3 x 3 = 81 possible policies. "Training" is the simplest possible form: score all 81 on series A and keep the best. The cost is 0.05 points for each unit of position change.
We did it twice, to show reward design. In the first the reward ignores cost. In the second the reward subtracts cost. Then both winners were played, with cost, on the new series B.
| Reward used in training | Training reward (A) | Trades in training | Result on new series B (with cost) |
|---|---|---|---|
| Raw profit, no cost | +5.90 | 89 | -3.96 |
| Profit minus cost | +3.36 | 1 | -6.22 |
| Average of all 81 policies | - | - | -10.52 |
Calculated by us on 29 Oct 2026, exact for these seeds. The first agent made 89 position changes in training, because its reward never counted cost. The second made 1, so once trading was charged for, it settled into holding a position. Both look good on A, which is the best of 81 tries on one random path. On B, where there is nothing to find, they scored -3.96 and -6.22. Across all 81 policies the average on B was -10.52 and only 3 finished above zero. Over the whole of series A the price rose 3.75 points and over series B it fell 6.06 (calculated by us, exact), so a policy that learned to hold a long position on A met a falling path on B. The training score said nothing about it. That is a toy with 81 policies. A neural network agent has far more room to memorise.
How it hits bots
- Sold as "AI that learns the market". Ask what the reward was, what data it trained on, how many versions were tried and what it earned on data it never saw.
- Grid and martingale behaviour. An agent rewarded on profit per step can learn to add to losers, because most steps in the training data recovered. That is a martingale in disguise, with the same tail.
- Constant retraining. Each retrain on recent data can fit a new noise pattern, so past live results say little about the next version.
How to check an agent before any money
- Train on early data and test once on a later period it never saw. See overfitting.
- Include spread, fees and slippage in the environment and in the reward.
- Run it on random prices. If it earns there, the environment has a leak. See look-ahead bias.
- Check the worst fall and the largest single loss, not only the total reward.
- Compare with a plain fixed rule. If the agent cannot beat it after costs, it adds complexity and nothing else.
- Forward test and paper trade before any real size.
What this page does not tell you
It does not say reinforcement learning cannot work in some settings. It says that in trading the data is thin, the reward is easy to get wrong and the agent is free to overfit. The toy numbers are made up and nothing here is a method to trade.
Keep Going
Related Tools and Guides
Keep exploring
FAQ
Frequently Asked Questions
What is reinforcement learning in trading?
It is a method where an agent chooses actions such as buy, sell or hold, receives a reward such as profit, and adjusts its decision rule toward actions that earned more reward.
Why is reward design so important?
The agent maximises the reward you wrote, not the result you meant. A reward with no cost or risk term can teach it to over-trade or to take a hidden large loss.
Why does reinforcement learning overfit in trading?
A price history is one path and mostly noise. A flexible agent can memorise that path, and the memorised pattern does not repeat on new data.
Is a reinforcement learning bot better than a rule-based bot?
Not by default. It has more room to fit noise and is harder to explain. Compare it with a plain rule after costs, on data it never saw.
Can I train an agent on historical prices safely?
Training is safe in the sense that no money is at risk. The risk is believing the result. Hold back data, include costs, and treat a good training score as weak evidence.
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 is a toy on made-up random prices 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