diff --git a/src/AC/AC.ts b/src/AC/AC.ts index 80a7afb55..c564efb0d 100644 --- a/src/AC/AC.ts +++ b/src/AC/AC.ts @@ -24,11 +24,11 @@ export class AC extends SimpleIndicator { this.momentum = new MOM(1); } - get isStable(): boolean { + override get isStable(): boolean { return this.result !== undefined; } - getResult(): Big { + override getResult(): Big { if (!this.result) { throw new NotEnoughDataError(); } @@ -36,7 +36,7 @@ export class AC extends SimpleIndicator { return this.result; } - update(low: BigSource, high: BigSource): void | Big { + override update(low: BigSource, high: BigSource): void | Big { const ao = this.ao.update(low, high); if (ao) { this.signal.update(ao); diff --git a/src/AO/AO.ts b/src/AO/AO.ts index 472212f41..d9b28ea1a 100644 --- a/src/AO/AO.ts +++ b/src/AO/AO.ts @@ -17,11 +17,11 @@ export class AO extends SimpleIndicator { this.long = new SMA(longInterval); } - get isStable(): boolean { + override get isStable(): boolean { return this.result !== undefined; } - getResult(): Big { + override getResult(): Big { if (!this.result) { throw new NotEnoughDataError(); } @@ -29,7 +29,7 @@ export class AO extends SimpleIndicator { return this.result; } - update(low: BigSource, high: BigSource): void | Big { + override update(low: BigSource, high: BigSource): void | Big { const candleSum = new Big(low).add(high); const medianPrice = candleSum.div(2); diff --git a/src/ATR/ATR.ts b/src/ATR/ATR.ts index e37c5b822..fe5f3bf6b 100644 --- a/src/ATR/ATR.ts +++ b/src/ATR/ATR.ts @@ -21,11 +21,11 @@ export class ATR extends SimpleIndicator { this.smma = new SMMA(interval); } - get isStable(): boolean { + override get isStable(): boolean { return this.candles.length > this.interval; } - update(candle: ATRCandle): void { + override update(candle: ATRCandle): void { this.candles.push(candle); if (!this.prevCandle) { @@ -49,7 +49,7 @@ export class ATR extends SimpleIndicator { this.prevCandle = candle; } - getResult(): Big { + override getResult(): Big { if (!this.result) { throw new NotEnoughDataError(); } diff --git a/src/CG/CG.ts b/src/CG/CG.ts index f086e67b3..c3f3899ca 100644 --- a/src/CG/CG.ts +++ b/src/CG/CG.ts @@ -18,7 +18,7 @@ export class CG extends SimpleIndicator { public readonly prices: Big[] = []; - get isStable(): boolean { + override get isStable(): boolean { return this.prices.length >= this.interval && this.signal.isStable; } @@ -27,7 +27,7 @@ export class CG extends SimpleIndicator { this.signal = new SMA(signalInterval); } - update(price: BigSource): void { + override update(price: BigSource): void { this.prices.push(new Big(price)); if (this.prices.length > this.interval) { @@ -50,7 +50,7 @@ export class CG extends SimpleIndicator { this.setResult(cg); } - getResult(): Big { + override getResult(): Big { if (!this.isStable || !this.result) { throw new NotEnoughDataError(); } diff --git a/src/DEMA/DEMA.ts b/src/DEMA/DEMA.ts index 8f3df6795..fdeb32cde 100644 --- a/src/DEMA/DEMA.ts +++ b/src/DEMA/DEMA.ts @@ -12,13 +12,13 @@ export class DEMA extends SimpleIndicator { this.outer = new EMA(interval); } - update(price: BigSource): void { + override update(price: BigSource): void { this.inner.update(price); this.outer.update(this.inner.getResult()); this.setResult(this.inner.getResult().times(2).sub(this.outer.getResult())); } - get isStable(): boolean { + override get isStable(): boolean { try { this.inner.getResult(); this.outer.getResult(); @@ -28,7 +28,7 @@ export class DEMA extends SimpleIndicator { } } - getResult(): Big { + override getResult(): Big { if (!this.result) { throw new NotEnoughDataError(); } diff --git a/src/EMA/EMA.test.ts b/src/EMA/EMA.test.ts index 23a21842c..6fde7aa73 100644 --- a/src/EMA/EMA.test.ts +++ b/src/EMA/EMA.test.ts @@ -17,7 +17,7 @@ describe('EMA', () => { ema.update(new Big(price)); const actual = ema.getResult(); const expected = new Big(ema10results[index]); - expect(actual!.toPrecision(12)).toEqual(expected.toPrecision(12)); + expect(actual.toPrecision(12)).toEqual(expected.toPrecision(12)); }); expect(ema.lowest!.toFixed(2)).toBe('38.20'); @@ -45,7 +45,7 @@ describe('EMA', () => { ema.update(new Big(price)); const actual = ema.getResult(); const expected = new Big(ema26results[index]); - expect(actual!.toPrecision(12)).toEqual(expected.toPrecision(12)); + expect(actual.toPrecision(12)).toEqual(expected.toPrecision(12)); }); expect(ema.lowest!.toFixed(2)).toBe('48.29'); diff --git a/src/EMA/EMA.ts b/src/EMA/EMA.ts index 619ac8ecb..273447389 100644 --- a/src/EMA/EMA.ts +++ b/src/EMA/EMA.ts @@ -2,7 +2,7 @@ import Big, {BigSource} from 'big.js'; import {MovingAverage} from '../MA/MovingAverage'; export class EMA extends MovingAverage { - update(_price: BigSource): void { + override update(_price: BigSource): void { const price = new Big(_price); // If it's the first update there is no previous result and a default has to be set. diff --git a/src/MA/MovingAverage.ts b/src/MA/MovingAverage.ts index 728381475..d5ee73b06 100644 --- a/src/MA/MovingAverage.ts +++ b/src/MA/MovingAverage.ts @@ -7,11 +7,11 @@ export abstract class MovingAverage extends SimpleIndicator { super(); } - get isStable(): boolean { + override get isStable(): boolean { return !!this.result; } - getResult(): Big { + override getResult(): Big { if (!this.result) { throw new NotEnoughDataError(); } diff --git a/src/MOM/MOM.ts b/src/MOM/MOM.ts index 40d34379e..816299e22 100644 --- a/src/MOM/MOM.ts +++ b/src/MOM/MOM.ts @@ -16,18 +16,18 @@ export class MOM extends SimpleIndicator { this.history = getFixedArray(this.historyLength); } - update(value: BigSource): void { + override update(value: BigSource): void { this.history.push(value); if (this.history.length === this.historyLength) { this.setResult(new Big(value).minus(this.history[0])); } } - get isStable(): boolean { + override get isStable(): boolean { return this.result !== undefined; } - getResult(): Big { + override getResult(): Big { if (!this.result) { throw new NotEnoughDataError(); } diff --git a/src/ROC/ROC.ts b/src/ROC/ROC.ts index 0b8661478..f9056ed30 100644 --- a/src/ROC/ROC.ts +++ b/src/ROC/ROC.ts @@ -10,11 +10,11 @@ export class ROC extends SimpleIndicator { this.interval = interval; } - get isStable(): boolean { + override get isStable(): boolean { return this.result !== undefined; } - update(_price: BigSource): void { + override update(_price: BigSource): void { const price = new Big(_price); this.priceHistory.push(price); @@ -35,7 +35,7 @@ export class ROC extends SimpleIndicator { this.setResult(price.sub(comparePrice).div(comparePrice)); } - getResult(): Big { + override getResult(): Big { if (!this.result) { throw new NotEnoughDataError(); } diff --git a/src/RSI/RSI.ts b/src/RSI/RSI.ts index f01168443..b750afa93 100644 --- a/src/RSI/RSI.ts +++ b/src/RSI/RSI.ts @@ -14,7 +14,7 @@ export class RSI extends SimpleIndicator { this.avgLoss = new Indicator(this.interval); } - update(price: BigSource): void { + override update(price: BigSource): void { const currentClose = new Big(price); this.prices.push(currentClose); @@ -52,14 +52,14 @@ export class RSI extends SimpleIndicator { } } - getResult(): Big { + override getResult(): Big { if (!this.isStable) { throw new NotEnoughDataError(); } return this.result!; } - get isStable(): boolean { + override get isStable(): boolean { if (this.result) { return this.result.gt(0); } diff --git a/src/SMA/SMA.ts b/src/SMA/SMA.ts index 4cd1f9258..14ac99101 100644 --- a/src/SMA/SMA.ts +++ b/src/SMA/SMA.ts @@ -4,7 +4,7 @@ import {MovingAverage} from '../MA/MovingAverage'; export class SMA extends MovingAverage { public readonly prices: Big[] = []; - update(price: BigSource): void { + override update(price: BigSource): void { this.prices.push(new Big(price)); if (this.prices.length > this.interval) { diff --git a/src/SMMA/SMMA.ts b/src/SMMA/SMMA.ts index e48e212ae..db7958153 100644 --- a/src/SMMA/SMMA.ts +++ b/src/SMMA/SMMA.ts @@ -11,7 +11,7 @@ class SMMA extends MovingAverage { this.sma = new SMA(interval); } - update(price: BigSource): void { + override update(price: BigSource): void { this.prices.push(new Big(price)); if (this.prices.length < this.interval) { @@ -33,7 +33,7 @@ class SMMA extends MovingAverage { } } - getResult(): Big { + override getResult(): Big { return this.result || new Big(0); } }