UNPKG

trading-signals

Version:

Technical indicators to run technical analysis with JavaScript / TypeScript.

63 lines 1.98 kB
import { TradingSignal, TrendIndicatorSeries } from '../../base/Indicator.js'; export class TDS extends TrendIndicatorSeries { closes = []; setupCount = 0; setupDirection = null; getRequiredInputs() { return 9; } update(close, replace) { if (replace) { this.closes.pop(); } this.closes.push(close); if (this.closes.length < 5) { return null; } if (this.closes.length > 13) { this.closes.shift(); } const index = this.closes.length - 1; const prev4 = this.closes[index - 4]; if (close > prev4) { if (this.setupDirection === 'bearish') { this.setupCount = 1; this.setupDirection = 'bullish'; } else { this.setupCount++; this.setupDirection = 'bullish'; } } else if (close < prev4) { if (this.setupDirection === 'bullish') { this.setupCount = 1; this.setupDirection = 'bearish'; } else { this.setupCount++; this.setupDirection = 'bearish'; } } if (this.setupCount >= this.getRequiredInputs()) { const result = this.setupDirection === 'bullish' ? 1 : -1; this.setupCount = 0; this.setupDirection = null; return this.setResult(result, replace); } return null; } calculateSignalState(result) { const hasResult = result !== null && result !== undefined; const isOverbought = hasResult && result === 1; switch (true) { case !hasResult: return TradingSignal.UNKNOWN; case isOverbought: return TradingSignal.BULLISH; default: return TradingSignal.BEARISH; } } } //# sourceMappingURL=TDS.js.map