forked from bennycode/trading-signals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBollingerBandsWidth.ts
36 lines (32 loc) · 1.33 KB
/
BollingerBandsWidth.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import {BigIndicatorSeries, NumberIndicatorSeries} from '../Indicator.js';
import type {Big, BigSource} from '../index.js';
import type {BollingerBands, FasterBollingerBands} from '../BBANDS/BollingerBands.js';
/**
* The Bollinger Bands Width (BBW) indicator, developed by John A. Bollinger, merges the information of Bollinger Bands
* into one definite number. It defines the narrowness of the underlying Bollinger Bands by representing the difference
* between the Upper Band and the Lower Band.
*
* @see https://www.tradingview.com/support/solutions/43000501972-bollinger-bands-width-bbw/
*/
export class BollingerBandsWidth extends BigIndicatorSeries {
constructor(public readonly bollingerBands: BollingerBands) {
super();
}
override update(price: BigSource): void | Big {
const result = this.bollingerBands.update(price);
if (result) {
return this.setResult(result.upper.minus(result.lower).div(result.middle), false);
}
}
}
export class FasterBollingerBandsWidth extends NumberIndicatorSeries {
constructor(public readonly bollingerBands: FasterBollingerBands) {
super();
}
override update(price: number): void | number {
const result = this.bollingerBands.update(price);
if (result !== undefined) {
return this.setResult((result.upper - result.lower) / result.middle, false);
}
}
}