UNPKG

trading-signals

Version:

Technical indicators to run technical analysis with JavaScript / TypeScript.

40 lines 1.34 kB
import { TechnicalIndicator } from '../../base/Indicator.js'; import { pushUpdate } from '../../util/pushUpdate.js'; import { ATR } from '../../volatility/ATR/ATR.js'; export class ChandelierExit extends TechnicalIndicator { #atr; #candles = []; interval; multiplier; constructor({ interval = 22, multiplier = 3 } = {}) { super(); this.interval = interval; this.multiplier = multiplier; this.#atr = new ATR(interval); } getRequiredInputs() { return this.#atr.getRequiredInputs(); } update(candle, replace) { const atr = this.#atr.update(candle, replace); pushUpdate(this.#candles, replace, candle, this.interval); if (atr === null) { return null; } let highest = this.#candles[0].high; let lowest = this.#candles[0].low; for (let i = 1; i < this.#candles.length; i++) { if (this.#candles[i].high > highest) { highest = this.#candles[i].high; } if (this.#candles[i].low < lowest) { lowest = this.#candles[i].low; } } return (this.result = { long: highest - this.multiplier * atr, short: lowest + this.multiplier * atr, }); } } //# sourceMappingURL=ChandelierExit.js.map