forked from coin-unknown/Indicators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwws.ts
41 lines (34 loc) · 1.15 KB
/
wws.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
37
38
39
40
41
/**
* The Welles Wilder's Smoothing Average (WWS) was developed by J. Welles Wilder, Jr. and is part of the Wilder's RSI indicator implementation.
* This indicator smoothes price movements to help you identify and spot bullish and bearish trends.
*/
export class WWS {
private prevValue: number = 0;
private sumCount = 1;
constructor(private period: number) {}
/**
* Get next value for closed candle hlc
* affect all next calculations
*/
nextValue(value: number) {
if (this.sumCount < this.period) {
this.prevValue += value;
this.sumCount++;
return;
}
if (this.sumCount === this.period) {
this.prevValue += value;
this.sumCount++;
this.nextValue = (value: number) =>
(this.prevValue = this.prevValue - this.prevValue / this.period + value);
return this.prevValue;
}
}
/**
* Get next value for non closed (tick) candle hlc
* does not affect any next calculations
*/
momentValue(value: number) {
return this.prevValue + (value - this.prevValue) / this.period;
}
}