TD

SMA Distance Bands & Dots

How far the price is from its long-term average, measured against how far it usually strays: statistically stretched highs and lows.

Two indicators and a screener share one calculation. SMA Distance Bands draws the distance from the 252-day average in its own pane, framed by ±σ bands of that same distance. SMA Distance Dots puts the extremes straight onto the price chart as dots. The SMA Distance Screener finds stretched names across a watchlist.

SMA Distance Bands

What it shows

SMA Distance Bands on a daily chart: the distance from the 252-day average with its ±2σ bands; the line is muted inside the bands and drawn in full colour outside them.
SMA Distance Bands on a daily chart: the distance from the 252-day average with its ±2σ bands; the line is muted inside the bands and drawn in full colour outside them. Click to enlarge.
ElementMeaning
Distance lineDistance from the SMA in percent. Green above the average, red below. Muted inside the bands, full colour outside them — the extremes are what stands out.
Upper and lower bands±Sigma × the standard deviation of the distance. Named at the right edge with their values, e.g. +2σ 38.5%.
Grey fillThe normal range between the bands.
Zero lineThe price is exactly at its average.
Background tintGreen while the line is above the upper band, red while it is below the lower band.

How to read it

SMA Distance Bands on a second daily chart: a stock that spends most of its time above its average, with the extremes standing out in full colour.
SMA Distance Bands on a second daily chart: a stock that spends most of its time above its average, with the extremes standing out in full colour. Click to enlarge.

Settings

SMA Length default: 252

Length of the simple moving average the distance is measured from; 252 trading days is one year.

StDev Length default: 504

Look-back of the standard deviation of the distance, about two years of daily bars. Shorter on a younger listing: the bars available, from 60.

Sigma default: 2.0

Band width in standard deviations.

Use Daily Calculation On All Timeframes default: on

Calculates everything on daily data whatever the chart timeframe, so weekly and intraday charts show the daily model. Off: calculated on the chart timeframe.

Highlight Extreme Zones default: on

Background tint while the line is outside the bands.

Alerts at bar close default: on

Alert conditions are confirmed at the bar close.

Fixed valueFixed at
Line inside the bandsline colour at 60% transparency
Line outside the bandsfull colour
Line namesdistance and both bands with their current values, at the right edge

Alerts

Open Create alert → Condition: [Finaspex] SMA Distance Bands and pick a condition.

AlertFires when
Above Upper Bandthe distance is above the upper band
Below Lower Bandthe distance is below the lower band
Cross Above Zerothe distance crosses above zero
Cross Below Zerothe distance crosses below zero
Re-entry From Abovethe distance moves back inside the bands from above
Re-entry From Belowthe distance moves back inside the bands from below

SMA Distance Dots

What it shows

SMA Distance Dots on a daily chart: green dots above the bars at stretched peaks, red dots below the bars at stretched troughs.
SMA Distance Dots on a daily chart: green dots above the bars at stretched peaks, red dots below the bars at stretched troughs. Click to enlarge.

The same calculation as SMA Distance Bands, shown directly on the price chart with no pane and no lines. A green dot marks a bar whose distance is above the upper band (a stretched peak), a red dot a bar below the lower band (a stretched trough). Runs of dots show how long an extreme lasted; the first bar without a dot after a run is the re-entry.

SMA Distance Dots on a weekly chart: the dots come from the daily calculation, so they mean the same thing as on the daily chart.
SMA Distance Dots on a weekly chart: the dots come from the daily calculation, so they mean the same thing as on the daily chart. Click to enlarge.

Settings

SMA Length default: 252

SMA the distance is measured from.

StDev Length default: 365

Look-back for the standard deviation of the distance.

Sigma default: 2.0

A dot prints when the distance is beyond ±Sigma · σ.

Use Daily Calculation On All Timeframes default: on

SMA and σ are calculated on daily data whatever the chart timeframe.

Alerts at bar close default: on

Dots and alerts appear on confirmed bars, so a dot never disappears once printed.

Show dots on price chart default: on

Master switch for the dots.

Dot offset (bars) default: 0

Shifts the dots left (−) or right (+) by N bars.

Green dot color default: green

Peak: price far above the SMA.

Red dot color default: red

Trough: price far below the SMA.

Dot opacity default: 70

100 = solid, 0 = invisible.

Dot placement default: Above/Below bar

Above/Below bar: green over the high, red under the low. Below/Above bar: the reverse. At close: both dots sit on the closing price.

Dot size default: Small

Tiny, Small, Normal, Large or Huge.

Why the Style tab entries are locked: TradingView needs a fixed size and position for every dot series, so the script holds one internal copy per colour, placement and size and switches between them. Set colour, size and placement in the Inputs tab.

Why the default StDev Length differs from the bands (365 against 504): the dots are tuned to mark the clearest extremes on the price chart. To make the dots land exactly where SMA Distance Bands leaves its band, give both indicators the same SMA Length, StDev Length and Sigma.

Alerts

AlertFires when
Green dot (peak)the distance closes above the upper band
Red dot (trough)the distance closes below the lower band
Back inside from abovethe distance crosses back down into the band
Back inside from belowthe distance crosses back up into the band

SMA Distance Screener

Companion of the SMA Distance Bands indicator. The screener finds the candidates across a watchlist; open each match with the indicator to see the full picture.

[Finaspex] SMA Distance Screener runs the same distance-and-band calculation in TradingView’s Pine Screener and returns Match = 1 for symbols stretched below their long-term average or just recovering from that state.

  1. Add the screener to your Favorites in the Pine Editor (the Pine Screener lists favourite indicators).
  2. Open the Pine Screener, choose a watchlist (for example the S&P 500) and select the script.
  3. Set the period to 1D.
  4. Add the filter Match = 1 and click Scan. Sort Sigma Distance ascending to see the most stretched names first.
  5. Run it after the close, or turn on Evaluate Last Closed Bar when scanning during the session.

Match conditions

ConditionTrue when
Below Lower Banddistance < lower band
Re-entry From Belowthe distance crossed up through the lower band within the last Re-entry Lookback bars

Settings

SMA Length (days) default: 252

Up to 450, so the calculation fits the screener’s 500-bar window.

StDev Length (days) default: 240

Shortened automatically so SMA + StDev fit inside the 500 bars.

Sigma default: 2.0

Band width in standard deviations.

Below Lower Band default: on

Include stocks currently below the lower band.

Re-entry From Below default: on

Include stocks that just crossed back above the lower band.

Re-entry Lookback (bars) default: 1

1 = a cross on the current bar; 3–5 if you scan occasionally.

Evaluate Last Closed Bar default: off

Ignores the still-forming bar and uses the previous completed one.

Columns

ColumnMeaning
Match1 = signal, 0 = none
Distance %Current distance from the SMA
Lower Band / Upper BandCurrent band levels in %
Sigma DistanceDistance in standard deviations, e.g. −2.4
Below Lower1 if the first condition is true
Re-entry From Below1 if the second condition is true
StDev UsedThe standard-deviation window actually applied

Why the screener uses a one-year σ window: the Pine Screener calculates the last 500 bars, and the SMA (252) plus the standard deviation must fit inside them. The window is set to fit automatically: StDev used = max(10, min(StDev Length, 495 − SMA Length − Re-entry Lookback)). The distance itself is identical to the chart indicator; the bands follow the last year instead of two. Deeply stretched names match on both; near −2σ the two can differ. To pre-filter, scan with Sigma 1.7–1.8 and confirm each candidate on the chart; for an exact match, set the chart indicator’s StDev Length to the value in StDev Used.

The Pine Screener does not send alerts. Use it to find the candidates, then set the alert on the SMA Distance Bands indicator on a chart, one symbol at a time.

Methodology

distance % = (close − SMA(close, SMA Length)) ÷ close × 100
σ = stdev(distance %, StDev Length)
upper band = +Sigma × σ    lower band = −Sigma × σ
green dot: distance % > upper band    red dot: distance % < lower band

With Use Daily Calculation On All Timeframes on, the distance and σ are requested from daily data, so weekly and intraday charts show the daily model. With it off, they are calculated on the chart’s own bars.

Why the distance is divided by the close: it expresses the gap as a share of today’s price, which keeps the upside readable — even a parabolic rally stays below +100%. The figure therefore differs slightly from “percent above the average” (close ÷ SMA − 1) quoted elsewhere; the bands are built from the same series, so the comparison between line and bands is exact.

Why the bands are centred on zero: zero is the average itself, so the bands answer “how far from the average is unusual for this stock?”. A stock in a long uptrend spends most of its time above zero and reaches the upper band more often than the lower one — which is part of the reading.

Scope and design choices

History
The distance line needs SMA Length bars (252 daily bars, one year). The σ window is StDev Length; on a younger listing it shrinks to the bars available, and the bands and dots appear after 60 bars of distance history. The band labels then show the window used, for example +2σ 45.3% · 320 bars.
Daily model on every timeframe
By default the calculation is daily on every chart, so a weekly chart shows the daily reading at the end of each week. Turn the setting off to build the model from the chart’s own bars.
Stretched is not the same as reversing
A stock can stay beyond its band for weeks in a strong trend. The re-entry alerts mark the moment the extreme eases; confirm the turn with the price structure, for example in Trend Leaders or Stage Analysis.
Screener and chart
The screener uses a one-year σ window to fit the Pine Screener’s 500-bar limit and the chart timeframe of the scan; run it on 1D, where it matches the daily model of the indicator.

Works well with