The ta.bb function in Pine Script v5 calculates the complete Bollinger Bands in one call — middle, upper and lower band — without you having to add and subtract standard deviations by hand. The most common mistake is treating a band touch as an automatic reversal signal, when in practice the bands measure volatility, not direction. Here you get the correct syntax, what each returned value means, the two opposite readings (reversal vs. breakout) and a ready-to-paste indicator for TradingView. Trading is a high-risk activity; use this as a study tool, not as a promise of profit.
Reading the bands is easy; executing with discipline is what separates those who survive. See how to turn signals into automated execution, and always test on a demo account.
See the bot automation guide →The function syntax
In Pine Script v5, this is the signature:
It takes three arguments and returns three values at once (a tuple):
source — the price series (almost always close).
length — the period of the average and of the standard deviation (classic default: 20).
mult — the standard deviation multiplier (default: 2.0).
middle — the middle band, which is simply an SMA of length periods.
upper — the upper band: middle + mult * stdev.
lower — the lower band: middle - mult * stdev.
The two opposite readings
There are two classic — and contradictory — strategies built around the bands. Knowing which one you are using avoids confusion:
Mean reversion: in a sideways market, price tends to return to the middle band. A touch of the lower band becomes a buy candidate; a touch of the upper band, a sell candidate.
Breakout: in a trending market, closing outside the band indicates strength, not exhaustion. Here, breaking the upper band is a signal of bullish continuation.
The same band produces opposite signals depending on the context. That is why Bollinger Bands alone are not enough — you need a trend filter.
Complete indicator (ready to paste)
Paste this code into TradingView’s Pine Editor (v5). It plots the three bands, fills the area between them and marks touches of the outer bands:
Common mistakes
Trading every touch as a reversal: in a strong trend, price “walks the band” for dozens of candles. A touch is not an order.
Ignoring the context: the same band calls for reversal in a sideways market and continuation in a trend. Decide which one first.
Confusing the squeeze with direction: a tight band warns that volatility is about to increase, not which way it will go.
Forgetting that the middle band is an SMA: the middle band is just a simple moving average — treat it as such.
FAQ
Does ta.bb exist in Pine v4?
The built-in function that returns the three bands belongs to v5. Before that, it was common to use ta.sma plus ta.stdev manually. Migrate to v5.
What is the difference from ta.bbw?ta.bbw returns only the band width, useful for measuring the squeeze. ta.bb returns the three complete lines.
Can the signals be automated?
Yes: alertcondition creates alerts that can fire webhooks, and a Python script can execute the order — always tested on a demo account first.
Do Bollinger Bands work for binary options?
They can help identify exhaustion in a sideways market, but on short expiries noise is deceptive. Use them as a context filter, never as a standalone trigger.
Disclaimer: binary options and trading in general are very high-risk activities and most retail traders lose money. This content is educational and technical; it does not constitute an investment recommendation, an offer or financial advice. Indicators do not predict the future and past results do not guarantee future results. Always test on a demo account before risking real capital, and never invest more than you can afford to lose.
