Bollinger percent B indicator: formula and limits
The Bollinger percent B indicator measures price location relative to the lower and upper Bollinger Bands. Its decimal value is 0 at the lower band, 0.5 at the middle band, and 1 at the upper band when the bands are symmetric and have nonzero width.
Direct answer
%B = (price - lower band) / (upper band - lower band). Values below 0 or above 1 are valid positions outside the bands. When the bands coincide, the denominator is zero and the ratio is undefined; it is not a neutral reading of 0.5.
Starting values
Lower band
%B = 0
Middle band
%B = 0.5
Upper band
%B = 1
Zero band width
Undefined ratio
Checks before using the result
- 1
Match the price source, length, deviation multiplier, symbol, and timeframe before comparing two %B series.
- 2
Keep thresholds on the same scale: decimal 0.8 equals 80% of the distance from the lower to the upper band.
- 3
Check missing and zero-width values separately. Replacing an undefined value with 0 would falsely place price at the lower band.
Calculate position from the same bar
Use price and both band values from the same bar. TradingView documents close, length 20, and a deviation multiplier of 2 as defaults. Record any changes to those inputs before comparing results.
- Subtract the lower band from the selected price.
- Divide by upper band minus lower band, provided that distance is positive.
- Keep the unrounded result for conditions; round only the displayed value.
Worked example: lower 90, upper 110
This hypothetical arithmetic example holds the bands fixed at 90 and 110. Their midpoint is 100 and their distance is 20. At price 105, %B = (105 - 90) / 20 = 0.75. These are independent input snapshots, not successive bars or measured market results. The table below checks the same formula at each price.
- Price 85 gives (85 - 90) / 20 = -0.25: 5 units below the lower band.
- Price 115 gives (115 - 90) / 20 = 1.25: 5 units above the upper band.
- Do not clamp either result to 0 or 1. Clamping would erase how far price moved outside the bands.
Handle zero width and missing inputs explicitly
If price, lower band, and upper band all equal 100, the formula becomes (100 - 100) / (100 - 100) = 0/0. It has no defined value. A flat price window can produce coincident bands; a zero deviation multiplier can also collapse them. This page specifies na for that case, rather than asserting an undocumented TradingView fallback.
- Return na when either band or the price is missing, or when the band distance is not positive.
- Skip threshold events until both the previous and current %B values are defined. A missing value is not a crossing.
- A very small positive band distance is still valid, but the ratio is sensitive to tiny price changes. Inspect unrounded inputs before diagnosing a large value as a bug.
Decimal values and percentage displays
Multiplying decimal %B by 100 changes the display scale, not the price location. The worked value 0.75 becomes 75%, and 1.25 becomes 125%. Neither value describes an investment return or the probability of a price move. A threshold entered as 80 into a decimal series does not mean 80%; it means eighty full band distances from the lower band.
Compare closed bars in TradingView
Add Bollinger Bands %b to the chart and match its settings to the bands used in your calculation. Compare the Data Window values on one closed bar at a time. An open bar can change both price and the bands, so an intrabar threshold event can disappear before the close.
- Start with a closed bar inside the bands, then inspect one outside them and any flat or missing-data cases available in the dataset.
- Distinguish a level from a cross: 0.79 to 0.81 crosses above 0.8; 0.81 to 0.83 remains above it but does not cross again.
- For chart-timeframe alerts, require a confirmed bar and configure delivery at bar close. Pine barstate.isconfirmed is true on historical bars and on the closing update of a realtime bar.
%B and BandWidth answer different questions
%B measures position; BandWidth measures the distance between the bands relative to their middle line. In a hypothetical symmetric example, price 100 gives %B = 0.5 with bands 90/110 and also with bands 99/101. The raw band distances are 20 and 2, despite identical %B. John Bollinger also cautions that touching a band alone does not supply a buy or sell signal. Price can remain near a band during a trend.
Hand-check %B with fixed bands of 90 and 110
| Price and position | Decimal calculation | Percentage display |
|---|---|---|
| 85: below lower | -5 / 20 = -0.25 | -25% |
| 90: at lower | 0 / 20 = 0 | 0% |
| 95: inside | 5 / 20 = 0.25 | 25% |
| 100: at midpoint | 10 / 20 = 0.5 | 50% |
| 105: inside | 15 / 20 = 0.75 | 75% |
| 110: at upper | 20 / 20 = 1 | 100% |
| 115: above upper | 25 / 20 = 1.25 | 125% |
Bollinger %B Pine Script prompt
Use the Pine Script AI Coding Agent to draft a checkable indicator from this specification. Verify the returned series bar by bar before defining strategy entries, exits, position sizing, and costs.
Create a Pine Script v6 Bollinger Bands %B indicator on the chart timeframe. Use close, a 20-bar SMA, and 2 standard deviations as defaults; expose source, length, and a positive multiplier. Calculate the decimal ratio of price minus lower band to upper band minus lower band. Return na for missing inputs or nonpositive band width, and never clamp valid results to 0 or 1. Plot decimal reference levels 0, 0.5, and 1. Add separate confirmed-bar alerts for crossing above 0.8, below 0.2, above 1, and below 0. Require valid previous and current values for crossing events. Expose the source and band values for Data Window inspection. Explain warm-up behavior and compare values against the hand calculation before adding any strategy orders.Generate the %B script
Related Bollinger Bands pages
Tools for the next test
Bollinger Bands Calculator
Compute Bollinger Bands to analyze market volatility and potential price breakouts.
Bollinger Bands Crossover
Define upper, lower, and basis crossover events by direction and generate separate bar-close alerts for each event.
Bollinger Bands and RSI
Combine Bollinger price location with a separate RSI momentum condition and inspect the resulting Pine Script rules.
Sources and method notes
Pineify provides tools and information, not investment advice. The numbers on this page are hypothetical calculations. %B does not guarantee a reversal, continuation, or return.