Home / Blog / Strategy Testing & Automation
Strategy Testing & Automation
What is an EMA crossover strategy?
An EMA crossover strategy buys when a fast exponential moving average crosses above a slower one and sells when it crosses back below. On futures day-trading charts the common pairs are the 9 and 21 EMA or the 20 and 50, and because both lines lag price, the cross confirms a move after it has started and flips back and forth when price goes sideways.
This post shows how an EMA is calculated, how much a crossover lags, what it does in a range, and how to put a stop and a size on it so it fits a prop account's daily loss limit and trailing drawdown. The prices in the pictures are made up to show the arithmetic; they are not market data.

Free strategy breakdown · free with your email
EMA trend following breakdown
The rule card, a real MNQ trend day, a real day of two quick stops, and what the trailing exit gives back.
✓ It's yours. The link is on its way to your inbox. Open the ema trend following breakdown now
Read the free overview firstHow an EMA is calculated
An exponential moving average is a running average of closes that weights the newest close most:
- EMA today =
α× today's close + (1 − α) × yesterday's EMA α = 2 ÷ (length + 1)- 9 EMA:
α = 2 ÷ 10 = 0.2 - 21 EMA:
α = 2 ÷ 22 ≈ 0.0909
A worked step (example figures): both EMAs stand at 30,000.00 and the next bar closes at 30,010.00.
- 9 EMA:
0.2 × 30,010 + 0.8 × 30,000 = 30,002.00 - 21 EMA:
30,010 ÷ 11 + 30,000 × 10 ÷ 11 ≈ 30,000.91
The 9 EMA moved 2 points toward the new close, the 21 EMA less than 1. That difference in speed is the whole strategy: when price rises for a while, the fast line pulls above the slow one.
Why a crossover lags
On a steady move, an EMA trails price by about (length − 1) ÷ 2 bars:
| EMA | Lag in bars | On 1-minute bars | On 5-minute bars |
|---|---|---|---|
| 9 | (9 − 1) ÷ 2 = 4 |
4 minutes |
20 minutes |
| 21 | (21 − 1) ÷ 2 = 10 |
10 minutes |
50 minutes |
If price rises 1 point a bar, the 9 EMA sits 4 points under it and the 21 EMA 10 points under it. In the picture at the top, price reaches 30,040 with the 9 EMA at 30,036 and the 21 at 30,030.
The cross happens later still, because the fast line has to catch up with the slow one after price turns. In the made-up V below, price falls 2 points a bar to a low of 30,000, then rises 2 points a bar. The 9 EMA crosses above the 21 EMA 12 bars after the low, with price at 30,024.

2 points a bar × 12 bars = 24 points of the move gone before the signal. On 5-minute bars that is an hour. The mirror happens at the exit: when the rise turns into a fall at the same speed, the cross back down comes about 12 bars and 24 points after the top. A crossover never buys the low or sells the high. It buys after a turn is confirmed and gives back part of every move at the end.
What a crossover does in a range
In a trend, the lines stay apart and the lag is the price of the signal. In a range, the lag works against you on every trade.
The second picture is a made-up range: price swings between 29,985 and 30,015, one full swing every 12 bars. The 9 and 21 EMA cross every 6 bars, each time after price has already turned. So every buy lands near the top of the range, about 30,013, and every sell near the bottom, about 29,987.

Run as a plain stop-and-reverse, each reversal costs about 30,013 − 29,987 = 26 points. Six reversals cost about 6 × 26 = 156 points, 156 × $2 = $312 on one MNQ, before commissions and slippage. Nothing went wrong; the rules did exactly what they say, in the wrong kind of day.
Hypothetical results. The range example above is arithmetic on made-up prices, before commissions and slippage; it is not a trade anyone placed. CFTC Rule 4.41: hypothetical or simulated performance results have certain limitations. Unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under- or over-compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.
Real days are messier than a sine wave, but the pattern is familiar to anyone who has watched two EMAs flatten. Our EMA trend following post shows a real MNQ session, 28 October 2026, where the 9 EMA crossed under the 21 at 10:35 ET and the lines kept crossing through late morning.
Crossover vs EMA trend following
The two are often confused:
| EMA crossover | EMA trend following (our version) | |
|---|---|---|
| Entry | The cross itself | A pullback to the 9 EMA, in the direction the cross set |
| Exit | The opposite cross | The first 5-minute close past the 21 EMA |
| Stop | None in the plain version | 1 tick past the setup bar, at least 10 points |
| Trades a day | As many as the lines cross | Two at most, one at a time |
In trend following, the cross only says which way to trade. The entry waits for price to come back to the fast line, and the stop and the two-trade cap set what a wrong guess costs before it happens. The EMA trend following breakdown has the full rule card and two real MNQ sessions, one that worked and one that did not.
Free strategy breakdownSee it on real charts: the ema trend following breakdown has the rule card, a day it worked and a day it failed.Get it ↓Common EMA pairs
- 5, 8 and 13. Very short. Turns quickly, crosses often, so more signals and more of them in chop.
- 9 and 21. A common pair on 1- to 5-minute charts. Lag of about
4and10bars. - 20 and 50. Slower. About
9.5and24.5bars of lag by the same formula, so fewer crosses, each one later. - 50 and 200. The "golden cross" and "death cross" names usually refer to this pair on daily charts, often with simple rather than exponential averages. It is a long-term chart signal, not a day-trading rule.
No pair is the right one. A shorter pair trades lag for whipsaw; a longer one trades whipsaw for lag. Pick one, write it down, and test that exact pair.
Putting a crossover in a prop account
Add a stop before the entry. In the plain version the exit is the next cross, and nobody knows at the entry how far away that will be. A prop account has a daily loss limit that does not wait for the next cross. Choose a stop in points first: past the most recent swing, or a fixed distance you have tested.

Size from that stop (example figures, not results): a 40-point stop on MNQ is 40 × $2 = $80 a contract. With a $200 budget per trade, $200 ÷ $80 = 2.5, which rounds down to 2 MNQ, risking $160. A $1,000 daily limit covers $1,000 ÷ $160 = 6.25, so 6 full stops. The position size calculator does this division for your own numbers, and the MNQ tick value post has the $0.50 a tick and $2 a point behind it.
Cap the trades. In the range above, at 2 MNQ each reversal costs 26 × $4 = $104, and six cost $624, before costs. A cap of two trades a day stops that at $208. A cap does not make the strategy better; it decides how much a sideways day can cost.
Remember the exit gives back open profit. By the V arithmetic above, the cross back down comes about 24 points after the top. On one MNQ that is $48 of open profit gone at the exit. Under an intraday trailing drawdown the floor has already moved up with that open profit, so the room left is smaller than the closed profit suggests.
Common mistakes
- Trading crosses inside the bar. On a live chart the EMAs move until the bar closes. A cross that shows mid-bar can disappear by the close. Act on closed bars only, and test it the same way.
- No stop. "The opposite cross is my stop" is a stop with no distance. Size cannot be calculated without one.
- Same size on every trade. If your stop is a swing, its distance changes. Size each trade from its own stop.
- Changing the pair after a bad day. Switching from 9/21 to 20/50 because of last week is a new strategy with no test behind it.
- Testing without costs. A crossover trades often. Commission and slippage on every entry and exit add up faster than on a strategy that trades twice a day.
- Ignoring the overnight session. On a 24-hour chart the EMAs at the 9:30 ET open come from overnight bars; on a regular-session chart they carry over from yesterday's close. Pick one and test on that one.
Automating a crossover
A crossover is often the first strategy people automate, because the rule is one line: in TradingView's Pine Script, ta.crossover(fast, slow) is true on the bar where the fast series crosses over the slow one; on a live bar it can change until the bar closes, so confirm on closed bars. On the chart, two of TradingView's built-in "Moving Average Exponential" indicators, lengths 9 and 21 on the close, show the same lines. How to automate a TradingView strategy walks through the steps from alert to order. Automation does not remove risk: it places the same trades, including the ones in a range, faster than you can stop them.
Test it before you trade it
Write the rules so two people would code them the same way: the pair, the timeframe, closed bars, the stop, the size, the trade cap and the time you go flat. Backtest them on your contract over many sessions with costs, then forward-test on a simulator. Our free guide, Build It, Break It, Then Trade It, walks through each step.
The full EMA trend following breakdown turns the crossover into a rule set with a stop, a cap and a trailing exit, and shows two real MNQ sessions step by step. It is free with your email, below.
Diagrams on this page are illustrations drawn by Tarrow Futures from made-up prices; they are not market data or trade results. Figures are before commissions and slippage. MNQ point value: CME Group contract specifications.
Free strategy breakdown · free with your email
EMA trend following breakdown
The rule card, a real MNQ trend day, a real day of two quick stops, and what the trailing exit gives back. We email you the link, so it is one tap away next time.
✓ It's yours. The link is on its way to your inbox. Open the ema trend following breakdown now
Read the free overview firstQuestions
What is an EMA crossover strategy?
A rule set that buys when a fast exponential moving average (for example the 9 EMA) crosses above a slower one (for example the 21 EMA) and sells or goes short when it crosses back below. In its plainest form it is always in the market, and the opposite cross is both the exit and the next entry.
What is the 9 and 21 EMA crossover?
The 9-period EMA crossing the 21-period EMA, a common pair on 1- to 5-minute day-trading charts. With EMA lag of (length − 1) ÷ 2 bars, the 9 EMA trails price by about 4 bars and the 21 EMA by about 10 on a steady move, so the cross confirms a turn several bars after it happened.
Is the EMA crossover a good strategy?
No rule set is good or bad in general; it depends on the exact rules, the market, the timeframe and the costs, tested over many sessions. What is true of every crossover is arithmetic, shown in the post. It reacts after price has turned, it gives back part of each move at the exit, and it buys high and sells low inside a sideways range.
Which EMA crossover is best for day trading?
There is no best pair. Shorter EMAs (such as 5 and 8, or 9 and 21) turn sooner and cross more often; longer ones (such as 20 and 50) cross less often and later. Choose the pair, then test that exact pair on your contract and timeframe with costs before trusting it.
How do you calculate an EMA?
EMA today = α × today's close + (1 − α) × yesterday's EMA, where α = 2 ÷ (length + 1). For a 9 EMA, α = 0.2; for a 21 EMA, α = 2 ÷ 22, about 0.0909.
Where do you put the stop on an EMA crossover trade?
The plain crossover has no stop; the opposite cross is the exit, and its distance is unknown when you enter. In a prop account, set a stop in points before the entry (past a recent swing, or a fixed distance), size from it, and check how many full stops fit your daily loss limit.
Educational material only. Not financial, investment or trading advice, and not a recommendation to trade any contract or size. Prop firm rules differ and change; the current rulebook of the firm you use decides. Worked examples use example figures, not results. Futures trading involves substantial risk of loss. Evaluations are paid tests and most people who take one do not pass.