trading-signals
Version:
Technical indicators to run technical analysis with JavaScript / TypeScript.
42 lines • 1.61 kB
JavaScript
import { TradingSignal, TrendIndicatorSeries } from '../../base/Indicator.js';
export class AD extends TrendIndicatorSeries {
#previousCandle = null;
#previousAD = null;
getRequiredInputs() {
return 1;
}
update(candle, replace) {
if (replace && this.#previousCandle !== null) {
}
else {
this.#previousAD = this.result ?? null;
}
this.#previousCandle = candle;
const highLowDiff = candle.high - candle.low;
let moneyFlowMultiplier = 0;
if (highLowDiff !== 0) {
moneyFlowMultiplier = (candle.close - candle.low - (candle.high - candle.close)) / highLowDiff;
}
const moneyFlowVolume = moneyFlowMultiplier * candle.volume;
const ad = (this.#previousAD ?? 0) + moneyFlowVolume;
return this.setResult(ad, replace);
}
calculateSignalState(result) {
const hasResult = result !== null && result !== undefined;
const previousResult = this.previousResult;
const hasPreviousResult = previousResult !== undefined;
const isBullish = hasResult && hasPreviousResult && result > previousResult;
const isBearish = hasResult && hasPreviousResult && result < previousResult;
switch (true) {
case !hasResult:
return TradingSignal.UNKNOWN;
case isBullish:
return TradingSignal.BULLISH;
case isBearish:
return TradingSignal.BEARISH;
default:
return TradingSignal.SIDEWAYS;
}
}
}
//# sourceMappingURL=AD.js.map