UNPKG

trading-signals

Version:

Technical indicators to run technical analysis with JavaScript / TypeScript.

49 lines 1.6 kB
import { SMA } from '../../trend/SMA/SMA.js'; import { TrendIndicatorSeries, TradingSignal } from '../../base/Indicator.js'; import { AO } from '../AO/AO.js'; import { MOM } from '../MOM/MOM.js'; export class AC extends TrendIndicatorSeries { ao; momentum; signal; shortAO; longAO; signalInterval; constructor(shortAO, longAO, signalInterval) { super(); this.shortAO = shortAO; this.longAO = longAO; this.signalInterval = signalInterval; this.ao = new AO(shortAO, longAO); this.momentum = new MOM(1); this.signal = new SMA(signalInterval); } getRequiredInputs() { return this.ao.getRequiredInputs() + this.signal.getRequiredInputs() - 1; } update(input, replace) { const ao = this.ao.update(input, replace); if (ao) { this.signal.update(ao, replace); if (this.signal.isStable) { const result = this.setResult(ao - this.signal.getResultOrThrow(), replace); this.momentum.update(result, replace); return result; } } return null; } calculateSignalState(result) { const hasResult = result !== null && result !== undefined; const isPositive = hasResult && result > 0; switch (true) { case !hasResult: return TradingSignal.UNKNOWN; case isPositive: return TradingSignal.BULLISH; default: return TradingSignal.BEARISH; } } } //# sourceMappingURL=AC.js.map