Z-score trading: entry thresholds, exit at the mean, ES backtest
A z-score measures how many standard deviations the price sits from its recent average. Enter against the move when it passes a set distance, often 2, exit when it returns to zero, test lookback and threshold as a plateau after costs, and pair the rule with a trend filter or a stop.
By Soren Huang · Published · updated · Editorial policy
Contents
- How do you use a z-score to time mean reversion entries?
- How do you calculate a z-score on price and on a spread?
- What lookback and threshold should you set?
- Why exit at the mean instead of the opposite band?
- How is a z-score different from Bollinger Bands?
- What happens to z-score entries in a trending market?
- What does an ES futures backtest show?
- Frequently asked questions
- References
How do you use a z-score to time mean reversion entries?
Z-score trading means you measure how many standard deviations the price sits from its recent average, enter against the move when that distance passes a set threshold (often 2), and exit when the z-score returns to zero. Test the lookback and the threshold as a plateau, after costs, and add a trend filter or a stop.
A z-score is the distance between the current value and its recent average, expressed in units of the recent standard deviation. Think of a rubber band. A z-score of zero is the band at rest. A z-score of 2 means the band is stretched twice as far as it usually stretches. Mean reversion trading bets that a stretched band snaps back, and the z-score tells you how stretched it is in one number that reads the same on any market.
The entry rule has three parts. When the z-score crosses below the negative threshold, you buy. When it crosses above the positive threshold, you sell short. When it crosses back through zero, you close the trade. The threshold is a filter: a higher value gives fewer, deeper entries. Statistical mean reversion is the version of this idea that works on a measured relationship rather than a chart pattern, and the mean reversion formula and futures example covers the family it belongs to. Among the technical analysis tools and indicators you can actually test, the z-score is one of the few that already comes with a statistical meaning attached.
How do you calculate a z-score on price and on a spread?
One formula covers both cases: subtract the rolling mean from the current value and divide by the rolling standard deviation. Standard deviation is a measure of how far values in a window typically sit from their average; a rolling value is one recomputed on each bar over the last N bars. The standard deviation indicator page shows how the window is built.
z = (value − rolling mean) ÷ rolling standard deviation
Here value is the current price (or spread), rolling mean is the average of the last N bars, and rolling standard deviation is the typical distance of those N bars from that average. N is the lookback, which the next section covers.
On a single futures market, the value is simply the close. On a pair of markets, the value is a spread. A spread is the price of one market minus a hedge ratio times the price of a second market, where the hedge ratio is the number of units of the second market that balance one unit of the first. Pairs traders use the spread version most, because two related markets drift apart and come back together more reliably than one market returns to its own average. The order of steps is the same either way, with one extra step at the front for the spread.
Hypothetical example
Single market: the 20-bar mean of an index future is 5,000 points and the 20-bar standard deviation is 40 points. The close is 4,900. z = (4,900 − 5,000) ÷ 40 = −2.5, so a rule with a threshold of 2 would be long. Spread: market A trades at 110, market B at 50, and the hedge ratio is 2. The spread is 110 − 2 × 50 = 10. If the 60-bar mean of the spread is 7 and its standard deviation is 1.5, then z = (10 − 7) ÷ 1.5 = 2.0, so the same rule would be short the spread (short A, long two units of B).
Two practical points. Compute the mean and the standard deviation only from bars that are already closed, so the z-score on a bar uses no information from that bar's own close before you could have acted on it. And keep the hedge ratio fixed during a test window; re-estimating it on every bar turns the spread into a moving target.
What lookback and threshold should you set?
Lookback decides what counts as normal and threshold decides how rare an entry is, so test a block of neighbouring values and judge the block, not a single winning pair. A lookback is the number of bars in the rolling window. A short lookback makes the mean follow price closely, so the z-score swings back to zero quickly and entries are frequent and shallow. A long lookback holds the mean steady, so stretches last longer and entries are rarer and deeper. The threshold works the other way around: 1.5 fires often, 2.5 waits for extremes.
| Setting | Short lookback, low threshold | Long lookback, high threshold |
|---|---|---|
| Entries | Many, shallow | Few, deep |
| Time to reach z = 0 | Short, often a few bars | Long, can take many bars |
| Cost pressure | High: small moves, many round trips | Low per trade, but few trades to judge |
| Trend risk | Mean catches up, losses smaller but frequent | Mean lags, a single trend can produce a large loss |
The way to choose is a grid. Run lookbacks from about 15 to 100 bars and thresholds from 1.5 to 3.0 in steps, with commission and slippage in every run. Then look for a region where neighbouring cells behave alike. Pardo (2008) calls this a plateau and treats a single sharp peak as a sign of luck rather than a real setting. Two numbers decide whether a cell is usable: the trade count, which must be large enough to judge, and the average trade after costs, which must be well above the round-trip cost. A threshold of 2.5 on daily bars may produce only a handful of trades a year, which is too few to say anything; the same threshold on 15-minute bars may produce a few hundred, which is enough.
Why exit at the mean instead of the opposite band?
Exit at z = 0 because that is the only part of the move the model predicts; waiting for the opposite band bets on an overshoot the z-score never promised. The rubber band snaps back to rest, not past it. Sometimes it does overshoot, and the trade that waited for +2 earns more. But the z-score gave no reason to expect that, so the extra gain is luck, and the trade stays open for longer while it waits.
- Exit at the mean (z crosses 0). Banks the predicted part of the move. Shorter time in market, so less exposure to news and trend changes. More trades per year from the same data, which makes the result easier to judge.
- Exit at the opposite band (z reaches the opposite threshold). Larger winners when the overshoot happens. The trade often stalls near zero and drifts back toward the entry, so the win rate falls and the time in market rises.
A useful middle ground is to test exits at fractions of the way back, such as z = −0.5 or z = +0.5 for a long trade, and to read them as a row in the same grid. If the result improves smoothly as the exit moves toward zero and then flattens, the exit at the mean is doing its job. A time exit, which closes the trade after a fixed number of bars whatever the z-score shows, is also worth a row, because a trade that has not reverted after many bars is usually a trade the mean has walked away from.
How is a z-score different from Bollinger Bands?
The two use the same statistics, but the z-score puts them on one scale, so the same threshold means the same thing on ES, on gold and on a spread. Bollinger Bands draw a moving average with lines a set number of standard deviations above and below it, in price units. A touch of the upper band with the usual 20-bar, 2-standard-deviation setting is exactly z = +2. The difference is what you can do with the reading afterwards.
| Question | Bollinger Bands | Z-score |
|---|---|---|
| Where is it drawn? | On the price chart, in points or dollars | In a separate panel, in standard deviations |
| Does 2 mean the same on every market? | No: the band width changes with the market and the bar size | Yes: 2 is two standard deviations everywhere |
| Can you compare two markets or a spread on one axis? | Only by eye | Yes, directly |
| Can you test 1.5 and 2.5 at once? | Yes, by drawing more bands | Yes, by moving a horizontal line |
| Usual exit | Middle band | z = 0, which is the same line |
For a single market tested on its own, the choice is cosmetic. For a portfolio of mean reversion rules, or for a spread, the z-score is the practical form, because one set of thresholds and one validation standard can be applied to every instrument. It also makes the grid in the previous section portable: a plateau found at a threshold of 2.0 to 2.5 on one market can be checked at the same values on another, which is not possible when the band is measured in points.
What happens to z-score entries in a trending market?
In a steady trend the z-score stays beyond the threshold for bar after bar, the mean moves away from each entry, and every new fade loses, so the rule needs a trend filter or a hard stop tested alongside it. The rubber band is now being pulled by a hand that keeps walking. It stays stretched, and the rest point itself moves. A long entry at z = −2.2 is followed by lower prices; the z-score may barely change because the mean falls too, but the price has moved against the position.
This is the mirror image of breakout trading. A Donchian channel breakout rule buys exactly the new high that the z-score sells, and an opening range breakout with its range, entry and stop parameters does the same inside the session. Neither family is right everywhere; the question is which regime the market is in when the signal fires. Three defences are commonly tested, and each one is a row in the grid, not an afterthought:
- A trend filter. Only take long fades when a longer-term measure, such as a slow moving average or an efficiency ratio, says the market is not in a strong downtrend, and the reverse for shorts. This removes the worst entries at the cost of some good ones.
- A hard stop in z units or in price. Close a long if the z-score reaches −3.5, or if the price falls a set multiple of the recent range below the entry. Kaminski and Lo (2014) show that a stop helps when returns trend and hurts when they revert, which is exactly the split a z-score trader faces, so the stop level needs its own test rather than a default.
- A time exit. Close any trade that has not returned to the mean after a set number of bars. A fade that has waited through a whole lookback window is usually a fade the mean has left behind.
What does an ES futures backtest show?
Our ES daily-bar run did not test a z-score rule directly; it used a HalfTrend rule as a stand-in, so read it for what a single kept candidate's drawdown looks like, not for how a z-score performs. HalfTrend is a trend-following indicator built from standard components, which makes it the opposite camp from the fading rule in this article, and that is useful here: it shows how a candidate that looks acceptable in its summary still spends long stretches under water. The run used ES daily bars from 2019-01-02 to 2025-06-30, long and short, one contract, with $20 commission and $25 slippage charged on every trade. 1,024 candidates went in and this one came out, kept for its return measured against its drawdown.
Source: AlphaPrime product engine (CPU), run 2026-10-31. ES daily bars, 2019-01-02 to 2025-06-30, long and short, 1 contract, $20 commission and $25 slippage per trade.
| Number | Result |
|---|---|
| Net profit (closed trades) | $80,597.5 |
| Max drawdown | $62,805 |
| Trades | 37 |
| Win rate | 48.65% |
| Profit factor | 1.979 |
| Average trade | $2,178.31 |
| Time in market | 86.96% |
Picking the kept candidate after the fact flatters it. The one survivor of 1,024 tries carries a selection bonus that no single candidate chosen in advance would have, which is the effect Bailey, Borwein, López de Prado and Zhu (2014) describe for any search that keeps the best backtest. Nothing here says the HalfTrend rule earned this money or that a reader can expect it. What the box does show is the shape of the problem. A net profit of $80,597.5 sits next to a max drawdown of $62,805, so the worst peak-to-trough fall is close to the whole gain. Thirty-seven trades over about six and a half years, with a time in market of 86.96%, means each position was held for weeks or months, and the equity curve spends long periods below its previous high while the position waits.

This is the same reading a z-score rule needs. A fade strategy with a tight exit at the mean has many small trades and, in a trend, a run of small losses that add up to one long drawdown. A trend rule like this one has few trades and deep drawdowns between them. In both cases the summary line hides the length of the hole. The drawdown and periodic performance panels of the Performance Report in AlphaPrime (Valynox) put that length in front of you month by month, which is where the decision about a trend filter or a stop is actually made.

Your next step is a grid, not a single run. Build the z-score on your own ES or TAIEX futures bars with a 20-bar lookback and a threshold of 2.0, exit at z = 0, with commission and slippage in. Then run lookbacks of 15, 30, 50 and 100 and thresholds of 1.5, 2.0 and 2.5, write down the trade count and the average trade after costs for each cell, and mark the cells where neighbours agree. Rerun the best block with a slow trend filter and with a stop at z = −3.5, and compare the longest drawdown in bars, not the net profit, before and after.
Frequently asked questions
What is a good z-score threshold for trading?
There is no single good value. A threshold of 2 is the common starting point because it marks a two-standard-deviation stretch, but the right value depends on the market, the bar size and the lookback. Test thresholds from 1.5 to 3.0 with costs included, count the trades each one produces, and choose from the middle of a region where neighbouring values behave alike rather than from the single best cell.
How do you calculate the z-score of a pairs trading spread?
First build the spread: the price of market A minus the hedge ratio times the price of market B, where the hedge ratio is the number of units of B that balance one unit of A. Then compute the rolling mean and rolling standard deviation of that spread over the last N bars. The z-score is the current spread minus the rolling mean, divided by the rolling standard deviation. Keep the hedge ratio fixed inside a test window so the spread does not shift under the rule.
Is a z-score the same as Bollinger Bands?
They use the same two statistics, a moving average and a standard deviation. Bollinger Bands draw them on the price chart in price units, while the z-score divides by the standard deviation so the reading is in standard deviation units. A touch of the upper 2-standard-deviation band is the same event as z = +2. The z-score is easier to compare across markets, spreads and bar sizes because its scale does not change.
Does z-score trading work in a trending market?
A plain z-score fade struggles in a steady trend. The reading stays beyond the threshold for many bars while the mean moves away from the entry, so each fade closes at a worse price than it opened. Traders who use z-scores on trending markets test a trend filter that blocks fades against the dominant direction, a stop in z units or price, and a time exit, and they judge the strategy on its longest drawdown rather than its net profit.
References
- Bailey, D. H., Borwein, J., López de Prado, M., & Zhu, Q. J. (2014). Pseudo-Mathematics and Financial Charlatanism: The Effects of Backtest Overfitting on Out-of-Sample Performance. Notices of the American Mathematical Society, 61(5), 458–471.
- Pardo, R. (2008). The Evaluation and Optimization of Trading Strategies (2nd ed.). John Wiley & Sons.
- Kaminski, K. M., & Lo, A. W. (2014). When Do Stop-Loss Rules Stop Losses? Journal of Financial Markets, 18, 234–254.

