diff --git a/src/ADX/ADX.ts b/src/ADX/ADX.ts index e959c3e37..7fd830092 100644 --- a/src/ADX/ADX.ts +++ b/src/ADX/ADX.ts @@ -1,6 +1,6 @@ import {Big} from 'big.js'; import {NotEnoughDataError} from '../error'; -import {ATR, ATRCandle, MovingAverageTypeContext, SMMA} from '..'; +import {ATR, HighLowClose, MovingAverageTypeContext, SMMA} from '..'; import {Indicator} from '../Indicator'; import {getAverage} from '../util/getAverage'; import {MovingAverage} from '../MA/MovingAverage'; @@ -32,12 +32,12 @@ export type ADXResult = { * @see https://learn.tradimo.com/technical-analysis-how-to-work-with-indicators/adx-determing-the-strength-of-price-movement */ export class ADX implements Indicator { - private readonly candles: ATRCandle[] = []; + private readonly candles: HighLowClose[] = []; private readonly atr: ATR; private readonly smoothedPDM: MovingAverage; private readonly smoothedMDM: MovingAverage; private readonly dxValues: Big[] = []; - private prevCandle: ATRCandle | undefined; + private prevCandle: HighLowClose | undefined; private adx: Big | undefined; private pdi: Big = new Big(0); private mdi: Big = new Big(0); @@ -52,7 +52,7 @@ export class ADX implements Indicator { return this.dxValues.length >= this.interval; } - update(candle: ATRCandle): void { + update(candle: HighLowClose): void { this.candles.push(candle); const atrResult = this.atr.update(candle); @@ -153,7 +153,7 @@ export class ADX implements Indicator { }; } - private directionalMovement(prevCandle: ATRCandle, currentCandle: ATRCandle): {mdm: Big; pdm: Big} { + private directionalMovement(prevCandle: HighLowClose, currentCandle: HighLowClose): {mdm: Big; pdm: Big} { const currentHigh = new Big(currentCandle.high); const lastHigh = new Big(prevCandle.high); diff --git a/src/ATR/ATR.ts b/src/ATR/ATR.ts index 1b86334e9..55421bdb5 100644 --- a/src/ATR/ATR.ts +++ b/src/ATR/ATR.ts @@ -1,10 +1,10 @@ -import Big, {BigSource} from 'big.js'; -import {NotEnoughDataError, SMMA} from '..'; +import Big from 'big.js'; +import {NotEnoughDataError} from '../error'; import {SimpleIndicator} from '../Indicator'; import {MovingAverage} from '../MA/MovingAverage'; import {MovingAverageTypeContext} from '../MA/MovingAverageTypeContext'; - -export type ATRCandle = {close: BigSource; high: BigSource; low: BigSource}; +import {SMMA} from '../SMMA/SMMA'; +import {HighLowClose} from '../util'; /** * Average True Range (ATR) @@ -17,9 +17,9 @@ export type ATRCandle = {close: BigSource; high: BigSource; low: BigSource}; * @see https://www.investopedia.com/terms/a/atr.asp */ export class ATR extends SimpleIndicator { - private readonly candles: ATRCandle[] = []; + private readonly candles: HighLowClose[] = []; private readonly smoothing: MovingAverage; - private prevCandle: ATRCandle | undefined; + private prevCandle: HighLowClose | undefined; constructor(public readonly interval: number, SmoothingIndicator: MovingAverageTypeContext = SMMA) { super(); @@ -30,7 +30,7 @@ export class ATR extends SimpleIndicator { return this.candles.length > this.interval; } - override update(candle: ATRCandle): Big | void { + override update(candle: HighLowClose): Big | void { this.candles.push(candle); if (!this.prevCandle) { @@ -63,7 +63,7 @@ export class ATR extends SimpleIndicator { return this.result; } - private trueRange(prevCandle: ATRCandle, currentCandle: ATRCandle): Big { + private trueRange(prevCandle: HighLowClose, currentCandle: HighLowClose): Big { const prevClose = new Big(prevCandle.close); const low = new Big(currentCandle.low); const high = new Big(currentCandle.high); diff --git a/src/STOCH/StochasticOscillator.ts b/src/STOCH/StochasticOscillator.ts index 66fb9b136..76e40c292 100644 --- a/src/STOCH/StochasticOscillator.ts +++ b/src/STOCH/StochasticOscillator.ts @@ -1,12 +1,12 @@ import {Indicator} from '../Indicator'; import Big from 'big.js'; import {SMA} from '../SMA/SMA'; -import {ATRCandle} from '../ATR/ATR'; import {MovingAverageTypeContext} from '../MA/MovingAverageTypeContext'; import {MovingAverage} from '../MA/MovingAverage'; import {getMaximum} from '../util/getMaximum'; import {getMinimum} from '../util/getMinimum'; import {NotEnoughDataError} from '../error'; +import {HighLowClose} from '../util'; export interface StochasticResult { d: Big; @@ -33,7 +33,7 @@ export interface StochasticResult { export class StochasticOscillator implements Indicator { public readonly d: MovingAverage; - private readonly candles: ATRCandle[] = []; + private readonly candles: HighLowClose[] = []; private result?: StochasticResult; /** @@ -59,7 +59,7 @@ export class StochasticOscillator implements Indicator { return this.result; } - update(candle: ATRCandle): StochasticResult | void { + update(candle: HighLowClose): StochasticResult | void { this.candles.push(candle); if (this.candles.length > this.periodK) { diff --git a/src/util/HighLowClose.ts b/src/util/HighLowClose.ts new file mode 100644 index 000000000..7c7ac6dc4 --- /dev/null +++ b/src/util/HighLowClose.ts @@ -0,0 +1,3 @@ +import {BigSource} from 'big.js'; + +export type HighLowClose = {close: BigSource; high: BigSource; low: BigSource}; diff --git a/src/util/index.ts b/src/util/index.ts index bd9cbeef8..7670153d4 100644 --- a/src/util/index.ts +++ b/src/util/index.ts @@ -1,2 +1,6 @@ +export * from './BandsResult'; export * from './getAverage'; export * from './getFixedArray'; +export * from './getMaximum'; +export * from './getMinimum'; +export * from './HighLowClose';