ohlcv-indicators 3.5.50 → 3.5.52

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ohlcv-indicators",
3
- "version": "3.5.50",
3
+ "version": "3.5.52",
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",
@@ -132,7 +132,7 @@ class CrossInstance {
132
132
 
133
133
  }
134
134
 
135
- export const crossPairs = (main, index, crossPairsList, {limit, oneHot}) => {
135
+ export const crossPairs = (main, index, crossPairsList) => {
136
136
 
137
137
  const {verticalOhlcv, verticalOhlcvTempCols, instances, len} = main
138
138
 
@@ -147,7 +147,7 @@ export const crossPairs = (main, index, crossPairsList, {limit, oneHot}) => {
147
147
 
148
148
  const col = slow.toString()
149
149
  verticalOhlcvTempCols.add(col)
150
- verticalOhlcv[col] = buildArray('Int16Array', len)
150
+ verticalOhlcv[col] = buildArray('Int16Array', len, slow)
151
151
  }
152
152
 
153
153
  if(!instances.hasOwnProperty('crossPairs'))
@@ -164,12 +164,7 @@ export const crossPairs = (main, index, crossPairsList, {limit, oneHot}) => {
164
164
 
165
165
  const crossArrType = 'Int16Array'
166
166
 
167
- verticalOhlcv[crossName] = buildArray(crossArrType, len)
168
-
169
- if(oneHot)
170
- {
171
- verticalOhlcv[`one_hot_${crossName}`] = buildArray('Array', len)
172
- }
167
+ verticalOhlcv[crossName] = buildArray(crossArrType, len, 0)
173
168
 
174
169
  } else if(index + 1 === len) {
175
170
  // sanity checks
@@ -181,7 +176,7 @@ export const crossPairs = (main, index, crossPairsList, {limit, oneHot}) => {
181
176
  }
182
177
  }
183
178
 
184
- if (fast !== "price" && !verticalOhlcv.hasOwnProperty(fast)) return
179
+ if (fast !== 'price' && !verticalOhlcv.hasOwnProperty(fast)) return
185
180
  if (!verticalOhlcv.hasOwnProperty(slow)) return
186
181
 
187
182
  const {run} = instances.crossPairs[crossName]
@@ -202,25 +197,9 @@ export const crossPairs = (main, index, crossPairsList, {limit, oneHot}) => {
202
197
  run.update(index, { fast: fastVal, slow: slowVal })
203
198
  }
204
199
 
205
- const rawValue = run.getResult()
206
-
207
- const value = rawValue//Math.max(-limit, Math.min(limit, rawValue))
208
-
200
+ const value = run.getResult()
209
201
  main.pushToMain({index, key: crossName, value})
210
202
 
211
- if(oneHot)
212
- {
213
- // clamp _just_ for the one-hot index
214
- const clamped = Math.max(-limit, Math.min(limit, rawValue));
215
- const oneHotIdx = clamped + limit;
216
- const oneHotSize = 2 * limit + 1;
217
- main.pushToMain({
218
- index,
219
- key: `one_hot_${crossName}`,
220
- value: oneHotEncode(oneHotIdx, oneHotSize)
221
- });
222
- }
223
-
224
203
  }
225
204
 
226
205
  return true
@@ -3,7 +3,7 @@ import { selectDateFormatter } from "./dateUtilities.js";
3
3
 
4
4
  const numberKeys = new Set(['open', 'high', 'low', 'close'])
5
5
 
6
- export const buildArray = (arrayType, len) => {
6
+ export const buildArray = (arrayType, len, fallbackValue) => {
7
7
  const ctorMap = {
8
8
  Array: Array,
9
9
  Float64Array: Float64Array,
@@ -14,14 +14,24 @@ export const buildArray = (arrayType, len) => {
14
14
  Int16Array: Int16Array,
15
15
  }
16
16
 
17
- const Ctor = ctorMap[arrayType];
17
+ const Ctor = ctorMap[arrayType]
18
18
  if (!Ctor || typeof Ctor.from !== 'function') {
19
- throw new Error(`Unsupported array type: ${arrayType}`);
19
+ throw new Error(`Unsupported array type: ${arrayType}`)
20
20
  }
21
21
  // Arrays get nulls, typed-arrays get NaNs
22
- const fillValue = arrayType === 'Array' ? null : NaN;
22
+
23
+ let fillValue
24
+
25
+ if(typeof fallbackValue !== 'undefined')
26
+ {
27
+ fillValue = fallbackValue
28
+ } else {
29
+ fillValue = arrayType === 'Array' ? null : NaN
30
+ }
31
+
32
+
23
33
  // Ctor.from({ length }, mapFn) works for Array *and* all TypedArrays
24
- return Ctor.from({ length: len }, () => fillValue);
34
+ return Ctor.from({ length: len }, () => fillValue)
25
35
  }
26
36
 
27
37
  export const assignTypes = main => {