trading-signals 7.0.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
@@ -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
@@ -100,16 +110,69 @@ sma.add(70);
100
110
  console.log(sma.getResultOrThrow()); // 40
101
111
  ```
102
112
 
103
- 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
+ ```
104
149
 
105
150
  ## Technical Indicator Types
106
151
 
107
- - Exhaustion indicators: Identify trend exhaustion and potential reversal.
108
- - Momentum indicators: Measure the speed and strength of price movements in a particular direction
109
- - 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)
110
156
  - Volatility indicators: Measure the degree of variation in prices over time, regardless of direction
111
157
  - Volume indicators: Measure the strength of a trend based on volume
112
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
+
113
176
  ## Supported Technical Indicators
114
177
 
115
178
  1. Acceleration Bands (ABANDS)
@@ -145,6 +208,7 @@ Most of the time, the minimum amount of data depends on the interval / time peri
145
208
  1. Volume-Weighted Average Price (VWAP)
146
209
  1. Weighted Moving Average (WMA)
147
210
  1. Wilder's Smoothed Moving Average (WSMA / WWS / SMMA / MEMA)
211
+ 1. Williams %R (WILLR)
148
212
  1. Zig Zag Indicator (ZigZag)
149
213
 
150
214
  Utility Methods:
@@ -165,7 +229,7 @@ Utility Methods:
165
229
 
166
230
  JavaScript uses double-precision floating-point arithmetic. For example, `0.1 + 0.2` yields `0.30000000000000004` due to binary floating-point representation.
167
231
 
168
- ![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)
169
233
 
170
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.
171
235
 
@@ -196,15 +260,23 @@ It is very important to do your own analysis before making any investment based
196
260
  - [Technical Analysis Library using Pandas and Numpy (Python)](https://github.com/bukosabino/ta)
197
261
  - [Tulip Indicators (ANSI C)](https://github.com/TulipCharts/tulipindicators)
198
262
 
263
+ ## Documentation
264
+
265
+ Build and run the documentation:
266
+
267
+ ```bash
268
+ npm run docs
269
+ ```
270
+
199
271
  ## Maintainers
200
272
 
201
273
  [![Benny Neugebauer on Stack Exchange][stack_exchange_bennycode_badge]][stack_exchange_bennycode_url]
202
274
 
203
275
  ## ⭐️ Become a TypeScript rockstar! ⭐️
204
276
 
205
- This package was built by Benny Code. Checkout my [**TypeScript course**](https://typescript.tv/) to become a coding rockstar!
277
+ This package was built by Benny Neugebauer. Checkout my [**TypeScript course**](https://typescript.tv/) to become a coding rockstar!
206
278
 
207
- [<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/)
208
280
 
209
281
  [1]: http://mikemcl.github.io/big.js/
210
282
  [stack_exchange_bennycode_badge]: https://stackexchange.com/users/flair/203782.png?theme=default