ohlcv-indicators 2.2.3 → 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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ohlcv-indicators",
3
- "version": "2.2.3",
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",
@@ -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