Skip to content

Where the close sits between the Bollinger Bands, as one number.

The close’s position between the lower and upper Bollinger Band: 0 at the lower band, 1 at the upper, below 0 or above 1 outside them.

Traders use it to turn “touching the band” into a number they can test, for example %B below 0 as stretched to the downside.

%B = (close − lower band) / (upper band − lower band)

When the bands meet, on a window where the price did not move, there is no %B and the bar has no value.

Call: bollingerB(periods, deviations)

Setting Chart default
periods: Periods 20
deviations: Deviations 2

What you get: a number.

Warm-up: with bollingerB(20, 2), it asks for 20 bars of history and a run-up of 1, and its first value came on bar 21 of the example data.

Bollinger %B drawn by its own code on example prices

The prices are made up, hourly, and the same on every page, so the chart shows how the indicator behaves, not how a market behaved.

function onIntervalClose() {
const percentB = bollingerB(20, 2);
if (OPEN_POSITIONS_COUNT === 0 && percentB < 0) {
openPosition("BUY", { quantity: 10000, stopLossPips: 25, takeProfitPips: 40 });
}
}

This sample buys when the close is below the lower band.