# %B

%B is an indicator on [Vela](https://vela.luxalgo.com/chart), our next-generation charting platform, written in Pine Script®.

%B distills Bollinger Band position into a single oscillator reading: 1 at the upper band, 0 at the lower, 0.5 at the basis, computed from a 20-bar average with a 2x standard deviation offset. Dashed overbought (1) and oversold (0) levels, a midline, and a gradient fill make band position readable at a glance, with alerts on every threshold and midline cross.

- Indicator in the LuxAlgo Library, by LuxAlgo, published Jun 11, 2026.
- Access: free.
- Concepts: [%B](https://www.luxalgo.com/library/concept/percent-b/) (primary)
- Open on Vela: https://vela.luxalgo.com/chart?pineScriptCodeId=i2fxgl76fya0zh63eejpsu2m
- Page: https://www.luxalgo.com/library/indicator/percent-b/

**%B** collapses Bollinger Band position into one oscillator value: 1 means price sits on the upper band, 0 on the lower, 0.5 on the moving-average basis, and anything beyond those bounds says price has moved outside the bands. This is the definitive clean build of the [%B statistic](https://www.luxalgo.com/library/concept/percent-b/): bands come from a 20-bar simple moving average with a 2x standard-deviation offset; the line is colored bullish above the 0.5 midline, bearish below it, and a gradient fill anchors each reading to the midline.

## How to Trade the %B?

- **%B above 1**: price is outside the upper band: uncommon, but a strong trend can pin readings there while price walks the band, so read it as strength first and stretch second.
- **%B below 0**: price is outside the lower band, the mirrored oversold condition.
- **Midline crosses**: a move through 0.5 marks price reclaiming or losing the basis, a simple bias filter between band tags.
- **Threshold exits**: crossing back inside 1 or 0 marks price pulling back within the bands; the exit is often more actionable than the entry.

Six alerts cover threshold entries and exits plus both midline crosses; optional markers circle bars held beyond a threshold.

## %B Settings

- **Length** (default 20): bars for the basis average and standard deviation; shorter reacts faster, longer smooths.
- **Source** (default close): price series the bands and %B are computed from.
- **Multiplier** (default 2): standard-deviation multiplier. %B is derived entirely from the bands, so everything inherits it.
- **Overbought** (default 1) and **Oversold** (default 0): thresholds; move them inward to flag approaches before a band tag.
- **Extreme Markers** (default disabled): circles on readings beyond a threshold.
- **Gradient Fill** (default enabled): gradient between %B and the midline; remaining Style inputs set colors.

## Frequently Asked Questions

### Is %B different from the Stochastic oscillator?

Yes. The [Stochastic oscillator](https://www.luxalgo.com/library/indicator/stochastic/) locates the close within the raw high/low range of a lookback window, while %B locates price within volatility bands around a moving average. The Stochastic cannot leave its 0-100 scale; %B can, and readings beyond 1 or below 0 carry real information.

### Why does %B stay above 1 for many bars in strong trends?

Trending price can walk the upper band, pinning the reading beyond the threshold; there, high values signal persistent strength rather than an imminent turn. The exit back inside is usually the more useful trigger.

### What happens when the bands have zero width?

A flat lookback window makes the standard deviation zero and %B would divide by zero; this build returns no value on such bars instead. Readings resume once the window regains variation.

## Related indicators

- [Nadaraya-Watson Envelope](https://www.luxalgo.com/library/indicator/nadaraya-watson-envelope/) (Envelope): markdown at https://www.luxalgo.com/library/indicator/nadaraya-watson-envelope.md
- [TTM Squeeze](https://www.luxalgo.com/library/indicator/ttm-squeeze/) (Volatility): markdown at https://www.luxalgo.com/library/indicator/ttm-squeeze.md
- [Fibonacci Bollinger Bands](https://www.luxalgo.com/library/indicator/fibonacci-bollinger-bands/) (Volatility): markdown at https://www.luxalgo.com/library/indicator/fibonacci-bollinger-bands.md
- [Double Bollinger Zones](https://www.luxalgo.com/library/indicator/double-bollinger-zones/) (Volatility): markdown at https://www.luxalgo.com/library/indicator/double-bollinger-zones.md
- [Proximal Range Filter](https://www.luxalgo.com/library/indicator/proximal-range-filter/) (Envelope): markdown at https://www.luxalgo.com/library/indicator/proximal-range-filter.md
- [Bollinger Squeeze](https://www.luxalgo.com/library/indicator/bollinger-squeeze/) (Volatility): markdown at https://www.luxalgo.com/library/indicator/bollinger-squeeze.md
- [Bollinger Bands Breakout Oscillator](https://www.luxalgo.com/library/indicator/bollinger-bands-breakout-oscillator/) (Bollinger Bands): markdown at https://www.luxalgo.com/library/indicator/bollinger-bands-breakout-oscillator.md
- [Donchian MA Bands](https://www.luxalgo.com/library/indicator/donchian-ma-bands/) (Donchian Channels): markdown at https://www.luxalgo.com/library/indicator/donchian-ma-bands.md

---

Source: https://www.luxalgo.com/library/indicator/percent-b/ (LuxAlgo Library). Free to use with attribution: https://www.luxalgo.com/library/license/
