trading-signals 7.1.0 → 7.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -110,16 +110,69 @@ sma.add(70);
110
110
  console.log(sma.getResultOrThrow()); // 40
111
111
  ```
112
112
 
113
- Most of the time, the minimum amount of data depends on the interval / time period used. If you’re not sure, take a look at the test files for the indicator to see examples of correct usage.
113
+ Most of the time, the minimum amount of data depends on the interval / time period used. If you're not sure, take a look at the test files for the indicator to see examples of correct usage.
114
+
115
+ ### When to use `getRequiredInputs()`?
116
+
117
+ Every indicator provides a `getRequiredInputs()` method that returns the minimum number of input values needed before the indicator becomes stable and can produce results. This is useful for validation and understanding when an indicator will start producing return values.
118
+
119
+ **Example:**
120
+
121
+ ```ts
122
+ import {SMA, EMA, RSI} from 'trading-signals';
123
+
124
+ const sma = new SMA(5);
125
+ console.log(sma.getRequiredInputs()); // 5
126
+ ```
127
+
128
+ The required inputs often depend on the indicator's configuration (like interval/period) and its internal calculation requirements. Some indicators like **MACD** or **Stochastic Oscillator** may require more inputs than their primary period because they use multiple moving averages or lookback periods internally.
129
+
130
+ ### When to use `getSignal()`?
131
+
132
+ Many momentum and trend indicators provide a `getSignal()` method that returns the current trading signal state along with change detection. This is useful for identifying potential trading opportunities.
133
+
134
+ **Example:**
135
+
136
+ ```ts
137
+ import {RSI} from 'trading-signals';
138
+
139
+ const rsi = new RSI(14);
140
+
141
+ // Add price data
142
+ // ...
143
+
144
+ // Get the trading signal
145
+ const signal = rsi.getSignal();
146
+ console.log(signal.state); // "BEARISH", "BULLISH", "SIDEWAYS", or "UNKNOWN"
147
+ console.log(signal.hasChanged); // true if the signal state changed from the previous value
148
+ ```
114
149
 
115
150
  ## Technical Indicator Types
116
151
 
117
- - Exhaustion indicators: Identify trend exhaustion and potential reversal.
118
- - Momentum indicators: Measure the speed and strength of price movements in a particular direction
119
- - Trend indicators: Measure the direction of a trend (uptrend, downtrend or sideways trend)
152
+ ### Indicator Function
153
+
154
+ - Momentum indicators: Measure the speed and strength (intensity) of price movements in a particular direction (overbought/oversold)
155
+ - Trend indicators: Measure the direction of a trend (bullish/bearish)
120
156
  - Volatility indicators: Measure the degree of variation in prices over time, regardless of direction
121
157
  - Volume indicators: Measure the strength of a trend based on volume
122
158
 
159
+ **Key readings:**
160
+
161
+ - Bullish sentiment: expect prices to rise
162
+ - Bearish sentiment: expect prices to fall
163
+ - Overbought condition: price may have risen too much too fast, meaning it’s trending up, but traders expect a short-term dip before continuing higher
164
+ - Oversold condition: price may have dropped too much too fast, meaning it’s trending down, but traders expect a short-term bounce before continuing lower or reversing upward
165
+
166
+ ### Indicator Timing
167
+
168
+ - Leading Indicators: Predictive tools that try to signal future price movements before they happen (i.e. RSI, Stochastic Oscillator, Volume spikes)
169
+ - Lagging Indicators: Confirmative tools that signal after a trend or move has already started (i.e. Moving Averages, MACD, ADX)
170
+
171
+ ### Indicator Scale
172
+
173
+ - Indicators: Have no upper or lower limits
174
+ - Oscillators: Move within a fixed range (e.g. 0-100, –1 to +1)
175
+
123
176
  ## Supported Technical Indicators
124
177
 
125
178
  1. Acceleration Bands (ABANDS)
@@ -176,7 +229,7 @@ Utility Methods:
176
229
 
177
230
  JavaScript uses double-precision floating-point arithmetic. For example, `0.1 + 0.2` yields `0.30000000000000004` due to binary floating-point representation.
178
231
 
179
- ![JavaScript arithmetic](https://raw.githubusercontent.com/bennycode/trading-signals/HEAD/js-arithmetic.png)
232
+ ![JavaScript arithmetic](https://raw.githubusercontent.com/bennycode/trading-signals/main/packages/trading-signals/js-arithmetic.png)
180
233
 
181
234
  While this isn’t perfectly accurate, it usually doesn’t matter in practice since indicators often work with averages, which already smooth out precision. In test cases, you can control precision by using Vitest’s [toBeCloseTo](https://vitest.dev/api/expect.html#tobecloseto) assertion.
182
235
 
@@ -223,7 +276,7 @@ npm run docs
223
276
 
224
277
  This package was built by Benny Neugebauer. Checkout my [**TypeScript course**](https://typescript.tv/) to become a coding rockstar!
225
278
 
226
- [<img src="https://raw.githubusercontent.com/bennycode/trading-signals/main/tstv.png">](https://typescript.tv/)
279
+ [<img src="https://raw.githubusercontent.com/bennycode/trading-signals/main/packages/trading-signals/tstv.png">](https://typescript.tv/)
227
280
 
228
281
  [1]: http://mikemcl.github.io/big.js/
229
282
  [stack_exchange_bennycode_badge]: https://stackexchange.com/users/flair/203782.png?theme=default
package/dist/index.cjs CHANGED
@@ -25,7 +25,6 @@ __export(index_exports, {
25
25
  AO: () => AO,
26
26
  ATR: () => ATR,
27
27
  AccelerationBands: () => AccelerationBands,
28
- BaseIndicatorSeries: () => BaseIndicatorSeries,
29
28
  BollingerBands: () => BollingerBands,
30
29
  BollingerBandsWidth: () => BollingerBandsWidth,
31
30
  CCI: () => CCI,
@@ -55,6 +54,8 @@ __export(index_exports, {
55
54
  TDS: () => TDS,
56
55
  TR: () => TR,
57
56
  TechnicalIndicator: () => TechnicalIndicator,
57
+ TradingSignal: () => TradingSignal,
58
+ TrendIndicatorSeries: () => TrendIndicatorSeries,
58
59
  VWAP: () => VWAP,
59
60
  WMA: () => WMA,
60
61
  WSMA: () => WSMA,
@@ -89,6 +90,12 @@ var NotEnoughDataError = class extends Error {
89
90
  };
90
91
 
91
92
  // src/types/Indicator.ts
93
+ var TradingSignal = {
94
+ BEARISH: "BEARISH",
95
+ BULLISH: "BULLISH",
96
+ SIDEWAYS: "SIDEWAYS",
97
+ UNKNOWN: "UNKNOWN"
98
+ };
92
99
  var TechnicalIndicator = class {
93
100
  result;
94
101
  getResult() {
@@ -117,10 +124,8 @@ var TechnicalIndicator = class {
117
124
  return inputs.map((input) => this.update(input, replace));
118
125
  }
119
126
  };
120
- var BaseIndicatorSeries = class extends TechnicalIndicator {
127
+ var IndicatorSeries = class extends TechnicalIndicator {
121
128
  previousResult;
122
- };
123
- var IndicatorSeries = class extends BaseIndicatorSeries {
124
129
  setResult(value, replace) {
125
130
  if (replace) {
126
131
  this.result = this.previousResult;
@@ -129,52 +134,23 @@ var IndicatorSeries = class extends BaseIndicatorSeries {
129
134
  return this.result = value;
130
135
  }
131
136
  };
132
-
133
- // src/exhaustion/TDS/TDS.ts
134
- var TDS = class extends IndicatorSeries {
135
- closes = [];
136
- setupCount = 0;
137
- setupDirection = null;
138
- getRequiredInputs() {
139
- return 9;
140
- }
141
- update(close, replace) {
142
- if (replace) {
143
- this.closes.pop();
144
- }
145
- this.closes.push(close);
146
- if (this.closes.length < 5) {
147
- return null;
148
- }
149
- if (this.closes.length > 13) {
150
- this.closes.shift();
151
- }
152
- const index = this.closes.length - 1;
153
- const prev4 = this.closes[index - 4];
154
- if (close > prev4) {
155
- if (this.setupDirection === "bearish") {
156
- this.setupCount = 1;
157
- this.setupDirection = "bullish";
158
- } else {
159
- this.setupCount++;
160
- this.setupDirection = "bullish";
161
- }
162
- } else if (close < prev4) {
163
- if (this.setupDirection === "bullish") {
164
- this.setupCount = 1;
165
- this.setupDirection = "bearish";
166
- } else {
167
- this.setupCount++;
168
- this.setupDirection = "bearish";
169
- }
170
- }
171
- if (this.setupCount >= this.getRequiredInputs()) {
172
- const result = this.setupDirection === "bullish" ? 1 : -1;
173
- this.setupCount = 0;
174
- this.setupDirection = null;
175
- return this.setResult(result, replace);
137
+ var TrendIndicatorSeries = class extends IndicatorSeries {
138
+ previousSignalState;
139
+ setResult(value, replace) {
140
+ if (replace && this.previousResult !== void 0) {
141
+ this.previousSignalState = this.calculateSignalState(this.previousResult);
142
+ } else if (!replace) {
143
+ this.previousSignalState = this.calculateSignalState(this.result);
176
144
  }
177
- return null;
145
+ return super.setResult(value, replace);
146
+ }
147
+ getSignal() {
148
+ const currentState = this.calculateSignalState(this.getResult());
149
+ const hasChanged = this.previousSignalState !== void 0 && this.previousSignalState !== currentState;
150
+ return {
151
+ hasChanged,
152
+ state: currentState
153
+ };
178
154
  }
179
155
  };
180
156
 
@@ -220,7 +196,7 @@ var SMA = class extends MovingAverage {
220
196
  };
221
197
 
222
198
  // src/momentum/AO/AO.ts
223
- var AO = class extends IndicatorSeries {
199
+ var AO = class extends TrendIndicatorSeries {
224
200
  constructor(shortInterval, longInterval, SmoothingIndicator = SMA) {
225
201
  super();
226
202
  this.shortInterval = shortInterval;
@@ -242,6 +218,21 @@ var AO = class extends IndicatorSeries {
242
218
  }
243
219
  return null;
244
220
  }
221
+ calculateSignalState(result) {
222
+ const hasResult = result !== null && result !== void 0;
223
+ const isBullish = hasResult && result > 0;
224
+ const isBearish = hasResult && result < 0;
225
+ switch (true) {
226
+ case !hasResult:
227
+ return TradingSignal.UNKNOWN;
228
+ case isBullish:
229
+ return TradingSignal.BULLISH;
230
+ case isBearish:
231
+ return TradingSignal.BEARISH;
232
+ default:
233
+ return TradingSignal.SIDEWAYS;
234
+ }
235
+ }
245
236
  };
246
237
 
247
238
  // src/momentum/MOM/MOM.ts
@@ -267,7 +258,7 @@ var MOM = class extends IndicatorSeries {
267
258
  };
268
259
 
269
260
  // src/momentum/AC/AC.ts
270
- var AC = class extends IndicatorSeries {
261
+ var AC = class extends TrendIndicatorSeries {
271
262
  constructor(shortAO, longAO, signalInterval) {
272
263
  super();
273
264
  this.shortAO = shortAO;
@@ -281,7 +272,7 @@ var AC = class extends IndicatorSeries {
281
272
  momentum;
282
273
  signal;
283
274
  getRequiredInputs() {
284
- return this.signal.getRequiredInputs();
275
+ return this.ao.getRequiredInputs() + this.signal.getRequiredInputs();
285
276
  }
286
277
  update(input, replace) {
287
278
  const ao = this.ao.update(input, replace);
@@ -295,6 +286,18 @@ var AC = class extends IndicatorSeries {
295
286
  }
296
287
  return null;
297
288
  }
289
+ calculateSignalState(result) {
290
+ const hasResult = result !== null && result !== void 0;
291
+ const isPositive = hasResult && result > 0;
292
+ switch (true) {
293
+ case !hasResult:
294
+ return TradingSignal.UNKNOWN;
295
+ case isPositive:
296
+ return TradingSignal.BULLISH;
297
+ default:
298
+ return TradingSignal.BEARISH;
299
+ }
300
+ }
298
301
  };
299
302
 
300
303
  // src/util/getGrid.ts
@@ -474,7 +477,7 @@ var MAD = class extends IndicatorSeries {
474
477
  };
475
478
 
476
479
  // src/momentum/CCI/CCI.ts
477
- var CCI = class extends IndicatorSeries {
480
+ var CCI = class extends TrendIndicatorSeries {
478
481
  constructor(interval) {
479
482
  super();
480
483
  this.interval = interval;
@@ -503,10 +506,25 @@ var CCI = class extends IndicatorSeries {
503
506
  pushUpdate(this.typicalPrices, replace, typicalPrice, this.interval);
504
507
  return typicalPrice;
505
508
  }
509
+ calculateSignalState(result) {
510
+ const hasResult = result !== null && result !== void 0;
511
+ const isOversold = hasResult && result <= -100;
512
+ const isOverbought = hasResult && result >= 100;
513
+ switch (true) {
514
+ case !hasResult:
515
+ return TradingSignal.UNKNOWN;
516
+ case isOversold:
517
+ return TradingSignal.BEARISH;
518
+ case isOverbought:
519
+ return TradingSignal.BULLISH;
520
+ default:
521
+ return TradingSignal.SIDEWAYS;
522
+ }
523
+ }
506
524
  };
507
525
 
508
526
  // src/momentum/CG/CG.ts
509
- var CG = class extends IndicatorSeries {
527
+ var CG = class extends TrendIndicatorSeries {
510
528
  constructor(interval, signalInterval) {
511
529
  super();
512
530
  this.interval = interval;
@@ -521,6 +539,23 @@ var CG = class extends IndicatorSeries {
521
539
  getRequiredInputs() {
522
540
  return this.signal.getRequiredInputs();
523
541
  }
542
+ calculateSignalState(result) {
543
+ const hasResult = result !== null && result !== void 0;
544
+ const signalValue = this.signal.getResult();
545
+ const hasSignal = signalValue !== null;
546
+ const isAboveSignal = hasResult && hasSignal && result > signalValue;
547
+ const isBelowSignal = hasResult && hasSignal && result < signalValue;
548
+ switch (true) {
549
+ case (!hasResult || !hasSignal):
550
+ return TradingSignal.UNKNOWN;
551
+ case isAboveSignal:
552
+ return TradingSignal.BULLISH;
553
+ case isBelowSignal:
554
+ return TradingSignal.BEARISH;
555
+ default:
556
+ return TradingSignal.SIDEWAYS;
557
+ }
558
+ }
524
559
  update(price, replace) {
525
560
  pushUpdate(this.prices, replace, price, this.interval);
526
561
  let nominator = 0;
@@ -548,6 +583,7 @@ var MACD = class extends TechnicalIndicator {
548
583
  this.signal = signal;
549
584
  }
550
585
  prices = [];
586
+ previousResult;
551
587
  getRequiredInputs() {
552
588
  return this.long.getRequiredInputs();
553
589
  }
@@ -558,6 +594,10 @@ var MACD = class extends TechnicalIndicator {
558
594
  if (this.prices.length === this.long.interval) {
559
595
  const macd = short - long;
560
596
  const signal = this.signal.update(macd, replace);
597
+ if (replace) {
598
+ this.result = this.previousResult;
599
+ }
600
+ this.previousResult = this.result;
561
601
  return this.result = {
562
602
  histogram: macd - signal,
563
603
  macd,
@@ -566,17 +606,44 @@ var MACD = class extends TechnicalIndicator {
566
606
  }
567
607
  return null;
568
608
  }
609
+ calculateSignal(result) {
610
+ const hasResult = result !== null && result !== void 0;
611
+ const isBullish = hasResult && result.histogram > 0;
612
+ const isBearish = hasResult && result.histogram < 0;
613
+ switch (true) {
614
+ case !hasResult:
615
+ return TradingSignal.UNKNOWN;
616
+ case isBullish:
617
+ return TradingSignal.BULLISH;
618
+ case isBearish:
619
+ default:
620
+ return TradingSignal.BEARISH;
621
+ }
622
+ }
623
+ getSignal() {
624
+ const previousState = this.calculateSignal(this.previousResult);
625
+ const state = this.calculateSignal(this.getResult());
626
+ const hasChanged = previousState !== state;
627
+ return {
628
+ hasChanged,
629
+ state
630
+ };
631
+ }
569
632
  };
570
633
 
571
634
  // src/momentum/OBV/OBV.ts
572
- var OBV = class extends IndicatorSeries {
635
+ var OBV = class extends TrendIndicatorSeries {
636
+ constructor(interval) {
637
+ super();
638
+ this.interval = interval;
639
+ }
573
640
  candles = [];
574
641
  getRequiredInputs() {
575
- return 2;
642
+ return this.interval;
576
643
  }
577
644
  update(candle, replace) {
578
- pushUpdate(this.candles, replace, candle, 2);
579
- if (this.candles.length === 1) {
645
+ pushUpdate(this.candles, replace, candle, this.getRequiredInputs());
646
+ if (this.candles.length < this.getRequiredInputs()) {
580
647
  return null;
581
648
  }
582
649
  const prevCandle = this.candles[this.candles.length - 2];
@@ -586,10 +653,27 @@ var OBV = class extends IndicatorSeries {
586
653
  const nextResult = currentPrice > prevPrice ? candle.volume : currentPrice < prevPrice ? -candle.volume : 0;
587
654
  return this.setResult(prevResult + nextResult, false);
588
655
  }
656
+ calculateSignalState(result) {
657
+ const hasResult = result !== null && result !== void 0;
658
+ const previousResult = this.previousResult;
659
+ const hasPreviousResult = previousResult !== void 0;
660
+ const isBullish = hasResult && hasPreviousResult && result > previousResult;
661
+ const isBearish = hasResult && hasPreviousResult && result < previousResult;
662
+ switch (true) {
663
+ case !hasResult:
664
+ return TradingSignal.UNKNOWN;
665
+ case isBullish:
666
+ return TradingSignal.BULLISH;
667
+ case isBearish:
668
+ return TradingSignal.BEARISH;
669
+ default:
670
+ return TradingSignal.SIDEWAYS;
671
+ }
672
+ }
589
673
  };
590
674
 
591
675
  // src/momentum/REI/REI.ts
592
- var REI = class extends IndicatorSeries {
676
+ var REI = class extends TrendIndicatorSeries {
593
677
  constructor(interval) {
594
678
  super();
595
679
  this.interval = interval;
@@ -597,6 +681,21 @@ var REI = class extends IndicatorSeries {
597
681
  highs = [];
598
682
  lows = [];
599
683
  closes = [];
684
+ calculateSignalState(result) {
685
+ const hasResult = result !== null && result !== void 0;
686
+ const isOverbought = hasResult && result > 60;
687
+ const isOversold = hasResult && result < -60;
688
+ switch (true) {
689
+ case !hasResult:
690
+ return TradingSignal.UNKNOWN;
691
+ case isOverbought:
692
+ return TradingSignal.BULLISH;
693
+ case isOversold:
694
+ return TradingSignal.BEARISH;
695
+ default:
696
+ return TradingSignal.SIDEWAYS;
697
+ }
698
+ }
600
699
  getRequiredInputs() {
601
700
  return this.interval + 8;
602
701
  }
@@ -647,7 +746,7 @@ var REI = class extends IndicatorSeries {
647
746
  };
648
747
 
649
748
  // src/momentum/ROC/ROC.ts
650
- var ROC = class extends IndicatorSeries {
749
+ var ROC = class extends TrendIndicatorSeries {
651
750
  constructor(interval) {
652
751
  super();
653
752
  this.interval = interval;
@@ -663,6 +762,18 @@ var ROC = class extends IndicatorSeries {
663
762
  }
664
763
  return null;
665
764
  }
765
+ calculateSignalState(result) {
766
+ const hasResult = result !== null && result !== void 0;
767
+ const isBearish = hasResult && result < 0;
768
+ switch (true) {
769
+ case !hasResult:
770
+ return TradingSignal.UNKNOWN;
771
+ case isBearish:
772
+ return TradingSignal.BEARISH;
773
+ default:
774
+ return TradingSignal.BULLISH;
775
+ }
776
+ }
666
777
  };
667
778
 
668
779
  // src/trend/WSMA/WSMA.ts
@@ -694,7 +805,7 @@ var WSMA = class extends IndicatorSeries {
694
805
  };
695
806
 
696
807
  // src/momentum/RSI/RSI.ts
697
- var RSI = class extends IndicatorSeries {
808
+ var RSI = class extends TrendIndicatorSeries {
698
809
  constructor(interval, SmoothingIndicator = WSMA) {
699
810
  super();
700
811
  this.interval = interval;
@@ -732,6 +843,21 @@ var RSI = class extends IndicatorSeries {
732
843
  }
733
844
  return null;
734
845
  }
846
+ calculateSignalState(result) {
847
+ const hasResult = result !== null && result !== void 0;
848
+ const isOversold = hasResult && result <= 30;
849
+ const isOverbought = hasResult && result >= 70;
850
+ switch (true) {
851
+ case !hasResult:
852
+ return TradingSignal.UNKNOWN;
853
+ case isOversold:
854
+ return TradingSignal.BEARISH;
855
+ case isOverbought:
856
+ return TradingSignal.BULLISH;
857
+ default:
858
+ return TradingSignal.SIDEWAYS;
859
+ }
860
+ }
735
861
  };
736
862
 
737
863
  // src/momentum/STOCH/StochasticOscillator.ts
@@ -752,6 +878,7 @@ var StochasticOscillator = class extends TechnicalIndicator {
752
878
  candles = [];
753
879
  periodM;
754
880
  periodP;
881
+ previousResult;
755
882
  getRequiredInputs() {
756
883
  return this.n + this.p + 1;
757
884
  }
@@ -766,6 +893,10 @@ var StochasticOscillator = class extends TechnicalIndicator {
766
893
  const stochK = this.periodM.update(fastK, replace);
767
894
  const stochD = stochK && this.periodP.update(stochK, replace);
768
895
  if (stochK !== null && stochD !== null) {
896
+ if (replace) {
897
+ this.result = this.previousResult;
898
+ }
899
+ this.previousResult = this.result;
769
900
  return this.result = {
770
901
  stochD,
771
902
  stochK
@@ -774,6 +905,30 @@ var StochasticOscillator = class extends TechnicalIndicator {
774
905
  }
775
906
  return null;
776
907
  }
908
+ calculateSignal(result) {
909
+ const hasResult = result !== null && result !== void 0;
910
+ const isOversold = hasResult && result.stochK <= 20;
911
+ const isOverbought = hasResult && result.stochK >= 80;
912
+ switch (true) {
913
+ case !hasResult:
914
+ return TradingSignal.UNKNOWN;
915
+ case isOversold:
916
+ return TradingSignal.BEARISH;
917
+ case isOverbought:
918
+ return TradingSignal.BULLISH;
919
+ default:
920
+ return TradingSignal.SIDEWAYS;
921
+ }
922
+ }
923
+ getSignal() {
924
+ const previousState = this.calculateSignal(this.previousResult);
925
+ const state = this.calculateSignal(this.getResult());
926
+ const hasChanged = previousState !== state;
927
+ return {
928
+ hasChanged,
929
+ state
930
+ };
931
+ }
777
932
  };
778
933
 
779
934
  // src/types/Period.ts
@@ -812,7 +967,7 @@ var Period = class extends TechnicalIndicator {
812
967
  };
813
968
 
814
969
  // src/momentum/STOCHRSI/StochasticRSI.ts
815
- var StochasticRSI = class extends IndicatorSeries {
970
+ var StochasticRSI = class extends TrendIndicatorSeries {
816
971
  constructor(interval, SmoothingRSI = WSMA, smoothing = {
817
972
  d: new SMA(3),
818
973
  k: new SMA(3)
@@ -850,10 +1005,85 @@ var StochasticRSI = class extends IndicatorSeries {
850
1005
  }
851
1006
  return null;
852
1007
  }
1008
+ calculateSignalState(result) {
1009
+ const hasResult = result !== null && result !== void 0;
1010
+ const isOversold = hasResult && result <= 0.2;
1011
+ const isOverbought = hasResult && result >= 0.8;
1012
+ switch (true) {
1013
+ case !hasResult:
1014
+ return TradingSignal.UNKNOWN;
1015
+ case isOversold:
1016
+ return TradingSignal.BEARISH;
1017
+ case isOverbought:
1018
+ return TradingSignal.BULLISH;
1019
+ default:
1020
+ return TradingSignal.SIDEWAYS;
1021
+ }
1022
+ }
1023
+ };
1024
+
1025
+ // src/momentum/TDS/TDS.ts
1026
+ var TDS = class extends TrendIndicatorSeries {
1027
+ closes = [];
1028
+ setupCount = 0;
1029
+ setupDirection = null;
1030
+ getRequiredInputs() {
1031
+ return 9;
1032
+ }
1033
+ update(close, replace) {
1034
+ if (replace) {
1035
+ this.closes.pop();
1036
+ }
1037
+ this.closes.push(close);
1038
+ if (this.closes.length < 5) {
1039
+ return null;
1040
+ }
1041
+ if (this.closes.length > 13) {
1042
+ this.closes.shift();
1043
+ }
1044
+ const index = this.closes.length - 1;
1045
+ const prev4 = this.closes[index - 4];
1046
+ if (close > prev4) {
1047
+ if (this.setupDirection === "bearish") {
1048
+ this.setupCount = 1;
1049
+ this.setupDirection = "bullish";
1050
+ } else {
1051
+ this.setupCount++;
1052
+ this.setupDirection = "bullish";
1053
+ }
1054
+ } else if (close < prev4) {
1055
+ if (this.setupDirection === "bullish") {
1056
+ this.setupCount = 1;
1057
+ this.setupDirection = "bearish";
1058
+ } else {
1059
+ this.setupCount++;
1060
+ this.setupDirection = "bearish";
1061
+ }
1062
+ }
1063
+ if (this.setupCount >= this.getRequiredInputs()) {
1064
+ const result = this.setupDirection === "bullish" ? 1 : -1;
1065
+ this.setupCount = 0;
1066
+ this.setupDirection = null;
1067
+ return this.setResult(result, replace);
1068
+ }
1069
+ return null;
1070
+ }
1071
+ calculateSignalState(result) {
1072
+ const hasResult = result !== null && result !== void 0;
1073
+ const isOverbought = hasResult && result === 1;
1074
+ switch (true) {
1075
+ case !hasResult:
1076
+ return TradingSignal.UNKNOWN;
1077
+ case isOverbought:
1078
+ return TradingSignal.BULLISH;
1079
+ default:
1080
+ return TradingSignal.BEARISH;
1081
+ }
1082
+ }
853
1083
  };
854
1084
 
855
1085
  // src/momentum/WILLR/WilliamsR.ts
856
- var WilliamsR = class extends TechnicalIndicator {
1086
+ var WilliamsR = class extends TrendIndicatorSeries {
857
1087
  constructor(interval) {
858
1088
  super();
859
1089
  this.interval = interval;
@@ -877,13 +1107,28 @@ var WilliamsR = class extends TechnicalIndicator {
877
1107
  }
878
1108
  const divisor = highest - lowest;
879
1109
  if (divisor === 0) {
880
- return this.result = -100;
1110
+ return this.setResult(-100, replace);
881
1111
  }
882
1112
  const willR = (highest - candle.close) / divisor * -100;
883
- return this.result = willR;
1113
+ return this.setResult(willR, replace);
884
1114
  }
885
1115
  return null;
886
1116
  }
1117
+ calculateSignalState(result) {
1118
+ const hasResult = result !== null && result !== void 0;
1119
+ const isOverbought = hasResult && result >= -20;
1120
+ const isOversold = hasResult && result <= -80;
1121
+ switch (true) {
1122
+ case !hasResult:
1123
+ return TradingSignal.UNKNOWN;
1124
+ case isOverbought:
1125
+ return TradingSignal.BULLISH;
1126
+ case isOversold:
1127
+ return TradingSignal.BEARISH;
1128
+ default:
1129
+ return TradingSignal.SIDEWAYS;
1130
+ }
1131
+ }
887
1132
  };
888
1133
 
889
1134
  // src/volatility/TR/TR.ts
@@ -1579,7 +1824,6 @@ var IQR = class extends IndicatorSeries {
1579
1824
  AO,
1580
1825
  ATR,
1581
1826
  AccelerationBands,
1582
- BaseIndicatorSeries,
1583
1827
  BollingerBands,
1584
1828
  BollingerBandsWidth,
1585
1829
  CCI,
@@ -1609,6 +1853,8 @@ var IQR = class extends IndicatorSeries {
1609
1853
  TDS,
1610
1854
  TR,
1611
1855
  TechnicalIndicator,
1856
+ TradingSignal,
1857
+ TrendIndicatorSeries,
1612
1858
  VWAP,
1613
1859
  WMA,
1614
1860
  WSMA,