trading-signals
Version:
Technical indicators to run technical analysis with JavaScript / TypeScript.
26 lines • 980 B
JavaScript
import { IndicatorSeries } from '../../base/Indicator.js';
export class TR extends IndicatorSeries {
#previousCandle;
#twoPreviousCandle;
getRequiredInputs() {
return 2;
}
update(candle, replace) {
const { high, low } = candle;
const highLow = high - low;
if (this.#previousCandle && replace) {
this.#previousCandle = this.#twoPreviousCandle;
}
if (this.#previousCandle) {
const highClose = Math.abs(high - this.#previousCandle.close);
const lowClose = Math.abs(low - this.#previousCandle.close);
this.#twoPreviousCandle = this.#previousCandle;
this.#previousCandle = candle;
return this.setResult(Math.max(highLow, highClose, lowClose), replace);
}
this.#twoPreviousCandle = this.#previousCandle;
this.#previousCandle = candle;
return this.setResult(highLow, replace);
}
}
//# sourceMappingURL=TR.js.map