ohlcv-indicators 2.2.1 → 2.2.3

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/index.js CHANGED
@@ -326,14 +326,19 @@ export default class OHLCV_INDICATORS {
326
326
  throw new Error('"size" must be a positive number in rsi.');
327
327
  }
328
328
 
329
- const {scale = null, target = 'close'} = options
329
+ const {scale = null, target = 'close', lag = 0} = options
330
330
 
331
331
  if (typeof scale === 'number' && !validMagnitudeValues.includes(scale)) {
332
332
 
333
333
  throw new Error(`"scale" value in rsi must be any of the following numbers: ${validMagnitudeValues.join(', ')}`);
334
334
  }
335
335
 
336
- this.inputParams.push({key: 'rsi', params: [size, {scale, target}]})
336
+ if (typeof lag !== 'number') {
337
+
338
+ throw new Error(`"lag" value in rsi must be a number in rsi.`);
339
+ }
340
+
341
+ this.inputParams.push({key: 'rsi', params: [size, {scale, target, lag}]})
337
342
 
338
343
  return this
339
344
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ohlcv-indicators",
3
- "version": "2.2.1",
3
+ "version": "2.2.3",
4
4
  "description": "A JavaScript library featuring optimized trading indicators for OHLCV arrays [{open, high, low, close, value}]. This library is optimized for backtesting and trading bot development.",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -4,7 +4,7 @@ import { calcMagnitude } from '../utilities/numberUtilities.js';
4
4
 
5
5
  const defaultTarget = 'close';
6
6
 
7
- export const rsi = (main, index, size, { scale, target }) => {
7
+ export const rsi = (main, index, size, { scale, target, lag }) => {
8
8
  const { verticalOhlcv, instances, lastIndexReplace } = main;
9
9
  const suffix = target === defaultTarget ? '' : `_${target}`;
10
10
  const rsiKey = `rsi_${size}${suffix}`;
@@ -29,6 +29,11 @@ export const rsi = (main, index, size, { scale, target }) => {
29
29
  [rsiKey]: [...nullArray],
30
30
  [rsiSmaKey]: [...nullArray],
31
31
  });
32
+
33
+ if(lag > 0)
34
+ {
35
+ main.lag([rsiKey, rsiSmaKey], lag)
36
+ }
32
37
  }
33
38
 
34
39
  const value = verticalOhlcv[target][index];
@@ -14,8 +14,6 @@ export const verticalToHorizontal = (
14
14
  const len = endIndex - startIndex;
15
15
 
16
16
  const result = new Array(len);
17
-
18
- console.log({skipNull, invalidValueIndex, len})
19
17
 
20
18
  for (let i = startIndex; i < endIndex; i++) {
21
19
  const row = {};