Library · Pine Script v6 · Library

Bands

by heyphat

This library exports a Band type and functions that build a simple-moving-average basis with upper and lower envelopes from standard deviation.

View on GitHub

GitHub stars26on the repository
Pine versionv6current
Lines of code35
Settings0inputs
LicenceAGPL-3.0
Last update2 months ago21 Aug 2026

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 library, select all of the template text and paste. Press Save and give it a name.
  4. 4Publish or import itA library draws nothing. Publish it from the editor, then import its functions in your own scripts.

Source Code

35 lines of Pine Script v6 from examples/pine-libs/alice/bands/1.pine, published under AGPL-3.0. Keep the author's credit and licence lines when you reuse it.

1.pine
//@version=6
library("Bands")

// A library may import OTHER libraries (resolved from the same on-disk tree).
import alice/mathx/1 as mx

// An exported user-defined type (UDT).
export type Band
    float basis = 0.0
    float upper = 0.0
    float lower = 0.0

// An exported enum.
export enum Side
    Above
    Below
    Inside

// An exported method — callable via receiver dispatch: `b.width()`.
export method width(Band self) =>
    self.upper - self.lower

// An exported function returning a UDT instance.
export compute(float src, int len, float mult) =>
    basis = ta.sma(src, len)
    dev = mult * ta.stdev(src, len)
    Band.new(basis, basis + dev, basis - dev)

// Takes an imported-UDT parameter and returns an enum member.
export classify(float src, Band bnd) =>
    src > bnd.upper ? Side.Above : src < bnd.lower ? Side.Below : Side.Inside

// Uses the TRANSITIVELY-imported MathX library.
export zWidth(float src, int len, float mult) =>
    math.abs(mx.zscore(src, len)) * mult

Overview

Bands classifies a source as above, below, or inside those envelopes, measures band width, and scales an imported z-score by a multiplier. Callers supply source, length, and multiplier. It draws nothing and has no inputs of its own.

Details

Published by

heyphat on GitHub

Type

Library, Pine Script v6

Draws

Library (no plots)

Category

Volatility & bands, Moving averages

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.

Topics

backtestingindicatorspine-scriptpinescripttechnical-analysistradingtradingviewtypescript

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

FunctionArrayMovingAverage

by ricardosantos79
261 stars

This Pine Script v5 library provides an exported function to calculate moving averages directly over float arrays. Users can supply a sample array, set the smoothing length, choose whether to omit initial values prior to reaching the lookback window, and speci

Library v5 Moving averages
Updated 4 years ago · None stated GitHub repository of FunctionArrayMovingAverage
29 stars

This library exports one function, custom_ma, which returns a 14-period exponential moving average of a supplied source series. It declares no inputs, so the length stays fixed at 14 and the caller chooses the series. It plots nothing and does not generate ent

Library v5 Moving averages
Updated 11 months ago · Custom licence GitHub repository of Exponential Trend [AlgoAlpha]

Public

by wanjo-tech
6 stars

This Pine Script v5 library walks historical price, volume, time and amount series until a requested number of hours is covered, stopping at 4999 bars. TimeAligned returns the bar count, net and absolute price changes, net and absolute log-price changes, volum

Library v5 Volatility & bandsVolume
Updated 2 years ago · None stated GitHub repository of Public
318 stars

Calculates and plots moving averages on selected VIX volatility terms (VIX9D, VIX, VIX3M, or VIX6M) in a separate pane. The script computes user-defined short and long moving averages using EMA or SMA. It shades the background red when the short-term moving av

Indicator v5 Volatility & bandsMoving averages
Updated 2 months ago · MIT GitHub repository of [TVT] VIX Short Term Danger

MACD-V

by harryguiacorn
219 stars

MACD-V is a volatility-normalized momentum indicator based on research by Alex Spiroglou. It calculates the standard MACD histogram and normalizes it by dividing by the Average True Range (ATR). Plotted in a separate pane as a colored histogram, it includes us

Indicator v5 Oscillators & momentumVolatility & bands
Updated 1 year ago · None stated GitHub repository of MACD-V

MultiIndicator

by capissimo
114 stars

MultiIndicator combines multiple technical indicators into a single separate pane to save chart space. It calculates and displays market regime detection based on ordinary least squares regression, a Holt exponential smoothing crossover, normalized RSI, ADX, a

Indicator v4 Oscillators & momentumTrend
Updated 1 year ago · None stated GitHub repository of MultiIndicator

More libraries

Trade Your Charts With a Regulated Broker

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

Compare brokers