trading-signals
Version:
Technical indicators to run technical analysis with JavaScript / TypeScript.
29 lines • 839 B
JavaScript
import { IndicatorSeries } from '../../base/Indicator.js';
import { getQuartile } from '../../util/getQuartile.js';
export class IQR extends IndicatorSeries {
#values = [];
interval;
constructor(interval) {
super();
this.interval = interval;
}
getRequiredInputs() {
return this.interval;
}
update(value, replace) {
if (replace) {
this.#values.pop();
}
this.#values.push(value);
if (this.#values.length > this.interval) {
this.#values.shift();
}
if (this.#values.length < this.interval) {
return null;
}
const q1 = getQuartile(this.#values, 0.25);
const q3 = getQuartile(this.#values, 0.75);
return this.setResult(q3 - q1, replace);
}
}
//# sourceMappingURL=IQR.js.map