trading-signals
Version:
Technical indicators to run technical analysis with JavaScript / TypeScript.
24 lines • 972 B
JavaScript
import { MovingAverage } from '../MA/MovingAverage.js';
import { pushUpdate } from '../../util/pushUpdate.js';
export class SMA15 extends MovingAverage {
prices = [];
static #WEIGHTS = [-3, -6, -5, 3, 21, 46, 67, 74, 67, 46, 21, 3, -5, -6, -3];
static #WEIGHT_SUM = 320;
getRequiredInputs() {
return SMA15.#WEIGHTS.length;
}
update(price, replace) {
pushUpdate(this.prices, replace, price, this.getRequiredInputs());
if (this.prices.length === this.getRequiredInputs()) {
let weightedPricesSum = 0;
for (let i = 0; i < this.getRequiredInputs(); i++) {
const weightedPrice = this.prices[i] * SMA15.#WEIGHTS[i];
weightedPricesSum += weightedPrice;
}
const weightedAverage = weightedPricesSum / SMA15.#WEIGHT_SUM;
return this.setResult(weightedAverage, replace);
}
return null;
}
}
//# sourceMappingURL=SMA15.js.map