ohlcv-indicators 3.0.1 → 3.0.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.
Files changed (2) hide show
  1. package/index.js +32 -11
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -53,27 +53,48 @@ export default class OHLCV_INDICATORS {
53
53
 
54
54
  for(let k in this.minMaxRanges)
55
55
  {
56
- this.minMaxRanges[k].min = Infinity
57
- this.minMaxRanges[k].max = -Infinity
56
+ this.minMaxRanges[k] = {min: Infinity, max: -Infinity}
58
57
  }
59
58
  }
60
59
 
61
60
  this.verticalOhlcv[key][index] = value
62
61
 
63
- if(typeof value === 'number' && !key.includes('_x_'))
62
+ if(typeof value === 'number')
64
63
  {
65
- if(!this.minMaxRanges.hasOwnProperty(key))
64
+ if(key.includes('_diff_'))
66
65
  {
67
- this.minMaxRanges[key] = { min: Infinity, max: -Infinity }
66
+ if(!this.minMaxRanges.hasOwnProperty(key) || (this.minMaxRanges[key].min === Infinity))
67
+ {
68
+ this.minMaxRanges[key] = { min: -1, max: 1}
69
+ }
68
70
  }
69
-
70
- if(value < this.minMaxRanges[key].min)
71
+ else if(key.startsWith('candle'))
71
72
  {
72
- this.minMaxRanges[key].min = value
73
+ if(key.startsWith('candle_top') || key.startsWith('bottom'))
74
+ {
75
+ this.minMaxRanges[key] = { min: 0, max: 1}
76
+ }
77
+ else
78
+ {
79
+ this.minMaxRanges[key] = { min: -1, max: 1}
80
+ }
73
81
  }
74
- if(value > this.minMaxRanges[key].max)
75
- {
76
- this.minMaxRanges[key].max = value
82
+ else if(!key.includes('_x_')) {
83
+ const newValue = (this.precision && this.priceBased.includes(key)) ? (value / this.precisionMultiplier) : value
84
+
85
+ if(!this.minMaxRanges.hasOwnProperty(key))
86
+ {
87
+ this.minMaxRanges[key] = { min: Infinity, max: -Infinity }
88
+ }
89
+
90
+ if(newValue < this.minMaxRanges[key].min)
91
+ {
92
+ this.minMaxRanges[key].min = newValue
93
+ }
94
+ if(newValue > this.minMaxRanges[key].max)
95
+ {
96
+ this.minMaxRanges[key].max = newValue
97
+ }
77
98
  }
78
99
  }
79
100
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ohlcv-indicators",
3
- "version": "3.0.1",
3
+ "version": "3.0.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",