fintech-algorithms

Bollinger BandWidth

Install and import

bash
npm install fintech-algorithms
ts
import { bollinger_bandwidth } from "fintech-algorithms/technical-indicators/volatility-and-channels/bollinger-bandwidth";

Signature

bollinger_bandwidth(close, p, multiplier)

The width of a Bollinger channel relative to its middle band. Low readings mark contraction, which historically precedes expansion — the quantity behind every 'squeeze' screen.

Parameters

NameTypeNotes
closenumber[]Per-bar closing prices, chronological.
pnumberLookback for the average and the standard deviation.
min: 1 · integer: true
multipliernumberNumber of standard deviations to each band.
min: 0

Returns

Record<string, (number | null)[]> · length same-as-input

Parallel series: middle, stddev, upper, lower and bandwidth.

Warm-up

The first p − 1 positions are null.

Errors

  • When p < 1, is not an integer, or multiplier is negative — throws RangeError

Complexity: time O(n × p), space O(n).

Worked example

executed Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.

Input

close
[100, 100.40234656, 100.79879348, 101.18354586, 101.55101638, 101.89592451]

Showing 6 of 240 elements.

p
20
multiplier
2

Call

bollinger_bandwidth(close, p, multiplier)

Returns

object with 5 fields: middle, stddev, upper, lower, bandwidth

{
  "middle": [null, null, null, null, null, null],
  "stddev": [null, null, null, null, null, null],
  "upper": [null, null, null, null, null, null],
  "lower": [null, null, null, null, null, null],
  "bandwidth": [null, null, null, null, null, null]
}

Other exports

This module also exports bollinger_bands. Every module additionally exports run as an alias of its primary function, and a meta object carrying its catalog id, domain, family, shape and article URL.

Diagrams

Bollinger BandWidth — canonical trace
Bollinger BandWidth — failure boundary
Bollinger BandWidth — mechanism map
Bollinger BandWidth — memory comparison

How it works

This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.

Read the article →

References

  • Bollinger Bands Rules — John Bollinger
  • Bollinger BandWidth (BBW) — TradingView
  • Bollinger Bands (BB) — TradingView
  • Bollinger Bands — TA-Lib
  • e-Handbook: Measures of Scale — NIST/SEMATECH
  • Public evidence boundary