VolatilityPine Script v6

ta.bb()

Bollinger Bands

Bollinger Bands. A Bollinger Band is a technical analysis tool defined by a set of lines plotted two standard deviations (positively and negatively) away from a simple moving average (SMA) of the security's price.

Syntax

Syntax
ta.bb(series, length, mult) → [series float, series float, series float]

Arguments

ParameterTypeDescription
seriesseries int/floatSource series (typically price).
lengthseries intLength of the moving average and standard deviation window.
multsimple int/floatStandard deviation factor.

Returns

Bollinger Bands.

Remarks

na values in the source series are ignored; the function calculates on the length quantity of non-na values.

Code Examples

Pine Script v6 Example
//@version=6
indicator("ta.bb")

[middle, upper, lower] = ta.bb(close, 5, 4)
plot(middle, color=color.yellow)
plot(upper, color=color.yellow)
plot(lower, color=color.yellow)

// the same on pine
f_bb(src, length, mult) =>
    float basis = ta.sma(src, length)
    float dev = mult * ta.stdev(src, length)
    [basis, basis + dev, basis - dev]

[pineMiddle, pineUpper, pineLower] = f_bb(close, 5, 4)

plot(pineMiddle)
plot(pineUpper)
plot(pineLower)

Trading Applications

Identify overbought/oversold conditions when price touches bands

Detect volatility squeezes for breakout trading

Use band width for volatility measurement

Combine with RSI for confluence signals

Related Functions

Frequently Asked Questions

Generate ta.bb() Code with AI

Skip the manual coding. Use Pineify's AI Coding Agent to generate Pine Script code using ta.bb() and other built-in functions instantly.