StdDev / Z-Score Node

The StdDev / Z-Score node measures how spread out a series has been, or how many standard deviations the current value sits from its own average. Stretch rules, the link to Bollinger Bands, and how it differs from Distance in standard deviations.

NodeBy AlgoLiftUpdated 5 min read
On this page 7How it worksZ-score or Distance in standard deviations?Example: fade a two-sigma stretchSettingsUse something else whenWhen it doesn't behaveGoing further

A 20-point drop on ES means a lot on a quiet morning and very little after a jobs report. The StdDev / Z-Score node measures a move in the series' own terms: how many standard deviations the current value sits from its recent average. Minus two is a stretch whatever kind of day it's been.

Takes
One series: an indicator, a price, a level, price action, a memory or another modifier
Gives
The z-score of the current value, or the window's standard deviation
Reach for it
A rule is about how stretched a value is, measured against its own volatility

How it works

The node looks at the last N values, the bar your rules are reading included, and gives you one of two outputs.

Z-Score, the default, is (current value − window average) ÷ window standard deviation. Zero is right on the average, +2 is two deviations above it, and the sign tells you which side you're on.

Std Dev is the standard deviation itself, in the input's own units: points for ES and NQ closes, dollars for a stock, RSI points for an RSI. It's the population kind, divided by N rather than N − 1.

If you've used Bollinger Bands, you already know this arithmetic. A 20-period z-score of the close above 2 is the same test as the close above the upper band of Bollinger Bands (20, 2): the same 20 closes, the same average, the same deviation. The z-score hands you the number instead of the line, so you can ask for 2.5, rank it, or use it on something that isn't price at all.

Two edge cases are worth knowing. A window that hasn't moved has no deviation, and the z-score there is empty rather than infinite. And because the current value is part of its own window, a z-score can only stretch so far: never more than √(N − 1). On 5 bars that's 2; on 10 bars, 3.

The input is any series the engine builds before the first bar: an indicator or one of its outputs, Current Price (read as the close of each completed bar), a price-action output, an external data source, a level (Price History, Pivot Levels, Event Day or Bands), a Distance in standard deviations, a Since or Capture, a Crossover on the Bar close clock, or another modifier. Math nodes, Constants and State Machines won't connect.

Z-score or Distance in standard deviations?

The Distance node has a Std dev unit, and the two are easy to mix up. They answer different questions.

StdDev / Z-ScoreDistance, Std dev
ReadsOne seriesA value and a reference
MeasuresThe value against its own N-bar averageThe gap between the two, against that gap's own last N values
Current PriceReads its completed closesRefused as the live price: both inputs must be completed-bar values

Wire a fast and a slow EMA into Distance and it tells you whether today's spread between them is unusual compared with recent spreads. That's a different number from this node's z-score of the close, even with the 20 SMA as the reference. If you mean "two standard deviations from the average" in the Bollinger sense, this is your node.

Example: fade a two-sigma stretch

Say you trade mean reversion on ES 5m: when a bar closes far below where price has been trading, you buy and expect a snap back toward the average.

Wire Current Price into a StdDev / Z-Score node, Period 20, Output Z-Score. Feed it into a Comparison: Less Than, Constant -2, and into a long Entry. Entries become possible once a bar closes more than two standard deviations below the average of the last 20 closes.

The exit can mirror the idea: a second Comparison, z-score Greater Than 0, into a Set Exit Condition, closes the trade once price is back at its average.

Settings

Period
Default 20
Bars in the window, from 2 to 999, the bar your rules are reading included.
Output
Default Z-Score
Z-Score, or Std Dev for the window's standard deviation in the input's units.

Use something else when

The gap between two lines, in standard deviations
Distance's Std dev unit measures how unusual the spread between a value and a reference is, compared with that spread's recent history.
Where it ranks, not how far it is
A rank ignores how far out the extreme is, which makes it calmer around big outliers.
A volatility number for stops
ATR measures how far bars actually travel, gaps between them included. The standard deviation of closes measures how spread out the closes are, which is a different question.
ATR

When it doesn't behave

My threshold of 2.5 never fires

Check the period. With the current value inside its own window, the z-score tops out at √(N − 1): 2 on 5 bars, 3 on 10. A 5-bar z-score can't reach 2.5 however far price runs. Lengthen the window or lower the bar.

It buys again and again all the way down

"Z-score below -2" is a state, and in a real selloff it can stay true for an hour. Every time a trade closes, the condition is still sitting there. Trigger on the moment instead, with a Crossover of the z-score below -2, or pair the fade with a trend filter so it stands aside when the stretch is the start of something.

It's empty on some bars

The window had no spread. A series that sits on the same value for N bars (a count, a level that hasn't changed) has a standard deviation of zero, and we leave the z-score empty rather than divide by it. A Comparison against an empty value reads false.

Going further

The z-score works on anything with a center to come back to. A z-score of RSI asks whether momentum is unusual for this market right now, not against a textbook 70. The Std Dev output makes a decent volatility regime on its own, and a Percentile Rank Modifier on top of it turns "quiet" into a threshold that holds across years.

Period and Output both sweep. Be careful with the threshold most of all: -2 is a convention, -2.37 is a fit. Pick a round number you'd have chosen before seeing the results, and let the backtest tell you whether the idea holds rather than where the best decimal is.

Or ask the copilot