UNPKG

trading-signals

Version:

Technical indicators to run technical analysis with JavaScript / TypeScript.

40 lines 1.27 kB
import { TradingSignal, TrendIndicatorSeries } from '../../base/Indicator.js'; import { pushUpdate } from '../../util/pushUpdate.js'; export class VROC extends TrendIndicatorSeries { #volumes = []; #historyLength; interval; constructor(interval) { super(); this.interval = interval; this.#historyLength = interval + 1; } getRequiredInputs() { return this.#historyLength; } update(volume, replace) { pushUpdate(this.#volumes, replace, volume, this.#historyLength); if (this.#volumes.length < this.#historyLength) { return null; } const previousVolume = this.#volumes[0]; if (previousVolume === 0) { return this.setResult(0, replace); } const vroc = ((volume - previousVolume) / previousVolume) * 100; return this.setResult(vroc, replace); } calculateSignalState(result) { if (result === null || result === undefined) { return TradingSignal.UNKNOWN; } if (result > 0) { return TradingSignal.BULLISH; } if (result < 0) { return TradingSignal.BEARISH; } return TradingSignal.SIDEWAYS; } } //# sourceMappingURL=VROC.js.map