Appearance
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
| Input | Type | Default |
|---|---|---|
| Length | int | 20 |
| Source | source | "close" |
| StdDev | float | 2 |
| Expansion/contraction lookback | int | 125 |
| Color | color | "#2962FF" |
| Expansion color | color | "#F23645" |
| Contraction color | color | "#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" }) });