trading-signals
Version:
Technical indicators to run technical analysis with JavaScript / TypeScript.
45 lines • 1.49 kB
JavaScript
import { TradingSignal, TrendIndicatorSeries } from '../../base/Indicator.js';
import { EMA } from '../../trend/EMA/EMA.js';
import { AD } from '../AD/AD.js';
export class ADOSC extends TrendIndicatorSeries {
#ad = new AD();
#fast;
#slow;
fastPeriod;
slowPeriod;
constructor({ fastPeriod = 3, slowPeriod = 10 } = {}) {
super();
this.fastPeriod = fastPeriod;
this.slowPeriod = slowPeriod;
this.#fast = new EMA(fastPeriod);
this.#slow = new EMA(slowPeriod);
}
getRequiredInputs() {
return this.#slow.getRequiredInputs();
}
update(candle, replace) {
const ad = this.#ad.update(candle, replace);
const fast = this.#fast.update(ad, replace);
const slow = this.#slow.update(ad, replace);
if (this.#slow.isStable) {
return this.setResult(fast - 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=ADOSC.js.map