UNPKG

trading-signals

Version:

Technical indicators to run technical analysis with JavaScript / TypeScript.

43 lines 1.53 kB
import { SMA } from '../../trend/SMA/SMA.js'; import { TrendIndicatorSeries, TradingSignal } from '../../base/Indicator.js'; export class AO extends TrendIndicatorSeries { long; short; shortInterval; longInterval; constructor(shortInterval, longInterval, SmoothingIndicator = SMA) { super(); this.shortInterval = shortInterval; this.longInterval = longInterval; this.short = new SmoothingIndicator(shortInterval); this.long = new SmoothingIndicator(longInterval); } getRequiredInputs() { return this.long.getRequiredInputs(); } update({ high, low }, replace) { const medianPrice = (low + high) / 2; this.short.update(medianPrice, replace); this.long.update(medianPrice, replace); if (this.long.isStable) { return this.setResult(this.short.getResultOrThrow() - this.long.getResultOrThrow(), 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=AO.js.map