Skip to content

Bollinger Bands %B ​

Where price sits within the Bollinger Bands, 0 = lower, 1 = upper.

Kind indicator · Drawn in its own pane

Try it ​

On the chart, press / and choose Bollinger Bands %B under Bands & channels. To change it, copy the source below into the AlphaScript editor.

Inputs ​

InputTypeDefault
Lengthint20
Sourcesource"close"
StdDevfloat2
Colorcolor"#22AB94"

Source ​

From packages/alphascript/indicators/bbpercentb.as.js.

js
indicator({ name: "Bollinger Bands %B", shortTitle: "BB %B", overlay: false, precision: 2 });
const length = input.int("Length", 20, { min: 1 });
const src = input.source("Source", "close");
const mult = input.float("StdDev", 2, { min: 0.001, max: 50, step: 0.1 });
const bb = ta.bbands(src, length, mult);
plot(ta.calc([src, bb.upper, bb.lower], (s, u, l) => (u - l ? (s - l) / (u - l) : NaN)), { title: "%B", color: input.color("Color", "#22AB94", { group: "Style" }) });
hline(1, { title: "Upper band", color: "#787B86", style: "dashed" });
hline(0.5, { title: "Middle band", color: "rgba(120,123,134,0.5)", style: "dotted" });
hline(0, { title: "Lower band", color: "#787B86", style: "dashed" });
fill(1, 0, { title: "Background", color: "rgba(38,166,154,0.1)" });

AlphaScript language v0.1 · runtime 0.2.0