trading-signals
Version:
Technical indicators to run technical analysis with JavaScript / TypeScript.
34 lines • 1.24 kB
JavaScript
import { TechnicalIndicator } from '../../base/Indicator.js';
import { pushUpdate } from '../../util/pushUpdate.js';
export class Aroon extends TechnicalIndicator {
#candles = [];
interval;
constructor(interval) {
super();
this.interval = interval;
}
getRequiredInputs() {
return this.interval + 1;
}
update(candle, replace) {
pushUpdate(this.#candles, replace, candle, this.getRequiredInputs());
if (this.#candles.length < this.getRequiredInputs()) {
return null;
}
let highestIndex = 0;
let lowestIndex = 0;
this.#candles.forEach(({ high, low }, i) => {
if (high >= this.#candles[highestIndex].high) {
highestIndex = i;
}
if (low <= this.#candles[lowestIndex].low) {
lowestIndex = i;
}
});
const newestIndex = this.#candles.length - 1;
const aroonDown = (100 * (this.interval - (newestIndex - lowestIndex))) / this.interval;
const aroonUp = (100 * (this.interval - (newestIndex - highestIndex))) / this.interval;
return (this.result = { aroonDown, aroonUp });
}
}
//# sourceMappingURL=Aroon.js.map