Bollinger Bands are a moving-average envelope developed by John Bollinger. The traditional version places an upper and lower band two standard deviations above and below a 20-period simple moving average. The bands describe price relative to its recent average and dispersion. %B locates price within the envelope, while BandWidth measures its width; a band touch or squeeze alone does not specify a trade.

Bollinger Bands at a glance
Scroll horizontally to read every column.
| Component | What it measures |
|---|---|
| Middle band | The simple moving average of the chosen price source. |
| Upper and lower bands | The average plus or minus a multiple of rolling standard deviation. |
| %B | Price location relative to the lower and upper bands. |
| BandWidth | The distance between the bands relative to the middle band. |
| Squeeze | A description of relatively narrow bands; a mechanical rule must define “relatively”. |
Bollinger describes 20 periods and two standard deviations as defaults, and warns against treating band tags as standalone signals.[1] Those defaults are not recommended settings here. The indicator rules library compares the bands with RSI momentum rules and other measurable conditions.
What is the Bollinger Bands formula?
Choose a price source, window length n and positive multiplier k. This page uses closing prices, a simple moving average and population standard deviation over the same n valid observations.
Middle band M = SMA(close, n); upper band U = M + k × σ; lower band L = M − k × σ
σ = √(sum of (close − M)² across the window ÷ n)
The standard deviation σ measures dispersion around the current window's mean. Each close in that window is compared with that same mean, not with the moving-average value from the close's own bar. The denominator is n, not n − 1.
Pine Script v6's ta.bb(source, length, mult) returns the middle, upper and lower bands, using an SMA and standard deviation. Its documented equivalent calculation uses ta.stdev, whose default biased calculation divides by n.[2] “Biased” here names the variance convention; it is not an assessment of trading quality.
Changing the price source, averaging method, length or standard-deviation convention changes the bands. The moving-average guide explains why an EMA and an SMA are different calculations. Bollinger discusses exponential bands as a distinct variation requiring consistent calculations.[1]
How do you calculate %B and BandWidth?
%B = (price − lower band) ÷ (upper band − lower band)
This page expresses %B as a fraction: zero is the lower band, 0.5 is the middle and one is the upper band. A price outside the envelope can give %B below zero or above one. Expressing the same fraction on a percentage scale would multiply it by 100.
BandWidth % = (upper band − lower band) ÷ middle band × 100
The percentage form above assumes a positive middle band. Bollinger defines BandWidth as width normalised by the middle band and %B as the location within the bands.[1] Pine Script v6 describes ta.bbw as the band difference divided by the middle band, and its documented equivalent calculation multiplies that ratio by 100, matching the percentage form used here.[2]
If both bands coincide, %B divides by zero and is undefined. With a positive middle band, the corresponding BandWidth is zero. If the middle band itself is zero, relative BandWidth is undefined. A script must handle these cases rather than replacing unavailable values with an unexplained trading signal.
Worked example: bands, %B and BandWidth
Illustrative prices and settings, not a recommendation. Use four closes, 98, 98, 102 and 102, and a multiplier of two. The short window keeps the arithmetic visible; it is not the traditional 20-period default.
- Middle: (98 + 98 + 102 + 102) ÷ 4 = 100.
- Dispersion: deviations are −2, −2, +2 and +2. Squared deviations total 4 + 4 + 4 + 4 = 16.
- Standard deviation: √(16 ÷ 4) = 2.
- Bands: upper = 100 + 2 × 2 = 104; lower = 100 − 2 × 2 = 96.
- %B at the latest close, 102: (102 − 96) ÷ (104 − 96) = 6 ÷ 8 = 0.75.
- BandWidth: (104 − 96) ÷ 100 × 100 = 8%.

The 8% is a width relative to the current middle band, not a price-return forecast. Likewise, %B = 0.75 is a location in the envelope, not a probability of a price increase.
What is a Bollinger squeeze?
A squeeze describes bands that are narrow relative to a chosen comparison. BandWidth makes the comparison measurable, but “low BandWidth” still needs a lookback and a boundary. The formula supplies neither a universal threshold nor a direction for a later move.
Illustrative definition: a narrowing event occurs when the current BandWidth is strictly below each of the previous three closed bars' BandWidth values. With previous values of 12%, 10% and 9%, a current 8% qualifies. Equality with the prior minimum does not qualify.
That example measures a new short-window low in width. A different squeeze definition might require width to remain below a specified level for several bars. These definitions produce different events, so record which one is being tested. The selected window and values are illustrations, not settings to copy.
Because the width formula contains standard deviation but no directional sign, the narrowing event does not identify an upward or downward breakout. Bollinger's rules also caution against assigning a statistical price-containment probability to the bands.[1] “Two standard deviations” does not make the envelope a confidence interval for a future price.
How do breakout and mean-reversion readings differ?
A breakout interpretation examines price moving beyond an envelope. A mean-reversion interpretation examines movement back toward an average. These are different hypotheses about the same inputs, not conclusions delivered by the indicator. Bollinger notes that price can move along a band during a trend and that a tag alone is not a signal.[1]
| Illustrative observation | Exact condition on closed bars |
|---|---|
| New close above the upper band | Previous close ≤ previous upper band; current close > current upper band. |
| Return strictly inside after a close below the lower band | Previous close < previous lower band; current lower band < current close < current upper band. |
| Still above the upper band | Current close > current upper band, without requiring a new crossing. |
The return-inside condition tests the upper boundary too. Merely crossing the lower band would also include a jump completely through the envelope to above the upper band. Leaving out that second comparison changes the event being described.
Compare each close with the bands for its own bar. Comparing all earlier prices with today's envelope rewrites the historical condition. A completed bar's high being above its final upper band also differs from observing price touch a changing band during that bar.
How do Bollinger Bands become TradingView alert conditions?
As of 25 September 2026, TradingView's Pine Script v6 reference provides ta.bb and ta.bbw; MetaTrader 5 documents Bollinger Bands as a chart indicator.[2][3] A plotted band is a calculation, not an order instruction.
For the illustrative upper-band crossing, record the feed, symbol, candle type, price source, length and multiplier. Define the evaluation time as the chart bar's closing update. Both the close and its bands can change while a realtime bar develops, so an intrabar crossing can disappear.[4]
A Pine script must expose the intended alert event, and the user must create the running TradingView alert. Match its frequency to the evaluation rule. TradingView saves the script, inputs, symbol and timeframe at creation; later changes require recreating the affected alert.[5] An indicator event alone does not specify direction, size or an exit.
Bar-close evaluation resolves the unfinished chart-bar input in this example. It does not settle confirmation of a separate higher-timeframe calculation or every other form of repainting.[4]
What must be checked between the alert and an MT5 trade?
PineConnector's Syntax reference defines the message's command, broker symbol, volume and stop or target parameters.[6] The user supplies those instructions separately from the band condition. Neither a band crossing nor a squeeze creates an order by itself.
- Condition: the specified band comparison is true at the stated time.
- Alert: the configured TradingView alert actually triggers.
- Delivery: the webhook transmits the chosen message.
- Processing: the matching PineConnector Portal → Bridge record shows the processing result.
- EA request: the EA submits an order request if the applicable checks permit it.
- Broker outcome: verify acceptance, the deal or deals, and the resulting position.
PineConnector's demo verification procedure treats message processing and broker execution as separate checks.[7] MetaQuotes distinguishes orders, deals and positions.[8] A strategy-only exit at a band is also different from an accepted broker-side stop loss.
TradingView and MetaTrader can use different feeds, quotes and timestamps, as PineConnector's price-difference FAQ explains.[9] A band price calculated on TradingView is not proof that the broker will accept the same number as a stop.
Which Bollinger Bands mistakes change the meaning?
- Reading dispersion as direction. BandWidth removes directional information; %B describes location, not an expected return.
- Mixing standard-deviation conventions. Dividing squared deviations by n − 1 instead of n widens the bands for the same nonconstant window.
- Ignoring moving boundaries. A price cross compares each price with its contemporaneous band, not a frozen line copied from another bar.
- Calling every tag a reversal. Bollinger explicitly distinguishes tags from standalone signals.[1]
- Fitting every parameter to the same history. Length, multiplier, squeeze definition and exit choices add opportunities for overfitting. TradingView describes testing an unchanged configuration on data outside the tuning sample.[10]
Frequently asked questions
What is the Bollinger Bands formula?
Traditional Bollinger Bands use a 20-period simple moving average with upper and lower bands two standard deviations away. More generally, the bands are SMA plus or minus k standard deviations over the chosen window. This page uses population standard deviation, dividing squared deviations by n. The conventional settings are defaults, not universally suitable trading parameters.
What does a Bollinger squeeze mean?
A Bollinger squeeze means the bands are narrow relative to a specified comparison, often expressed through BandWidth. A mechanical squeeze rule needs an exact threshold or historical comparison, lookback and evaluation time. Narrow bands describe recent dispersion; they do not identify the direction of a later price move or establish an entry by themselves.
Can Bollinger %B be above one or below zero?
Yes. Using the fractional convention, %B = (price − lower band) ÷ (upper band − lower band). Price above the upper band gives a value above one, while price below the lower band gives a negative value. The measure is undefined when the two bands coincide. %B is a location measure, not a probability.
What does ta.bb return in Pine Script?
Pine Script v6's ta.bb(source, length, mult) returns three values in order: the middle band, upper band and lower band. The calculation uses an SMA and standard deviation. A script must separately define comparisons, confirmation and alert events. Calling the function does not create a running TradingView alert or submit an MT5 order.
Reviewed 25 September 2026. Facts were checked against the linked sources on that date. Nothing in this article was tested on a trading account and no code was compiled.
Related reading
- Indicator rules library
- SMA, EMA and moving-average crossover rules
- RSI formula and measurable conditions
- VWAP: volume weighting and anchors
- Confirmed-bar evaluation in Pine Script
Sources
- John Bollinger – Bollinger Band Rules, accessed 25 September 2026.
- TradingView – Pine Script v6 reference: ta.bb, ta.bbw and ta.stdev, accessed 25 September 2026.
- MetaQuotes – Bollinger Bands, accessed 25 September 2026.
- TradingView – Repainting, accessed 25 September 2026.
- TradingView – Alerts, accessed 25 September 2026.
- PineConnector – PineConnector Syntax, accessed 25 September 2026.
- PineConnector – Test your setup, accessed 25 September 2026.
- MetaQuotes – Basic principles: orders, deals and positions, accessed 25 September 2026.
- PineConnector – Frequently asked questions: price differences, accessed 25 September 2026.
- TradingView – Strategies: overfitting, accessed 25 September 2026.
PineConnector executes the instructions you send it. It does not select trades, manage money, or hold funds. Trading carries risk, and past performance of any strategy does not indicate future results.