trading-signals 5.0.4 → 6.0.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 +88 -70
- package/dist/index.cjs +1792 -0
- package/dist/index.d.cts +620 -0
- package/dist/index.d.ts +619 -30
- package/dist/index.js +1690 -32
- package/package.json +22 -10
- package/dist/ABANDS/AccelerationBands.d.ts +0 -26
- package/dist/ABANDS/AccelerationBands.js +0 -72
- package/dist/ABANDS/AccelerationBands.js.map +0 -1
- package/dist/AC/AC.d.ts +0 -26
- package/dist/AC/AC.js +0 -61
- package/dist/AC/AC.js.map +0 -1
- package/dist/ADX/ADX.d.ts +0 -22
- package/dist/ADX/ADX.js +0 -56
- package/dist/ADX/ADX.js.map +0 -1
- package/dist/AO/AO.d.ts +0 -21
- package/dist/AO/AO.js +0 -47
- package/dist/AO/AO.js.map +0 -1
- package/dist/ATR/ATR.d.ts +0 -18
- package/dist/ATR/ATR.js +0 -40
- package/dist/ATR/ATR.js.map +0 -1
- package/dist/BBANDS/BollingerBands.d.ts +0 -23
- package/dist/BBANDS/BollingerBands.js +0 -69
- package/dist/BBANDS/BollingerBands.js.map +0 -1
- package/dist/BBW/BollingerBandsWidth.d.ts +0 -13
- package/dist/BBW/BollingerBandsWidth.js +0 -28
- package/dist/BBW/BollingerBandsWidth.js.map +0 -1
- package/dist/CCI/CCI.d.ts +0 -21
- package/dist/CCI/CCI.js +0 -65
- package/dist/CCI/CCI.js.map +0 -1
- package/dist/CG/CG.d.ts +0 -21
- package/dist/CG/CG.js +0 -80
- package/dist/CG/CG.js.map +0 -1
- package/dist/DEMA/DEMA.d.ts +0 -18
- package/dist/DEMA/DEMA.js +0 -41
- package/dist/DEMA/DEMA.js.map +0 -1
- package/dist/DMA/DMA.d.ts +0 -28
- package/dist/DMA/DMA.js +0 -44
- package/dist/DMA/DMA.js.map +0 -1
- package/dist/DX/DX.d.ts +0 -28
- package/dist/DX/DX.js +0 -107
- package/dist/DX/DX.js.map +0 -1
- package/dist/EMA/EMA.d.ts +0 -20
- package/dist/EMA/EMA.js +0 -79
- package/dist/EMA/EMA.js.map +0 -1
- package/dist/Indicator.d.ts +0 -36
- package/dist/Indicator.js +0 -100
- package/dist/Indicator.js.map +0 -1
- package/dist/MA/MovingAverage.d.ts +0 -16
- package/dist/MA/MovingAverage.js +0 -30
- package/dist/MA/MovingAverage.js.map +0 -1
- package/dist/MA/MovingAverageTypes.d.ts +0 -5
- package/dist/MA/MovingAverageTypes.js +0 -2
- package/dist/MA/MovingAverageTypes.js.map +0 -1
- package/dist/MACD/MACD.d.ts +0 -41
- package/dist/MACD/MACD.js +0 -89
- package/dist/MACD/MACD.js.map +0 -1
- package/dist/MAD/MAD.d.ts +0 -16
- package/dist/MAD/MAD.js +0 -72
- package/dist/MAD/MAD.js.map +0 -1
- package/dist/MOM/MOM.d.ts +0 -16
- package/dist/MOM/MOM.js +0 -48
- package/dist/MOM/MOM.js.map +0 -1
- package/dist/OBV/OBV.d.ts +0 -11
- package/dist/OBV/OBV.js +0 -33
- package/dist/OBV/OBV.js.map +0 -1
- package/dist/ROC/ROC.d.ts +0 -14
- package/dist/ROC/ROC.js +0 -33
- package/dist/ROC/ROC.js.map +0 -1
- package/dist/RSI/RSI.d.ts +0 -21
- package/dist/RSI/RSI.js +0 -88
- package/dist/RSI/RSI.js.map +0 -1
- package/dist/SMA/SMA.d.ts +0 -11
- package/dist/SMA/SMA.js +0 -42
- package/dist/SMA/SMA.js.map +0 -1
- package/dist/STOCH/StochasticOscillator.d.ts +0 -37
- package/dist/STOCH/StochasticOscillator.js +0 -98
- package/dist/STOCH/StochasticOscillator.js.map +0 -1
- package/dist/STOCH/StochasticRSI.d.ts +0 -17
- package/dist/STOCH/StochasticRSI.js +0 -60
- package/dist/STOCH/StochasticRSI.js.map +0 -1
- package/dist/TR/TR.d.ts +0 -13
- package/dist/TR/TR.js +0 -46
- package/dist/TR/TR.js.map +0 -1
- package/dist/WMA/WMA.d.ts +0 -14
- package/dist/WMA/WMA.js +0 -59
- package/dist/WMA/WMA.js.map +0 -1
- package/dist/WSMA/WSMA.d.ts +0 -19
- package/dist/WSMA/WSMA.js +0 -63
- package/dist/WSMA/WSMA.js.map +0 -1
- package/dist/error/NotEnoughDataError.d.ts +0 -3
- package/dist/error/NotEnoughDataError.js +0 -8
- package/dist/error/NotEnoughDataError.js.map +0 -1
- package/dist/error/index.d.ts +0 -1
- package/dist/error/index.js +0 -2
- package/dist/error/index.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/util/BandsResult.d.ts +0 -11
- package/dist/util/BandsResult.js +0 -2
- package/dist/util/BandsResult.js.map +0 -1
- package/dist/util/HighLowClose.d.ts +0 -27
- package/dist/util/HighLowClose.js +0 -2
- package/dist/util/HighLowClose.js.map +0 -1
- package/dist/util/Period.d.ts +0 -30
- package/dist/util/Period.js +0 -59
- package/dist/util/Period.js.map +0 -1
- package/dist/util/getAverage.d.ts +0 -3
- package/dist/util/getAverage.js +0 -11
- package/dist/util/getAverage.js.map +0 -1
- package/dist/util/getFixedArray.d.ts +0 -1
- package/dist/util/getFixedArray.js +0 -14
- package/dist/util/getFixedArray.js.map +0 -1
- package/dist/util/getMaximum.d.ts +0 -2
- package/dist/util/getMaximum.js +0 -11
- package/dist/util/getMaximum.js.map +0 -1
- package/dist/util/getMinimum.d.ts +0 -2
- package/dist/util/getMinimum.js +0 -11
- package/dist/util/getMinimum.js.map +0 -1
- package/dist/util/getStandardDeviation.d.ts +0 -3
- package/dist/util/getStandardDeviation.js +0 -14
- package/dist/util/getStandardDeviation.js.map +0 -1
- package/dist/util/index.d.ts +0 -8
- package/dist/util/index.js +0 -9
- package/dist/util/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -12,98 +12,75 @@ The main focus of this library is on the accuracy of calculations, but using the
|
|
|
12
12
|
|
|
13
13
|
All indicators can be updated over time by streaming data (prices or candles) to the `update` method. Some indicators also provide `static` batch methods for further performance improvements when providing data up-front during a backtest or historical data import.
|
|
14
14
|
|
|
15
|
-
##
|
|
16
|
-
|
|
17
|
-
- **Accurate.** Indicators with intervals will return a result only when the period is reached.
|
|
18
|
-
- **Convenient.** Indicators with intervals will save their all-time highs and lows.
|
|
19
|
-
- **Fast.** If you need high throughput, you can use the included [faster implementations][2].
|
|
20
|
-
- **Flexible.** All advanced indicators support different smoothing overlays (WSMA, etc.).
|
|
21
|
-
- **Live.** It allows for the replacement of values, enabling live charting.
|
|
22
|
-
- **Modern.** Uses ECMAScript Modules (ESM) syntax.
|
|
23
|
-
- **Precise.** Better accuracy than calculating with primitive numbers thanks to [big.js][1].
|
|
24
|
-
- **Robust.** Checked against common division by zero mistakes.
|
|
25
|
-
- **Tested.** Code coverage is 100%. No surprises when using it.
|
|
26
|
-
- **Typed.** Source code is 100% TypeScript. No need to install external typings.
|
|
27
|
-
- **Verified.** All results are verified with [other libraries](#alternatives) to guarantee correctness.
|
|
28
|
-
- **Versatile.** Indicators can be updated up-front or by streaming prices.
|
|
15
|
+
## Installation
|
|
29
16
|
|
|
30
|
-
|
|
17
|
+
```bash
|
|
18
|
+
npm install trading-signals
|
|
19
|
+
```
|
|
31
20
|
|
|
32
|
-
|
|
33
|
-
- Volume indicators: Measure the strength of a trend (based on volume)
|
|
34
|
-
- Volatility indicators: Measure how much disagreement there is in the market based on price (statistical measure of its dispersion)
|
|
35
|
-
- Momentum indicators: Measure the strength of a trend (based on price / speed of price movement)
|
|
21
|
+
## Usage
|
|
36
22
|
|
|
37
|
-
|
|
23
|
+
**CommonJS:**
|
|
38
24
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
1. Average True Range (ATR)
|
|
43
|
-
1. Awesome Oscillator (AO)
|
|
44
|
-
1. Bollinger Bands (BBANDS)
|
|
45
|
-
1. Bollinger Bands Width (BBW)
|
|
46
|
-
1. Center of Gravity (CG)
|
|
47
|
-
1. Commodity Channel Index (CCI)
|
|
48
|
-
1. Directional Movement Index (DMI / DX)
|
|
49
|
-
1. Double Exponential Moving Average (DEMA)
|
|
50
|
-
1. Dual Moving Average (DMA)
|
|
51
|
-
1. Exponential Moving Average (EMA)
|
|
52
|
-
1. Mean Absolute Deviation (MAD)
|
|
53
|
-
1. Momentum (MOM / MTM)
|
|
54
|
-
1. Moving Average Convergence Divergence (MACD)
|
|
55
|
-
1. On-Balance Volume (OBV)
|
|
56
|
-
1. Rate-of-Change (ROC)
|
|
57
|
-
1. Relative Strength Index (RSI)
|
|
58
|
-
1. Simple Moving Average (SMA)
|
|
59
|
-
1. Stochastic Oscillator (STOCH)
|
|
60
|
-
1. Stochastic RSI (STOCHRSI)
|
|
61
|
-
1. True Range (TR)
|
|
62
|
-
1. Weighted Moving Average (WMA)
|
|
63
|
-
1. Wilder's Smoothed Moving Average (WSMA / WWS / SMMA / MEMA)
|
|
25
|
+
```ts
|
|
26
|
+
const {Big, SMA} = require('trading-signals');
|
|
27
|
+
```
|
|
64
28
|
|
|
65
|
-
|
|
29
|
+
**ESM:**
|
|
66
30
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
31
|
+
```ts
|
|
32
|
+
import {Big, SMA} from 'trading-signals';
|
|
33
|
+
```
|
|
70
34
|
|
|
71
|
-
|
|
35
|
+
**Example:**
|
|
72
36
|
|
|
73
37
|
```typescript
|
|
74
38
|
import {Big, SMA} from 'trading-signals';
|
|
75
39
|
|
|
76
40
|
const sma = new SMA(3);
|
|
77
41
|
|
|
78
|
-
// You can add
|
|
79
|
-
sma.
|
|
80
|
-
sma.
|
|
81
|
-
sma.
|
|
42
|
+
// You can add values individually:
|
|
43
|
+
sma.add(40);
|
|
44
|
+
sma.add(30);
|
|
45
|
+
sma.add(20);
|
|
82
46
|
|
|
83
|
-
// You can add multiple
|
|
47
|
+
// You can add multiple values at once:
|
|
84
48
|
sma.updates([20, 40, 80]);
|
|
85
49
|
|
|
86
|
-
// You can add
|
|
87
|
-
sma.
|
|
50
|
+
// You can add stringified values:
|
|
51
|
+
sma.add('10');
|
|
88
52
|
|
|
89
|
-
// You can replace a previous value (useful for live
|
|
53
|
+
// You can replace a previous value (useful for live charting):
|
|
90
54
|
sma.replace('40');
|
|
91
55
|
|
|
92
56
|
// You can add arbitrary-precision decimals:
|
|
93
|
-
sma.
|
|
57
|
+
sma.add(new Big(30.0009));
|
|
94
58
|
|
|
95
|
-
// You can
|
|
96
|
-
console.log(sma.
|
|
97
|
-
|
|
59
|
+
// You can check if an indicator is stable:
|
|
60
|
+
console.log(sma.isStable); // true
|
|
61
|
+
|
|
62
|
+
// If an indicator is stable, you can get its result:
|
|
63
|
+
console.log(sma.getResult()?.toFixed()); // "50.0003"
|
|
64
|
+
|
|
65
|
+
// You can also get the result without optional chaining:
|
|
66
|
+
console.log(sma.getResultOrThrow().toFixed()); // "50.0003"
|
|
67
|
+
|
|
68
|
+
// Various precisions are available too:
|
|
69
|
+
console.log(sma.getResultOrThrow().toFixed(2)); // "50.00"
|
|
70
|
+
console.log(sma.getResultOrThrow().toFixed(4)); // "50.0003"
|
|
71
|
+
|
|
72
|
+
// Each indicator also includes convenient features such as "lowest" and "highest" lifetime values:
|
|
73
|
+
console.log(sma.lowest?.toFixed(2)); // "23.33"
|
|
74
|
+
console.log(sma.highest?.toFixed(2)); // "53.33"
|
|
98
75
|
```
|
|
99
76
|
|
|
100
|
-
### When to use `
|
|
77
|
+
### When to use `add(...)`?
|
|
101
78
|
|
|
102
|
-
|
|
79
|
+
To input data, you need to call the indicator's `add` method. Depending on whether the minimum required input data for the interval has been reached, the `add` method may or may not return a result from the indicator.
|
|
103
80
|
|
|
104
|
-
### When to use `
|
|
81
|
+
### When to use `getResultOrThrow()`?
|
|
105
82
|
|
|
106
|
-
You can call `
|
|
83
|
+
You can call `getResultOrThrow()` at any point in time, but it throws errors unless an indicator has received the minimum amount of data. If you call `getResultOrThrow()`, before an indicator has received the required amount of input values, a `NotEnoughDataError` will be thrown.
|
|
107
84
|
|
|
108
85
|
**Example:**
|
|
109
86
|
|
|
@@ -119,7 +96,7 @@ sma.update(40);
|
|
|
119
96
|
|
|
120
97
|
try {
|
|
121
98
|
// We will get an error, because the minimum amount of inputs is 3
|
|
122
|
-
sma.
|
|
99
|
+
sma.getResultOrThrow();
|
|
123
100
|
} catch (error) {
|
|
124
101
|
console.log(error.constructor.name); // "NotEnoughDataError"
|
|
125
102
|
}
|
|
@@ -128,11 +105,52 @@ try {
|
|
|
128
105
|
sma.update(70);
|
|
129
106
|
|
|
130
107
|
// Now, we will receive a proper result
|
|
131
|
-
console.log(sma.
|
|
108
|
+
console.log(sma.getResultOrThrow().valueOf()); // "40"
|
|
132
109
|
```
|
|
133
110
|
|
|
134
111
|
Most of the time, the minimum amount of data depends on the interval / time period used.
|
|
135
112
|
|
|
113
|
+
## Technical Indicator Types
|
|
114
|
+
|
|
115
|
+
- Trend indicators: Measure the direction of a trend (uptrend, downtrend or sideways trend)
|
|
116
|
+
- Volume indicators: Measure the strength of a trend (based on volume)
|
|
117
|
+
- Volatility indicators: Measure how much disagreement there is in the market based on price (statistical measure of its dispersion)
|
|
118
|
+
- Momentum indicators: Measure the strength of a trend (based on price / speed of price movement)
|
|
119
|
+
|
|
120
|
+
## Supported Technical Indicators
|
|
121
|
+
|
|
122
|
+
1. Acceleration Bands (ABANDS)
|
|
123
|
+
1. Accelerator Oscillator (AC)
|
|
124
|
+
1. Average Directional Index (ADX)
|
|
125
|
+
1. Average True Range (ATR)
|
|
126
|
+
1. Awesome Oscillator (AO)
|
|
127
|
+
1. Bollinger Bands (BBANDS)
|
|
128
|
+
1. Bollinger Bands Width (BBW)
|
|
129
|
+
1. Center of Gravity (CG)
|
|
130
|
+
1. Commodity Channel Index (CCI)
|
|
131
|
+
1. Directional Movement Index (DMI / DX)
|
|
132
|
+
1. Double Exponential Moving Average (DEMA)
|
|
133
|
+
1. Dual Moving Average (DMA)
|
|
134
|
+
1. Exponential Moving Average (EMA)
|
|
135
|
+
1. Mean Absolute Deviation (MAD)
|
|
136
|
+
1. Momentum (MOM / MTM)
|
|
137
|
+
1. Moving Average Convergence Divergence (MACD)
|
|
138
|
+
1. On-Balance Volume (OBV)
|
|
139
|
+
1. Rate-of-Change (ROC)
|
|
140
|
+
1. Relative Strength Index (RSI)
|
|
141
|
+
1. Simple Moving Average (SMA)
|
|
142
|
+
1. Stochastic Oscillator (STOCH)
|
|
143
|
+
1. Stochastic RSI (STOCHRSI)
|
|
144
|
+
1. True Range (TR)
|
|
145
|
+
1. Weighted Moving Average (WMA)
|
|
146
|
+
1. Wilder's Smoothed Moving Average (WSMA / WWS / SMMA / MEMA)
|
|
147
|
+
|
|
148
|
+
Utility Methods:
|
|
149
|
+
|
|
150
|
+
1. Average / Mean
|
|
151
|
+
1. Standard Deviation
|
|
152
|
+
1. Rolling Standard Deviation
|
|
153
|
+
|
|
136
154
|
## Performance
|
|
137
155
|
|
|
138
156
|
### Arbitrary-precision decimal arithmetic
|
|
@@ -165,12 +183,12 @@ fasterStochRSI.update(4);
|
|
|
165
183
|
fasterStochRSI.update(5);
|
|
166
184
|
fasterStochRSI.update(6);
|
|
167
185
|
|
|
168
|
-
console.log(fasterStochRSI.
|
|
186
|
+
console.log(fasterStochRSI.getResultOrThrow());
|
|
169
187
|
```
|
|
170
188
|
|
|
171
189
|
### Benchmarks
|
|
172
190
|
|
|
173
|
-
You can run `
|
|
191
|
+
You can run `npm run start:benchmark` to see the runtime performance of each technical indicator on your machine. This will give you an understanding of which indicators can be calculated faster than others.
|
|
174
192
|
|
|
175
193
|
## Disclaimer
|
|
176
194
|
|