UNPKG

trading-signals

Version:

Technical indicators to run technical analysis with JavaScript / TypeScript.

37 lines 1.22 kB
import { IndicatorSeries } from '../../base/Indicator.js'; import { pushUpdate } from '../../util/pushUpdate.js'; export class BreakoutBarLow extends IndicatorSeries { #lookback; #highs = []; #lastEmitted = false; constructor(config) { super(); this.#lookback = config.lookback; } getRequiredInputs() { return this.#lookback + 1; } update(candle, replace) { if (replace && this.#lastEmitted) { this.rollbackLastResult(); } this.#lastEmitted = false; pushUpdate(this.#highs, replace, candle.high, this.getRequiredInputs()); if (this.#highs.length < this.getRequiredInputs()) { return null; } const currentHigh = this.#highs[this.#highs.length - 1]; let maxPriorHigh = this.#highs[0]; for (let i = 1; i < this.#highs.length - 1; i++) { if (this.#highs[i] > maxPriorHigh) { maxPriorHigh = this.#highs[i]; } } if (currentHigh > maxPriorHigh) { this.#lastEmitted = true; return this.setResult(candle.low, false); } return null; } } //# sourceMappingURL=BreakoutBarLow.js.map