OPEN-SOURCE SCRIPT
Rolling Z-Score

A simple statistical indicator that measures how far the current price is from its recent average, expressed in standard deviations (a "z-score"). It helps visualize when price is unusually stretched relative to its own recent behavior.
What it does
This indicator calculates a rolling z-score of price over a user-defined lookback window. The z-score expresses the current value as the number of standard deviations away from its rolling mean:
z = (price − rolling mean) / rolling standard deviation
A reading of 0 means price is exactly at its recent average. +2 means two standard deviations above average; −2 means two below. Values reset continuously as the rolling window moves.
How to read it
Near 0 → price is close to its recent mean
Above +2 → price is statistically stretched to the upside
Below −2 → price is statistically stretched to the downside
The dashed lines mark the ±2 reference levels; the center line marks the mean.
Inputs
Window length: the lookback period for the mean and standard deviation (default 20)
Source: the price series used (default close)
Important notes
A high or low z-score is not a buy or sell signal on its own. In a trending market, price can stay stretched (high or low z-score) for extended periods — an extreme reading can keep getting more extreme. This tool measures statistical deviation; it does not predict reversals. Use it as one input within a broader, tested framework, not as a standalone signal.
What it does
This indicator calculates a rolling z-score of price over a user-defined lookback window. The z-score expresses the current value as the number of standard deviations away from its rolling mean:
z = (price − rolling mean) / rolling standard deviation
A reading of 0 means price is exactly at its recent average. +2 means two standard deviations above average; −2 means two below. Values reset continuously as the rolling window moves.
How to read it
Near 0 → price is close to its recent mean
Above +2 → price is statistically stretched to the upside
Below −2 → price is statistically stretched to the downside
The dashed lines mark the ±2 reference levels; the center line marks the mean.
Inputs
Window length: the lookback period for the mean and standard deviation (default 20)
Source: the price series used (default close)
Important notes
A high or low z-score is not a buy or sell signal on its own. In a trending market, price can stay stretched (high or low z-score) for extended periods — an extreme reading can keep getting more extreme. This tool measures statistical deviation; it does not predict reversals. Use it as one input within a broader, tested framework, not as a standalone signal.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.