Bollinger Bands %B (PERCENTB)
Summary
Bollinger Bands %B: where the input sits relative to its Bollinger Bands, 0 at the lower band and 1 at the upper band. Values below 0 or above 1 mean the input is outside the bands.
Formula
where and are the BBANDS bands of with period , moving-average type and deviation multipliers , .
Notes
- An input on the middle band reads
optInNbDevDn / (optInNbDevUp + optInNbDevDn): 0.5 with equal multipliers. - With a simple moving average and both multipliers equal to k, %B = 0.5 + z / (2k), where z is the z-score of the input in its window.
- The result is a ratio; multiply by 100 to read it as a percentage.
- Any
optInMATypeother than SMA is a TA-Lib generalisation, as it is for BBANDS: the deviation stays the population standard deviation about the simple mean. - PERCENTB is bit for bit
(inReal - lower) / (upper - lower)computed from BBANDS' own outputs, and 0.5 wherever those two bands are equal.
Inputs
inReal— Input data series
Outputs
outReal— Position of the input between the lower band (0) and the upper band (1)
Parameters
| Parameter | Type | Default | Accepted values | Description |
|---|---|---|---|---|
optInTimePeriod | integer | 20 | 2–100000 | Periods for the MA and standard deviation |
optInNbDevUp | real | 2 | any real | Standard-deviation multiplier for the upper band |
optInNbDevDn | real | 2 | any real | Standard-deviation multiplier for the lower band |
optInMAType | MAType | SMA (0) | any MAType | Moving-average type for the middle band |
MAType values: 0 SMA · 1 EMA · 2 WMA · 3 DEMA · 4 TEMA · 5 TRIMA · 6 KAMA · 7 MAMA · 8 T3 · 9 HMA · 10 DISABLED · 11 DEFAULT · 12 ZLEMA · 13 RMA · 14 VIDYA · 15 ALMA
Properties
Numerical Stability: Depends on MA Type — This function's default, SMA, is start-independent.
| ☐ Overlap Input |
| ✅ Independent Y-Axis i |
| ☐ Candlestick |
| ☐ Can Output NaN or ±Inf |
| ☐ Identity at Period 1 |
Implementation
TA-Lib Definition: percentb.c · percentb.yaml
| Native | File |
|---|---|
| C | ta_PERCENTB.c |
| Rust | percentb.rs |
| Java | Core_PERCENTB.java |
| C# | Core_PERCENTB.cs |
TA-Lib is also available for Python, R and more using a wrapper.
Aliases
Bollinger %b, %b, %B, Percent B, BB %B, BBP, Bollinger Bands %B
See Also
References
- John A. Bollinger, Bollinger on Bollinger Bands, McGraw-Hill 2001 (ISBN 0071373683)
- John Bollinger, Bollinger Band Rules, rules 15-17