Ready to go further
Next: what does a string of small losses cost?
Whipsaw trades are often small losses in a row. The expected value calculator shows how win rate, average win and average loss combine.
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
- An EMA is an exponential moving average: an average of recent prices that gives the newest prices the most weight. A crossover rule compares a fast EMA with a slow one.
- The rule in this guide: be long while the fast EMA is above the slow EMA, and flat otherwise. Other versions also go short.
- In the made-up table below, the 3 and 8 EMA cross 7 times in 20 bars. The one trend trade gains +3.00 points and the two range trades make -3.00 and -2.00 (calculated by us on 29 Oct 2026, exact).
- The rule reacts after the move has started, so it always enters late. In a sideways range it flips back and forth and each flip pays costs. That is a whipsaw.
- The settings, such as 3 and 8, are choices. Picking the pair that fit past data best is a common way to overfit.
What an EMA crossover is
A simple moving average adds up the last N closes and divides by N. Every close counts equally, and a close that drops out of the window makes the average jump. An exponential moving average avoids the jump. It keeps one running number and updates it on each new close:
a = 2 / (N + 1)
For N = 3, a = 0.50. For N = 8, a = 0.222
A short EMA (a small N) follows the price closely. A long EMA (a large N) moves slowly. Plot both and the short one sits nearer the price. When a rise begins, the fast line turns up first and crosses above the slow one. When the rise fades, the fast line falls back through the slow one. A crossover bot turns those two events into orders. A first value is needed to start the calculation, and here it is the first close. Platforms differ in how they seed it, so a check against your own chart may differ slightly at the start.
A worked example on made-up prices
The table uses 20 made-up closes. The first three bars are flat at 100, then the price climbs to 108, then it chops between 104 and 107. The rule is long while the 3 EMA is above the 8 EMA, with trades at the close of the bar where the state changes. Every number was calculated by us on 29 Oct 2026 and is exact to the rounding shown.
| Bar | Close | 3 EMA | 8 EMA | State | Action |
|---|---|---|---|---|---|
| 0 | 100.0 | 100.00 | 100.00 | Fast below | |
| 1 | 100.0 | 100.00 | 100.00 | Fast below | |
| 2 | 100.0 | 100.00 | 100.00 | Fast below | |
| 3 | 101.0 | 100.50 | 100.22 | Fast above | Cross up: buy |
| 4 | 102.0 | 101.25 | 100.62 | Fast above | |
| 5 | 104.0 | 102.63 | 101.37 | Fast above | |
| 6 | 106.0 | 104.31 | 102.40 | Fast above | |
| 7 | 107.0 | 105.66 | 103.42 | Fast above | |
| 8 | 108.0 | 106.83 | 104.44 | Fast above | |
| 9 | 107.0 | 106.91 | 105.01 | Fast above | |
| 10 | 105.0 | 105.96 | 105.01 | Fast above | |
| 11 | 107.0 | 106.48 | 105.45 | Fast above | |
| 12 | 105.0 | 105.74 | 105.35 | Fast above | |
| 13 | 107.0 | 106.37 | 105.72 | Fast above | |
| 14 | 104.0 | 105.18 | 105.33 | Fast below | Cross down: sell |
| 15 | 107.0 | 106.09 | 105.70 | Fast above | Cross up: buy |
| 16 | 104.0 | 105.05 | 105.33 | Fast below | Cross down: sell |
| 17 | 107.0 | 106.02 | 105.70 | Fast above | Cross up: buy |
| 18 | 105.0 | 105.51 | 105.54 | Fast below | Cross down: sell |
| 19 | 108.0 | 106.76 | 106.09 | Fast above | Cross up: buy |
The first cross is at bar 3. The bot buys at 101.0 and holds through the climb. At bar 14 the fast line falls under the slow one and it sells at 104.0, a gain of 3.0 points. The price peaked at 108, so the rule gave back part of the move before it exited. That is the cost of waiting for a cross.
Then the range starts. The bot buys at 107.0 on bar 15 and sells at 104.0 one bar later, a loss of 3.0. It buys again at 107.0 on bar 17 and sells at 105.0, a loss of 2.0. At bar 19 it buys again at 108.0 and the trade is still open. With a made-up cost of 0.5 points per round trip, the three closed trades net +2.50, -3.50 and -2.50. Together that is -2.00 points before costs and -3.50 after.
Why it whipsaws in a range
A crossover is a trend rule. It makes money when a move runs far enough after the cross to pay for the late entry, the late exit and the costs. In a range the price swings back before it gets far, so each cross is a false start. The fast line is always close to the price, and the slow line is close to the middle of the range, so a small swing of the price is enough to push the fast line across. Each false start costs the spread and usually some slippage, and a bot that trades every cross pays them again and again.
There is no setting that removes this. A slower pair crosses less often, but it enters later and exits later. A faster pair catches turns sooner, but it whipsaws more. Some designs add a filter, such as a minimum gap between the two lines or a trend test on a longer timeframe. A filter is another setting and another thing to overfit, and it also lets some real trends pass.
How a bot would test it
- Write the rule down exactly. The two lengths, long only or long and short, the price used for the signal, and where the order is placed. If the bot cannot act in time, trade on the next bar's open, not on the close that made the signal. Using the signal bar's own close is a form of look-ahead bias.
- Add full costs. The spread, the fee and a slippage allowance on every cross, as in the example above.
- Test trending and ranging periods apart. Report the result of each. A rule that only works in one has told you which kind of market it needs.
- Count trades and look at the worst run. Check the longest string of losing trades and the max drawdown, not only the total.
- Try neighbouring settings. If 3 and 8 works but 3 and 9 and 4 and 8 do not, the result is probably noise. The steps are in how to backtest a trading strategy.
- Keep data back. Test once on data that was not used to pick the lengths, as described in backtesting.
What it does not tell you
The example shows how the rule behaves on 20 made-up bars. It does not show that the rule earns on any real market, and the path was chosen to illustrate the point. A real test needs far more trades and honest costs. Nothing here is a signal.
Keep Going
Related Tools and Guides
Keep exploring
FAQ
Frequently Asked Questions
What is an EMA crossover?
A rule that compares a fast exponential moving average with a slow one. When the fast one moves above the slow one, the rule reads it as an upward turn, and when it moves below, as a downward turn.
What is the difference between an EMA and an SMA?
An SMA gives every close in the window the same weight. An EMA gives more weight to recent closes, so it reacts sooner and does not jump when an old close drops out.
Which EMA lengths are best?
There is no best pair. The pair that looks best on past data is often the one that fit its noise. Test neighbouring pairs and different periods, and expect the result to change.
Why does an EMA crossover lose in a sideways market?
The price swings back before the cross can pay off, so the rule enters, exits and pays costs again and again. Each of those trades is a small loss.
Can a trading bot run an EMA crossover?
Yes, it is a simple rule to code. The hard parts are honest costs, a fair test and the losing runs in a range, not the rule itself.
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 prices and costs are made up, and no setting 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