Skip to content

Bollinger BandWidth ​

Bollinger band width relative to the basis, with expansion and contraction marks.

Kind indicator · Drawn in its own pane

Try it ​

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

Inputs ​

InputTypeDefault
Lengthint20
Sourcesource"close"
StdDevfloat2
Expansion/contraction lookbackint125
Colorcolor"#2962FF"
Expansion colorcolor"#F23645"
Contraction colorcolor"#26A69A"

Source ​

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

js
indicator({ name: "Bollinger BandWidth", shortTitle: "BBW", overlay: false, precision: 4 });
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 lookback = input.int("Expansion/contraction lookback", 125, { min: 1 });
const bb = ta.bbands(src, length, mult);
const bbw = ta.calc([bb.upper, bb.lower, bb.middle], (u, l, m) => (m ? (u - l) / m : NaN));
plot(bbw, { title: "Bollinger BandWidth", color: input.color("Color", "#2962FF", { group: "Style" }) });
plot(ta.highest(bbw, lookback), { title: "Highest expansion", color: input.color("Expansion color", "#F23645", { group: "Style" }) });
plot(ta.lowest(bbw, lookback), { title: "Lowest contraction", color: input.color("Contraction color", "#26A69A", { group: "Style" }) });

AlphaScript language v0.1 · runtime 0.2.0