VolatilityPine Script v6

ta.bb()Bollinger Bands

Returns an SMA basis and bands mult standard deviations above and below it. Two is a common multiplier, but the function uses the value supplied by the caller.

TradingView language reference

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

Study band touches in context; a touch alone is not an overbought or oversold signal

Detect volatility squeezes for breakout trading

Use band width for volatility measurement

Combine with RSI for confluence signals

Related Functions

Frequently Asked Questions

ta.bb() returns three series: the middle band (SMA of the source), upper band (middle + mult × standard deviation), and lower band (middle − mult × standard deviation).

Traders often watch touches or closes outside the bands, narrowing bands (squeeze) before expansions, and mean reversion versus trend continuation setups. Bands are not guaranteed oversold/overbought signals; context and risk management matter.

mult scales the distance of the upper and lower bands from the middle band in units of standard deviation. Higher mult widens the channels; lower mult tightens them.

Generate ta.bb() Code with AI

Draft Pine Script using ta.bb() with Pineify's AI Coding Agent, then review the arguments and test the result on your chart. Usage depends on your plan and available credits.