UNPKG

trading-signals

Version:

Technical indicators to run technical analysis with JavaScript / TypeScript.

29 lines 1.01 kB
import { MovingAverage } from '../MA/MovingAverage.js'; import { WMA } from '../WMA/WMA.js'; export class HMA extends MovingAverage { #wmaHalf; #wmaFull; #wmaSqrt; constructor(interval) { super(interval); this.#wmaHalf = new WMA(Math.floor(interval / 2)); this.#wmaFull = new WMA(interval); this.#wmaSqrt = new WMA(Math.floor(Math.sqrt(interval))); } getRequiredInputs() { return this.#wmaFull.getRequiredInputs() + this.#wmaSqrt.getRequiredInputs() - 1; } update(price, replace) { const half = this.#wmaHalf.update(price, replace); const full = this.#wmaFull.update(price, replace); if (half !== null && full !== null) { const lagReduced = 2 * half - full; const result = this.#wmaSqrt.update(lagReduced, replace); if (result !== null) { return this.setResult(result, replace); } } return null; } } //# sourceMappingURL=HMA.js.map