Z-Score normalizes the distance between price and its rolling mean by the rolling standard deviation. Values are dimensionless and comparable across symbols and timeframes.
Formula
mean = SMA(close, period)
sd = stddev(close, period)
z = (close - mean) / sdParams
period- window for the mean and stddev. Required.
Output
Single column named after your indicator (e.g. zscore).
Common thresholds
| |z| value | Meaning | |---|---| | > 1 | Mildly extended | | > 2 | Statistically rare (~5% tail) | | > 3 | Very rare (~0.3% tail) |
These are based on a normal distribution. Real returns have fatter tails - extreme readings happen more often than the normal would suggest.
Usage
- Mean reversion: fade
z > 2andz < -2back toward zero. - Trend filter: skip trades when
|z| < 0.5(price is uneventfully near the mean). - Cross-symbol portfolio rules: rank multiple symbols by current Z-Score and trade the most extreme.
Pitfalls
The mean and stddev are based on the symbol's recent history - they shift over time. A "Z = 3" reading during a calm period can be very different from a "Z = 3" reading during a panic. Combine with an absolute volatility filter for portability.
