Indicator · Pine Script v5 · On the chart

Z-Score Highlighter

by ryangaraygay

Calculates the Z-score of closing prices over a specified moving average period and standard deviation length.

View on GitHub

GitHub stars2on the repository
Pine versionv5runs as is
Lines of code30
Settings3inputs
LicenceMIT
Last update1 year ago10 Apr 2025

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

30 lines of Pine Script v5 from z-score-highlighter.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

z-score-highlighter.pine
//@version=5
indicator("Z-Score Highlighter", overlay=true)

// Function to calculate the Z-score
zscore(src, length) =>
    mean = ta.sma(src, length)
    stdev = ta.stdev(src, length)
    (src - mean) / stdev

// Input parameters
length = input(20, title="Z-Score Length")
threshold = input(2, title="Z-Score Threshold")

// Calculate the Z-score of the closing price
z = zscore(close, length)

// Highlight bars where the Z-score is above the threshold
highlightCondition = z > threshold
highlightConditionB = z < -threshold


string my_session = input.session("0830-1500", title='NYSession')
timeinrange(res, sess) => not na(time(res, sess)) ? true : false
in_session = timeinrange(timeframe.period, my_session)

// Plot a circle at the high price when the condition is met
plotshape(series=highlightCondition and in_session, location=location.abovebar, color=color.blue, style=shape.xcross, size=size.tiny, title="Z-Score High")
plotshape(series=highlightConditionB and in_session, location=location.belowbar, color=color.orange, style=shape.xcross, size=size.tiny, title="Z-Score Low")

alertcondition(barstate.isconfirmed and in_session and (highlightCondition or highlightConditionB), "Outlier take profit alert", "An outlier has been detected. Considering take profit or tightening.")

Overview

Z-Score Highlighter identifies potential statistical outliers by checking if the Z-score breaches positive or negative threshold levels during a user-configurable trading session. Outliers within session hours are marked directly on the main price chart using cross shapes above or below price bars.

Details

Published by

ryangaraygay on GitHub

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Oscillators & momentum, Volatility & bands, Sessions & time

Markets

Any symbol

Timeframes

M1-M5, M15-H1

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
Z-Score Lengthint20length
Z-Score Thresholdint2threshold
NYSessionsession0830-1500my_session
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

This indicator plots an average daily range from hourly high-low ranges stored for each hour across a selectable number of days. It highlights time sessions on the price chart and can show a timeline and the current range box. Optional filters use a volatility

Indicator v5 Volatility & bandsSessions & time Repaints
Updated 5 months ago · None stated GitHub repository of Average Daily Range with Time Session Highlighter

Gold Dominator Pro

by thanvish21
1 stars

Gold Dominator Pro is a multi-indicator overlay designed primarily for gold trading. It combines higher-timeframe exponential moving averages with momentum oscillators like RSI, MACD, and StochRSI, alongside volatility tools such as ATR, Bollinger Bands, and A

Indicator v5 TrendOscillators & momentum
Updated 2 months ago · None stated GitHub repository of Gold Dominator Pro
1 stars

Overlay indicator for XAUUSD gold that draws predicted support and resistance levels at 08:00 and 19:00 SGT on the price chart along with buy and sell take-profit levels spaced by ATR multiples. It generates RSI reversal signals as triangles when the indicator

Indicator v5 Support & resistanceOscillators & momentum
Updated 2 months ago · None stated GitHub repository of Predicted Signals + RSI trigger

The Momentum Setup is a multi-indicator visual tool designed for trend and momentum analysis directly on the price chart. It combines Relative Strength Index (RSI), Money Flow Index (MFI), Commodity Channel Index (CCI), Supertrend, and a 250-bar percentage cha

Indicator v5 Oscillators & momentumTrend
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup - Ankush Bajaj Momentum Investing Setup

This indicator plots trade entry and exit signals on the price chart by combining Bollinger Bands with optional filter conditions. It calculates standard Bollinger Bands along with RSI, Aroon, and moving average filters. Reversal signals trigger when price bre

Indicator v4 Volatility & bandsOscillators & momentum
Updated 2 months ago · None stated GitHub repository of Bollinger Bands Winner IND [Alorse]

More indicators

Trade Your Charts With a Regulated Broker

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

Compare brokers