Indicator · Pine Script v4 · Own pane

Z-Score BB

by amico1234· code credited to luminaryfi

Z-Score BB measures statistical deviation by comparing a short-term 22-bar sample mean against a longer-term population baseline.

View on GitHub

GitHub stars1on the repository
Pine versionv4older, still runs
Lines of code39
Settings2inputs
LicenceNone statedfile: MPL-2.0
Last update2 years ago2 Mar 2024

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

39 lines of Pine Script v4 from zscore.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

zscore.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © luminaryfi
//@version=4
study("Z-Score BB", precision=4)

n = input(title='n',defval=63)
disp = input('x̅ (21)',title='Display Z-Score from:', options=['x̅ (21)','μ (63)'])

price_sample = array.new_float(0)
for i = 0 to 21
    array.push(price_sample,close[i])

price_sample_mean = array.avg(price_sample)
price_pop_mean = sma(close,n)
price_pop_sd = stdev(close,n)
sqrt_n = sqrt(n)
price_pop_se = price_pop_sd/ sqrt_n

z = (price_sample_mean - price_pop_mean)/ price_pop_se
z_abs = abs(z) 

z_low_sample_mean = price_sample_mean - z_abs
z_high_sample_mean = price_sample_mean + z_abs

z_low_pop_mean = price_pop_mean - z_abs
z_high_pop_mean = price_pop_mean + z_abs


plot(disp=='z_high_pop_mean' or disp=='μ (63)'?z_high_pop_mean:na, title='Z-Low',color=#FF9800, transp=10, linewidth=2)
plot(disp=='z_low_pop_mean' or disp=='μ (63)'?z_low_pop_mean:na, title='Z-High', color=#ab00ad, transp=10, linewidth=2)
plot(disp=='price_pop_mean' or disp=='μ (63)'?price_pop_mean:na, title='μ (63)', color=#ff00f1, transp=15, linewidth=2)


plot(disp=='z_high_sample_mean' or disp=='x̅ (21)'?z_high_sample_mean:na, title='Z-High', color=#040af9, transp=10, linewidth=2)
//plot(disp=='z_low_sample_mean' or disp=='x̅ (21)'?z_low_sample_mean:na, title='Z-Low', color=#040af9, transp=10, linewidth=2)

plot(disp=='z_low_sample_mean' or disp=='x̅ (21)'?z_low_sample_mean:na, title='Z-Low',color=#808000, transp=10, linewidth=2)

plot(disp=='price_sample_mean' or disp=='x̅ (21)'?price_sample_mean:na, title='x̅ (21)', color=#00adf8, transp=15, linewidth=2)

Overview

Z-Score BB computes the population standard deviation and standard error to derive absolute Z-score offset bands around the selected baseline. Users can toggle the indicator view between sample mean bounds and population mean bounds using the input options.

Details

Published by

amico1234 on GitHub

Code credit

luminaryfi, as written in the script's header

Type

Indicator, Pine Script v4

Draws

Separate pane below the chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
nint63n
Display Z-Score from:stringx̅ (21)disp
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

261 stars

This indicator calculates standardized z-scores of price data across four different lookback periods (6, 14, 26, and 100). Standardizing data subtracts the moving average from the price and divides by the standard deviation. It applies a Double Exponential Mov

Indicator v5 Mean reversionVolatility & bands
114 stars

This indicator implements a dual-direction variation of the Williams Vix Fix oscillator in a separate pane. It normalizes price data using min-max scaling to compute both upward and downward synthetic volatility metrics across two selectable calculation modes

Indicator v4 Volatility & bandsMean reversion
Updated 1 year ago · None stated GitHub repository of Combo Williams Vix Fix (Twin)
99 stars

The Mean Squared Error indicator calculates the mean of squared differences between a source series and its EMA, averaged via a rolling buffer acting as SMA. This error metric plots as a filled red area on a separate pane, while the EMA overlays as a yellow li

Indicator v6 Volatility & bandsMean reversion
Updated 4 weeks ago · Apache-2.0 GitHub repository of Mean Squared Error (MSE)

This indicator classifies market behavior into momentum, mean-reversion, noise, or mixed regimes. It fuses four statistical predictability sensors—Variance Ratio across multiple horizons, return autocorrelation, Hurst exponent approximation, and fractal effici

Indicator v6 TrendMean reversion
Updated 3 days ago · MIT GitHub repository of Predictability Regime Index [WavesUnchained]

Variance Ratio Test

by Anderson-ALGO
9 stars

This indicator calculates the Variance Ratio Test statistic to evaluate random walk behavior across multiple sampling periods. It computes log returns, base period variance over a specified lookback window, and scaled multi-period variances to determine test Z

Indicator v4 Volatility & bandsMean reversion
Updated 5 years ago · None stated GitHub repository of Variance Ratio Test

This indicator builds a channel from a Hull moving average of the source and an ATR scaled by a band multiplier, then normalizes price inside that channel into a 0 to 100 oscillator. It smooths the result with a weighted moving average and plots the line in a

Indicator v6 Mean reversionVolatility & bands
Updated 3 months ago · None stated GitHub repository of Radiant Mean Reversion Channels [Pineify]

More Volatility & bands scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers