trading-signals 7.0.0 → 7.1.0

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
@@ -10,6 +10,16 @@ The "trading-signals" library provides a TypeScript implementation for common te
10
10
 
11
11
  All indicators can be updated over time by streaming data (prices or [candles](https://en.wikipedia.org/wiki/Candlestick_chart)) to the `add` method. Some indicators also provide `static` batch methods for further performance improvements when providing data up-front during a backtest or historical data import. You can try it out streaming input data by running the provided [demo script](./src/start/demo.ts) with `npm start`, which uses a keyboard input stream.
12
12
 
13
+ ## Features
14
+
15
+ - **Streaming Updates:** No need to reprocess historical data
16
+ - **Replace Mode:** Efficient live chart updates
17
+ - **Lazy Evaluation:** Indicators only calculate when stable
18
+ - **Memory Efficiency:** Rolling windows, not full history storage
19
+ - **Excellent Test Coverage:** 100% across all metrics
20
+ - **Zero Runtime Dependencies:** Minimal bundle size
21
+ - **Type Safety:** Full TypeScript with strict mode
22
+
13
23
  ## Installation
14
24
 
15
25
  ```bash
@@ -145,6 +155,7 @@ Most of the time, the minimum amount of data depends on the interval / time peri
145
155
  1. Volume-Weighted Average Price (VWAP)
146
156
  1. Weighted Moving Average (WMA)
147
157
  1. Wilder's Smoothed Moving Average (WSMA / WWS / SMMA / MEMA)
158
+ 1. Williams %R (WILLR)
148
159
  1. Zig Zag Indicator (ZigZag)
149
160
 
150
161
  Utility Methods:
@@ -196,13 +207,21 @@ It is very important to do your own analysis before making any investment based
196
207
  - [Technical Analysis Library using Pandas and Numpy (Python)](https://github.com/bukosabino/ta)
197
208
  - [Tulip Indicators (ANSI C)](https://github.com/TulipCharts/tulipindicators)
198
209
 
210
+ ## Documentation
211
+
212
+ Build and run the documentation:
213
+
214
+ ```bash
215
+ npm run docs
216
+ ```
217
+
199
218
  ## Maintainers
200
219
 
201
220
  [![Benny Neugebauer on Stack Exchange][stack_exchange_bennycode_badge]][stack_exchange_bennycode_url]
202
221
 
203
222
  ## ⭐️ Become a TypeScript rockstar! ⭐️
204
223
 
205
- This package was built by Benny Code. Checkout my [**TypeScript course**](https://typescript.tv/) to become a coding rockstar!
224
+ This package was built by Benny Neugebauer. Checkout my [**TypeScript course**](https://typescript.tv/) to become a coding rockstar!
206
225
 
207
226
  [<img src="https://raw.githubusercontent.com/bennycode/trading-signals/main/tstv.png">](https://typescript.tv/)
208
227
 
package/dist/index.cjs CHANGED
@@ -58,6 +58,7 @@ __export(index_exports, {
58
58
  VWAP: () => VWAP,
59
59
  WMA: () => WMA,
60
60
  WSMA: () => WSMA,
61
+ WilliamsR: () => WilliamsR,
61
62
  ZigZag: () => ZigZag,
62
63
  getAverage: () => getAverage,
63
64
  getGrid: () => getGrid,
@@ -851,6 +852,40 @@ var StochasticRSI = class extends IndicatorSeries {
851
852
  }
852
853
  };
853
854
 
855
+ // src/momentum/WILLR/WilliamsR.ts
856
+ var WilliamsR = class extends TechnicalIndicator {
857
+ constructor(interval) {
858
+ super();
859
+ this.interval = interval;
860
+ }
861
+ candles = [];
862
+ getRequiredInputs() {
863
+ return this.interval;
864
+ }
865
+ update(candle, replace) {
866
+ pushUpdate(this.candles, replace, candle, this.interval);
867
+ if (this.candles.length === this.interval) {
868
+ let highest = this.candles[0].high;
869
+ let lowest = this.candles[0].low;
870
+ for (let i = 1; i < this.candles.length; i++) {
871
+ if (this.candles[i].high > highest) {
872
+ highest = this.candles[i].high;
873
+ }
874
+ if (this.candles[i].low < lowest) {
875
+ lowest = this.candles[i].low;
876
+ }
877
+ }
878
+ const divisor = highest - lowest;
879
+ if (divisor === 0) {
880
+ return this.result = -100;
881
+ }
882
+ const willR = (highest - candle.close) / divisor * -100;
883
+ return this.result = willR;
884
+ }
885
+ return null;
886
+ }
887
+ };
888
+
854
889
  // src/volatility/TR/TR.ts
855
890
  var TR = class extends IndicatorSeries {
856
891
  previousCandle;
@@ -1202,16 +1237,14 @@ var PSAR = class extends IndicatorSeries {
1202
1237
  }
1203
1238
  let sar = (this.extreme - this.lastSar) * this.acceleration + this.lastSar;
1204
1239
  if (this.isLong) {
1205
- if (this.previousCandle) {
1206
- const hasPrevPrev = this.prePreviousCandle != null;
1207
- if (hasPrevPrev && low < sar) {
1208
- if (this.prePreviousCandle.low < sar) {
1209
- sar = this.prePreviousCandle.low;
1210
- }
1211
- sar = this.previousCandle.low < sar ? this.previousCandle.low : sar;
1212
- } else if (this.previousCandle.low < sar) {
1213
- sar = this.previousCandle.low;
1240
+ const hasPrevPrev = this.prePreviousCandle != null;
1241
+ if (hasPrevPrev && low < sar) {
1242
+ if (this.prePreviousCandle.low < sar) {
1243
+ sar = this.prePreviousCandle.low;
1214
1244
  }
1245
+ sar = this.previousCandle.low < sar ? this.previousCandle.low : sar;
1246
+ } else if (this.previousCandle.low < sar) {
1247
+ sar = this.previousCandle.low;
1215
1248
  }
1216
1249
  if (high > this.extreme) {
1217
1250
  this.extreme = high;
@@ -1229,24 +1262,20 @@ var PSAR = class extends IndicatorSeries {
1229
1262
  this.acceleration = this.accelerationStep;
1230
1263
  }
1231
1264
  } else {
1232
- if (this.previousCandle) {
1233
- const hasPrevPrev = this.prePreviousCandle != null;
1234
- if (hasPrevPrev && high > sar) {
1235
- if (this.prePreviousCandle.high > sar) {
1236
- sar = this.prePreviousCandle.high;
1237
- }
1238
- sar = this.previousCandle.high > sar ? this.previousCandle.high : sar;
1239
- } else if (this.previousCandle.high > sar) {
1240
- sar = this.previousCandle.high;
1265
+ const hasPrevPrev = this.prePreviousCandle != null;
1266
+ if (hasPrevPrev && high > sar) {
1267
+ if (this.prePreviousCandle.high > sar) {
1268
+ sar = this.prePreviousCandle.high;
1241
1269
  }
1270
+ sar = this.previousCandle.high > sar ? this.previousCandle.high : sar;
1271
+ } else if (this.previousCandle.high > sar) {
1272
+ sar = this.previousCandle.high;
1242
1273
  }
1243
1274
  if (low < this.extreme) {
1244
1275
  this.extreme = low;
1245
- if (this.acceleration < this.accelerationMax) {
1246
- this.acceleration += this.accelerationStep;
1247
- if (this.acceleration > this.accelerationMax) {
1248
- this.acceleration = this.accelerationMax;
1249
- }
1276
+ this.acceleration += this.accelerationStep;
1277
+ if (this.acceleration > this.accelerationMax) {
1278
+ this.acceleration = this.accelerationMax;
1250
1279
  }
1251
1280
  }
1252
1281
  if (high > sar) {
@@ -1265,9 +1294,6 @@ var PSAR = class extends IndicatorSeries {
1265
1294
  return this.setResult(sar, replace);
1266
1295
  }
1267
1296
  getResultOrThrow() {
1268
- if (this.lastSar === null) {
1269
- throw new NotEnoughDataError(this.getRequiredInputs());
1270
- }
1271
1297
  return super.getResultOrThrow();
1272
1298
  }
1273
1299
  };
@@ -1586,6 +1612,7 @@ var IQR = class extends IndicatorSeries {
1586
1612
  VWAP,
1587
1613
  WMA,
1588
1614
  WSMA,
1615
+ WilliamsR,
1589
1616
  ZigZag,
1590
1617
  getAverage,
1591
1618
  getGrid,
package/dist/index.d.cts CHANGED
@@ -260,6 +260,14 @@ declare class StochasticRSI extends IndicatorSeries {
260
260
  update(price: number, replace: boolean): number | null;
261
261
  }
262
262
 
263
+ declare class WilliamsR extends TechnicalIndicator<number, HighLowClose<number>> {
264
+ readonly interval: number;
265
+ readonly candles: HighLowClose<number>[];
266
+ constructor(interval: number);
267
+ getRequiredInputs(): number;
268
+ update(candle: HighLowClose<number>, replace: boolean): number | null;
269
+ }
270
+
263
271
  declare class ADX extends IndicatorSeries<HighLowClose<number>> {
264
272
  readonly interval: number;
265
273
  private readonly dx;
@@ -499,4 +507,4 @@ declare class TR extends IndicatorSeries<HighLowClose<number>> {
499
507
  update(candle: HighLowClose<number>, replace: boolean): number;
500
508
  }
501
509
 
502
- export { AC, ADX, AO, ATR, AccelerationBands, type BandsResult, BaseIndicatorSeries, BollingerBands, BollingerBandsWidth, CCI, CG, DEMA, DMA, type DMAResult, DX, EMA, type GridConfig, type HighLow, type HighLowClose, type HighLowCloseVolume, IQR, IndicatorSeries, LinearRegression, type LinearRegressionResult, MACD, type MACDResult, MAD, MOM, NotEnoughDataError, OBV, type OpenHighLowClose, type OpenHighLowCloseVolume, PSAR, type PSARConfig, Period, type PeriodResult, REI, RMA, ROC, RSI, SMA, SMA15, StochasticOscillator, StochasticRSI, type StochasticResult, type Streak, TDS, TR, TechnicalIndicator, VWAP, WMA, WSMA, ZigZag, type ZigZagConfig, getAverage, getGrid, getMaximum, getMedian, getMinimum, getQuartile, getStandardDeviation, getStreaks, isFriday, isMonday, isSaturday, isSunday, isThursday, isTuesday, isWednesday, pushUpdate };
510
+ export { AC, ADX, AO, ATR, AccelerationBands, type BandsResult, BaseIndicatorSeries, BollingerBands, BollingerBandsWidth, CCI, CG, DEMA, DMA, type DMAResult, DX, EMA, type GridConfig, type HighLow, type HighLowClose, type HighLowCloseVolume, IQR, IndicatorSeries, LinearRegression, type LinearRegressionResult, MACD, type MACDResult, MAD, MOM, NotEnoughDataError, OBV, type OpenHighLowClose, type OpenHighLowCloseVolume, PSAR, type PSARConfig, Period, type PeriodResult, REI, RMA, ROC, RSI, SMA, SMA15, StochasticOscillator, StochasticRSI, type StochasticResult, type Streak, TDS, TR, TechnicalIndicator, VWAP, WMA, WSMA, WilliamsR, ZigZag, type ZigZagConfig, getAverage, getGrid, getMaximum, getMedian, getMinimum, getQuartile, getStandardDeviation, getStreaks, isFriday, isMonday, isSaturday, isSunday, isThursday, isTuesday, isWednesday, pushUpdate };
package/dist/index.d.ts CHANGED
@@ -260,6 +260,14 @@ declare class StochasticRSI extends IndicatorSeries {
260
260
  update(price: number, replace: boolean): number | null;
261
261
  }
262
262
 
263
+ declare class WilliamsR extends TechnicalIndicator<number, HighLowClose<number>> {
264
+ readonly interval: number;
265
+ readonly candles: HighLowClose<number>[];
266
+ constructor(interval: number);
267
+ getRequiredInputs(): number;
268
+ update(candle: HighLowClose<number>, replace: boolean): number | null;
269
+ }
270
+
263
271
  declare class ADX extends IndicatorSeries<HighLowClose<number>> {
264
272
  readonly interval: number;
265
273
  private readonly dx;
@@ -499,4 +507,4 @@ declare class TR extends IndicatorSeries<HighLowClose<number>> {
499
507
  update(candle: HighLowClose<number>, replace: boolean): number;
500
508
  }
501
509
 
502
- export { AC, ADX, AO, ATR, AccelerationBands, type BandsResult, BaseIndicatorSeries, BollingerBands, BollingerBandsWidth, CCI, CG, DEMA, DMA, type DMAResult, DX, EMA, type GridConfig, type HighLow, type HighLowClose, type HighLowCloseVolume, IQR, IndicatorSeries, LinearRegression, type LinearRegressionResult, MACD, type MACDResult, MAD, MOM, NotEnoughDataError, OBV, type OpenHighLowClose, type OpenHighLowCloseVolume, PSAR, type PSARConfig, Period, type PeriodResult, REI, RMA, ROC, RSI, SMA, SMA15, StochasticOscillator, StochasticRSI, type StochasticResult, type Streak, TDS, TR, TechnicalIndicator, VWAP, WMA, WSMA, ZigZag, type ZigZagConfig, getAverage, getGrid, getMaximum, getMedian, getMinimum, getQuartile, getStandardDeviation, getStreaks, isFriday, isMonday, isSaturday, isSunday, isThursday, isTuesday, isWednesday, pushUpdate };
510
+ export { AC, ADX, AO, ATR, AccelerationBands, type BandsResult, BaseIndicatorSeries, BollingerBands, BollingerBandsWidth, CCI, CG, DEMA, DMA, type DMAResult, DX, EMA, type GridConfig, type HighLow, type HighLowClose, type HighLowCloseVolume, IQR, IndicatorSeries, LinearRegression, type LinearRegressionResult, MACD, type MACDResult, MAD, MOM, NotEnoughDataError, OBV, type OpenHighLowClose, type OpenHighLowCloseVolume, PSAR, type PSARConfig, Period, type PeriodResult, REI, RMA, ROC, RSI, SMA, SMA15, StochasticOscillator, StochasticRSI, type StochasticResult, type Streak, TDS, TR, TechnicalIndicator, VWAP, WMA, WSMA, WilliamsR, ZigZag, type ZigZagConfig, getAverage, getGrid, getMaximum, getMedian, getMinimum, getQuartile, getStandardDeviation, getStreaks, isFriday, isMonday, isSaturday, isSunday, isThursday, isTuesday, isWednesday, pushUpdate };
package/dist/index.js CHANGED
@@ -771,6 +771,40 @@ var StochasticRSI = class extends IndicatorSeries {
771
771
  }
772
772
  };
773
773
 
774
+ // src/momentum/WILLR/WilliamsR.ts
775
+ var WilliamsR = class extends TechnicalIndicator {
776
+ constructor(interval) {
777
+ super();
778
+ this.interval = interval;
779
+ }
780
+ candles = [];
781
+ getRequiredInputs() {
782
+ return this.interval;
783
+ }
784
+ update(candle, replace) {
785
+ pushUpdate(this.candles, replace, candle, this.interval);
786
+ if (this.candles.length === this.interval) {
787
+ let highest = this.candles[0].high;
788
+ let lowest = this.candles[0].low;
789
+ for (let i = 1; i < this.candles.length; i++) {
790
+ if (this.candles[i].high > highest) {
791
+ highest = this.candles[i].high;
792
+ }
793
+ if (this.candles[i].low < lowest) {
794
+ lowest = this.candles[i].low;
795
+ }
796
+ }
797
+ const divisor = highest - lowest;
798
+ if (divisor === 0) {
799
+ return this.result = -100;
800
+ }
801
+ const willR = (highest - candle.close) / divisor * -100;
802
+ return this.result = willR;
803
+ }
804
+ return null;
805
+ }
806
+ };
807
+
774
808
  // src/volatility/TR/TR.ts
775
809
  var TR = class extends IndicatorSeries {
776
810
  previousCandle;
@@ -1122,16 +1156,14 @@ var PSAR = class extends IndicatorSeries {
1122
1156
  }
1123
1157
  let sar = (this.extreme - this.lastSar) * this.acceleration + this.lastSar;
1124
1158
  if (this.isLong) {
1125
- if (this.previousCandle) {
1126
- const hasPrevPrev = this.prePreviousCandle != null;
1127
- if (hasPrevPrev && low < sar) {
1128
- if (this.prePreviousCandle.low < sar) {
1129
- sar = this.prePreviousCandle.low;
1130
- }
1131
- sar = this.previousCandle.low < sar ? this.previousCandle.low : sar;
1132
- } else if (this.previousCandle.low < sar) {
1133
- sar = this.previousCandle.low;
1159
+ const hasPrevPrev = this.prePreviousCandle != null;
1160
+ if (hasPrevPrev && low < sar) {
1161
+ if (this.prePreviousCandle.low < sar) {
1162
+ sar = this.prePreviousCandle.low;
1134
1163
  }
1164
+ sar = this.previousCandle.low < sar ? this.previousCandle.low : sar;
1165
+ } else if (this.previousCandle.low < sar) {
1166
+ sar = this.previousCandle.low;
1135
1167
  }
1136
1168
  if (high > this.extreme) {
1137
1169
  this.extreme = high;
@@ -1149,24 +1181,20 @@ var PSAR = class extends IndicatorSeries {
1149
1181
  this.acceleration = this.accelerationStep;
1150
1182
  }
1151
1183
  } else {
1152
- if (this.previousCandle) {
1153
- const hasPrevPrev = this.prePreviousCandle != null;
1154
- if (hasPrevPrev && high > sar) {
1155
- if (this.prePreviousCandle.high > sar) {
1156
- sar = this.prePreviousCandle.high;
1157
- }
1158
- sar = this.previousCandle.high > sar ? this.previousCandle.high : sar;
1159
- } else if (this.previousCandle.high > sar) {
1160
- sar = this.previousCandle.high;
1184
+ const hasPrevPrev = this.prePreviousCandle != null;
1185
+ if (hasPrevPrev && high > sar) {
1186
+ if (this.prePreviousCandle.high > sar) {
1187
+ sar = this.prePreviousCandle.high;
1161
1188
  }
1189
+ sar = this.previousCandle.high > sar ? this.previousCandle.high : sar;
1190
+ } else if (this.previousCandle.high > sar) {
1191
+ sar = this.previousCandle.high;
1162
1192
  }
1163
1193
  if (low < this.extreme) {
1164
1194
  this.extreme = low;
1165
- if (this.acceleration < this.accelerationMax) {
1166
- this.acceleration += this.accelerationStep;
1167
- if (this.acceleration > this.accelerationMax) {
1168
- this.acceleration = this.accelerationMax;
1169
- }
1195
+ this.acceleration += this.accelerationStep;
1196
+ if (this.acceleration > this.accelerationMax) {
1197
+ this.acceleration = this.accelerationMax;
1170
1198
  }
1171
1199
  }
1172
1200
  if (high > sar) {
@@ -1185,9 +1213,6 @@ var PSAR = class extends IndicatorSeries {
1185
1213
  return this.setResult(sar, replace);
1186
1214
  }
1187
1215
  getResultOrThrow() {
1188
- if (this.lastSar === null) {
1189
- throw new NotEnoughDataError(this.getRequiredInputs());
1190
- }
1191
1216
  return super.getResultOrThrow();
1192
1217
  }
1193
1218
  };
@@ -1505,6 +1530,7 @@ export {
1505
1530
  VWAP,
1506
1531
  WMA,
1507
1532
  WSMA,
1533
+ WilliamsR,
1508
1534
  ZigZag,
1509
1535
  getAverage,
1510
1536
  getGrid,
package/package.json CHANGED
@@ -6,8 +6,8 @@
6
6
  "devDependencies": {
7
7
  "@arethetypeswrong/cli": "^0.18.2",
8
8
  "@tstv/eslint-config": "^4.0.0",
9
- "@types/node": "^18.19.124",
10
- "@vitest/coverage-v8": "^3.2.4",
9
+ "@types/node": "^24.9.2",
10
+ "@vitest/coverage-v8": "^4.0.6",
11
11
  "dependency-cruiser": "^17.0.1",
12
12
  "eslint": "^9.35.0",
13
13
  "generate-changelog": "^1.8.0",
@@ -18,10 +18,8 @@
18
18
  "rimraf": "^6.0.1",
19
19
  "tsup": "^8.5.0",
20
20
  "tsx": "^4.20.5",
21
- "typedoc": "^0.28.12",
22
- "typedoc-plugin-markdown": "^4.8.1",
23
21
  "typescript": "^5.9.2",
24
- "vitest": "^3.1.2"
22
+ "vitest": "^4.0.6"
25
23
  },
26
24
  "exports": {
27
25
  ".": {
@@ -73,11 +71,9 @@
73
71
  "scripts": {
74
72
  "build": "tsup",
75
73
  "changelog:commit": "git add CHANGELOG.md && git commit -m \"docs: updated CHANGELOG.md\"",
76
- "clean": "rimraf coverage dist docs",
74
+ "clean": "rimraf coverage dist",
77
75
  "dist": "npm run clean && npm run build",
78
- "docs": "npm run docs:build",
79
- "docs:build": "typedoc src/index.ts",
80
- "docs:release": "npm run docs:build && git add docs/* && git commit -m \"docs: Updated API\"",
76
+ "docs": "npm run dist && cd docs && npm install && npm run dev",
81
77
  "fix": "npm run fix:other && npm run fix:code",
82
78
  "fix:code": "npm run lint:code -- --fix",
83
79
  "fix:other": "npm run prettier -- --write",
@@ -88,9 +84,9 @@
88
84
  "postversion": "git push origin && git push origin --tags && npm publish && git restore .",
89
85
  "prettier": "prettier --ignore-path .gitignore --log-level error \"**/*.{json,scss,yml}\"",
90
86
  "preversion": "git checkout main && git pull && npm install && npm run test && npm run dist && npm run test:exports",
91
- "release:major": "generate-changelog -M -x \"chore,test\" && npm run changelog:commit && npm run docs:release && npm version major",
92
- "release:minor": "generate-changelog -m -x \"chore,test\" && npm run changelog:commit && npm run docs:release && npm version minor",
93
- "release:patch": "generate-changelog -p -x \"chore,test\" && npm run changelog:commit && npm run docs:release && npm version patch",
87
+ "release:major": "generate-changelog -M -x \"chore,test\" && npm run changelog:commit && npm version major",
88
+ "release:minor": "generate-changelog -m -x \"chore,test\" && npm run changelog:commit && npm version minor",
89
+ "release:patch": "generate-changelog -p -x \"chore,test\" && npm run changelog:commit && npm version patch",
94
90
  "start": "tsx ./src/start/demo.ts",
95
91
  "test": "npm run test:types && npm run test:imports && npm run test:units -- --coverage",
96
92
  "test:exports": "attw --pack .",
@@ -100,5 +96,5 @@
100
96
  "test:units:watch": "vitest --watch"
101
97
  },
102
98
  "type": "module",
103
- "version": "7.0.0"
99
+ "version": "7.1.0"
104
100
  }