trading-signals 7.1.0 → 7.2.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
@@ -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