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.
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.