UNPKG

trading-signals

Version:

Technical indicators to run technical analysis with JavaScript / TypeScript.

42 lines 1.41 kB
import { TradingSignal, TrendIndicatorSeries } from '../../base/Indicator.js'; import { EMA } from '../../trend/EMA/EMA.js'; export class PPO extends TrendIndicatorSeries { #fast; #slow; fastPeriod; slowPeriod; constructor({ fastPeriod = 12, slowPeriod = 26 } = {}) { super(); this.fastPeriod = fastPeriod; this.slowPeriod = slowPeriod; this.#fast = new EMA(fastPeriod); this.#slow = new EMA(slowPeriod); } getRequiredInputs() { return this.#slow.getRequiredInputs(); } update(price, replace) { const fast = this.#fast.update(price, replace); const slow = this.#slow.update(price, replace); if (this.#slow.isStable) { return this.setResult((100 * (fast - slow)) / slow, replace); } return null; } calculateSignalState(result) { const hasResult = result !== null && result !== undefined; const isBullish = hasResult && result > 0; const isBearish = hasResult && result < 0; switch (true) { case !hasResult: return TradingSignal.UNKNOWN; case isBullish: return TradingSignal.BULLISH; case isBearish: return TradingSignal.BEARISH; default: return TradingSignal.SIDEWAYS; } } } //# sourceMappingURL=PPO.js.map