UNPKG

trading-signals

Version:

Technical indicators to run technical analysis with JavaScript / TypeScript.

37 lines 1.14 kB
import { TradingSignal, TrendIndicatorSeries } from '../../base/Indicator.js'; import { pushUpdate } from '../../util/pushUpdate.js'; export class MOM extends TrendIndicatorSeries { #history; #historyLength; interval; constructor(interval) { super(); this.interval = interval; this.#historyLength = interval + 1; this.#history = []; } getRequiredInputs() { return this.#historyLength; } update(value, replace) { pushUpdate(this.#history, replace, value, this.#historyLength); if (this.#history.length === this.#historyLength) { return this.setResult(value - this.#history[0], replace); } return null; } calculateSignalState(result) { const hasResult = result !== null && result !== undefined; if (!hasResult) { return TradingSignal.UNKNOWN; } if (result > 0) { return TradingSignal.BULLISH; } if (result < 0) { return TradingSignal.BEARISH; } return TradingSignal.SIDEWAYS; } } //# sourceMappingURL=MOM.js.map