ohlcv-indicators 2.2.2 → 2.2.4

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
@@ -50,6 +50,8 @@ export default class OHLCV_INDICATORS {
50
50
  this.invalidValueIndex = index
51
51
  }
52
52
 
53
+
54
+
53
55
  this.verticalOhlcv[key][index] = value
54
56
  }
55
57
 
@@ -66,8 +68,9 @@ export default class OHLCV_INDICATORS {
66
68
  } = this;
67
69
  const result = {};
68
70
  const shouldSlice = invalidValueIndex >= 0 && skipNull;
69
- const sliceLength = len - invalidValueIndex;
71
+ const sliceLength = len - (invalidValueIndex + 1);
70
72
 
73
+
71
74
  for (const [key, arr] of Object.entries(verticalOhlcv)) {
72
75
  // If slicing is needed, create a sliced copy, otherwise re-use the array.
73
76
  let newArr = shouldSlice ? arr.slice(-sliceLength) : arr;
@@ -90,7 +93,6 @@ export default class OHLCV_INDICATORS {
90
93
 
91
94
  const {precisionMultiplier, priceBased, precision, verticalOhlcv, invalidValueIndex} = this
92
95
 
93
-
94
96
  return verticalToHorizontal(verticalOhlcv, skipNull, precision, precisionMultiplier, priceBased, invalidValueIndex)
95
97
  }
96
98
 
@@ -326,14 +328,19 @@ export default class OHLCV_INDICATORS {
326
328
  throw new Error('"size" must be a positive number in rsi.');
327
329
  }
328
330
 
329
- const {scale = null, target = 'close'} = options
331
+ const {scale = null, target = 'close', lag = 0} = options
330
332
 
331
333
  if (typeof scale === 'number' && !validMagnitudeValues.includes(scale)) {
332
334
 
333
335
  throw new Error(`"scale" value in rsi must be any of the following numbers: ${validMagnitudeValues.join(', ')}`);
334
336
  }
335
337
 
336
- this.inputParams.push({key: 'rsi', params: [size, {scale, target}]})
338
+ if (typeof lag !== 'number') {
339
+
340
+ throw new Error(`"lag" value in rsi must be a number in rsi.`);
341
+ }
342
+
343
+ this.inputParams.push({key: 'rsi', params: [size, {scale, target, lag}]})
337
344
 
338
345
  return this
339
346
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ohlcv-indicators",
3
- "version": "2.2.2",
3
+ "version": "2.2.4",
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];
@@ -10,13 +10,17 @@ export const candleStudies = (main, index, size, stdDev, {lag, scale}) => {
10
10
  if(index === 0)
11
11
  {
12
12
  const {nullArray} = main
13
-
14
- const candleParts = ['candle_body', 'candle_top', 'candle_bottom']
15
- const candleGaps = ['candle_gap']
16
- const candleChanges = ['candle_change_close', 'candle_change_high', 'candle_change_low', 'candle_change_open']
17
- const keyNames = [...candleParts, ...candleGaps, ...candleChanges]
18
-
19
- Object.assign(verticalOhlcv, Object.fromEntries(keyNames.map(k => [k, nullArray])))
13
+
14
+ Object.assign(verticalOhlcv, {
15
+ candle_body: [...nullArray],
16
+ candle_top: [...nullArray],
17
+ candle_bottom: [...nullArray],
18
+ candle_gap: [...nullArray],
19
+ candle_change_close: [...nullArray],
20
+ candle_change_high: [...nullArray],
21
+ candle_change_low: [...nullArray],
22
+ candle_change_open: [...nullArray],
23
+ })
20
24
 
21
25
  Object.assign(instances, {
22
26
  candleStudies: {
@@ -21,6 +21,7 @@ import { calcMagnitude } from "./numberUtilities.js"
21
21
 
22
22
 
23
23
  export const classifyBoll = (value, bollingerBands, scale = 0.05) => {
24
+
24
25
  // Validate that value and bollingerBands are not null/undefined
25
26
  if (value == null || bollingerBands == null) return null
26
27
 
@@ -12,8 +12,8 @@ export const verticalToHorizontal = (
12
12
  const startIndex = skipNull && invalidValueIndex >= 0 ? invalidValueIndex + 1 : 0;
13
13
  const endIndex = obj[keys[0]].length;
14
14
  const len = endIndex - startIndex;
15
-
16
15
  const result = new Array(len);
16
+
17
17
 
18
18
  for (let i = startIndex; i < endIndex; i++) {
19
19
  const row = {};
@@ -21,15 +21,10 @@ export const verticalToHorizontal = (
21
21
  const key = keys[j];
22
22
  const value = obj[key][i];
23
23
 
24
- if(value === null || typeof value === 'undefined')
25
- {
26
- row[key] = null
27
- }
28
- else{
29
- row[key] = (precision && priceBased.includes(key)) ? value / precisionMultiplier : value
30
- }
24
+ row[key] = (precision && priceBased.includes(key)) ? value / precisionMultiplier : value
31
25
 
32
26
  }
27
+
33
28
  result[i - startIndex] = row;
34
29
  }
35
30