Indicator · Pine Script v6 · On the chart

Bollinger Bands

by piecioshka

This indicator plots standard Bollinger Bands directly on the price chart using a simple moving average and standard deviation bounds.

View on GitHub

GitHub stars2on the repository
Pine versionv6current
Lines of code48
Settings5inputs
LicenceMIT
Last update12 days ago18 Oct 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 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

48 lines of Pine Script v6 from indicators/overlays/bollinger-bands/bollinger-bands.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

bollinger-bands.pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Piotr Kowalski "piecioshka"
// Docs (EN): https://github.com/piecioshka/tradingview-pine-scripts/blob/main/indicators/overlays/bollinger-bands/bollinger-bands.md
// Docs (PL): https://github.com/piecioshka/tradingview-pine-scripts/blob/main/indicators/overlays/bollinger-bands/bollinger-bands.pl.md

// @version=6
indicator('Bollinger Bands', overlay = true, max_labels_count=500)

aColor = color.rgb(114, 48, 131)
bColor = color.rgb(240, 199, 58)

len = input.int(20, 'SMA')
mult = input.float(2.0, 'StdDev', minval=0.001, step=0.5)
showTrades = input.bool(true, 'Signal markers', tooltip='Mean-reversion signals as markers: below the candle (long) when close drops below the lower band (bet on a return to the mean), above the candle (sell) when close rises above the upper band. Shape and size in the Appearance group.')

gA = 'Appearance'
shapeName = input.string('Triangle', 'Marker shape', options=['Triangle', 'Arrow', 'Label arrow', 'Circle', 'Diamond'], group=gA, tooltip='Triangle - solid triangle.\nArrow - small thin arrow.\nLabel arrow - arrow-shaped label bubble.\nCircle / Diamond - neutral dot markers.')
sizeName  = input.string('Small', 'Marker size', options=['Tiny', 'Small', 'Normal', 'Large'], group=gA)

// Markers as labels - the shape is picked from an input, which plotshape() cannot do (its style must be a constant).
upStyle    = shapeName == 'Arrow' ? label.style_arrowup : shapeName == 'Label arrow' ? label.style_label_up : shapeName == 'Circle' ? label.style_circle : shapeName == 'Diamond' ? label.style_diamond : label.style_triangleup
downStyle  = shapeName == 'Arrow' ? label.style_arrowdown : shapeName == 'Label arrow' ? label.style_label_down : shapeName == 'Circle' ? label.style_circle : shapeName == 'Diamond' ? label.style_diamond : label.style_triangledown
markerSize = sizeName == 'Tiny' ? size.tiny : sizeName == 'Normal' ? size.normal : sizeName == 'Large' ? size.large : size.small

std = ta.stdev(close, len)
sma = ta.sma(close, len)
upper = sma + mult * std
lower = sma - mult * std

center = plot(sma, color=color.new(color.white, 30), force_overlay=true)
plotUpper = plot(upper, color=aColor, force_overlay=true)
plotLower = plot(lower, color=bColor, force_overlay=true)

fill(plotUpper, center, color = color.new(aColor, 90))
fill(center, plotLower, color = color.new(bColor, 90))

// --- Signal markers (mean reversion on the bands) ---
longTrade = ta.crossunder(close, lower)
sellTrade = ta.crossover(close, upper)

if showTrades and longTrade
    label.new(bar_index, na, '', yloc=yloc.belowbar, style=upStyle, color=color.green, size=markerSize)
if showTrades and sellTrade
    label.new(bar_index, na, '', yloc=yloc.abovebar, style=downStyle, color=color.red, size=markerSize)

// --- Alerts ---
alertcondition(longTrade, 'BB: below the lower band', 'Price closed below the lower Bollinger band (mean reversion long setup)')
alertcondition(sellTrade, 'BB: above the upper band', 'Price closed above the upper Bollinger band (mean reversion short setup)')

Overview

Bollinger Bands displays filled background channels between the center moving average and the outer bands. Optional mean-reversion signal markers appear below or above price bars when the close crosses outside the lower or upper bands. Traders can customize the moving average length, standard deviation multiplier, marker shape, and marker size.

Details

Published by

piecioshka on GitHub

Draws

On the price 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.

Topics

pinescriptpinescript-indicatorspinescript-strategiestradingtradingview

Settings

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

SettingTypeDefaultVariable
SMAint20len
StdDevfloat2.0mult
Signal markersbooltrueshowTrades
Marker shapestringTriangleshapeName
Marker sizestringSmallsizeName
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

Peak Reversal v3

by Zettt
43 stars

Peak Reversal v3 identifies potential mean-reversion points by plotting configurable Keltner Channels alongside a squeeze detector directly on the price chart. It detects momentum extremes when candles cross or trade completely outside the inner or outer chann

Indicator v6 Mean reversionVolatility & bands
Updated 1 year ago · None stated GitHub repository of Peak Reversal v3
6 stars

This indicator classifies price action into four distinct market regimes: Trend, Expansion, Compression, or Mean Reversion. It determines states using a simplified Hurst exponent estimate, ADX slope thresholds, and realized volatility measurements. Based on th

Indicator v6 TrendVolatility & bands
Updated 2 months ago · MIT GitHub repository of Capital41 Regime Matrix v3
4 stars

This indicator plots directional trade signals, ATR-based target and stop-loss boxes, and SuperSmoother reversal bands directly on the price chart. It evaluates market conditions across selectable technical strategies, displaying confidence scores alongside an

Indicator v6 Screeners & dashboardsTrend Repaints
Updated 2 days ago · None stated GitHub repository of Elton's Predictions Decision Engine

4x4 Futures Ghost Matrix

by knectardev
1 stars

This indicator generates intraday trading signals by combining dual-sigma standard deviation bands, Heikin Ashi candle vectors, and a four-bar confluence score. It triggers long and short signals during defined trading sessions using either mean-reversion boun

Indicator v5 Volatility & bandsMean reversion
Updated 9 months ago · None stated GitHub repository of 4x4 Futures Ghost Matrix

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