ohlcv-indicators 3.2.5 → 3.2.7

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.
@@ -119,7 +119,7 @@ var OHLCV_INDICATORS;
119
119
  * rm {number} Rounding mode: 0 (down), 1 (half-up), 2 (half-even) or 3 (up).
120
120
  * [more] {boolean} Whether the result of division was truncated.
121
121
  */
122
- function d(t, e, r, n) {
122
+ function b(t, e, r, n) {
123
123
  var o = t.c;
124
124
  if (r === p && (r = t.constructor.RM), 0 !== r && 1 !== r && 2 !== r && 3 !== r) throw Error(f);
125
125
  if (e < 1) n = 3 === r && (n || !!o[0]) || 0 === e && (1 === r && o[0] >= 5 || 2 === r && (o[0] > 5 || 5 === o[0] && (n || o[1] !== p))),
@@ -147,7 +147,7 @@ var OHLCV_INDICATORS;
147
147
  /*
148
148
  * Return a string representing the value of Big x in normal or exponential notation.
149
149
  * Handles P.toExponential, P.toFixed, P.toJSON, P.toPrecision, P.toString and P.valueOf.
150
- */ function b(t, e, r) {
150
+ */ function d(t, e, r) {
151
151
  var n = t.e, o = t.c.join(""), i = o.length;
152
152
  // Exponential notation?
153
153
  if (e) o = o.charAt(0) + (i > 1 ? "." + o.slice(1) : "") + (n < 0 ? "e" : "e+") + n;
@@ -196,14 +196,14 @@ var OHLCV_INDICATORS;
196
196
  if (!o[0]) throw Error(h);
197
197
  // Dividend is 0? Return +-0.
198
198
  if (!n[0]) return t.s = i, t.c = [ t.e = 0 ], t;
199
- var l, c, f, y, v, b = o.slice(), m = l = o.length, g = n.length, w = n.slice(0, l), // remainder
199
+ var l, c, f, y, v, d = o.slice(), m = l = o.length, g = n.length, w = n.slice(0, l), // remainder
200
200
  O = w.length, S = t, // quotient
201
201
  _ = S.c = [], j = 0, P = u + (S.e = e.e - t.e) + 1;
202
202
  // precision of the result
203
203
  // Add zeros to make remainder as long as divisor.
204
204
  for (S.s = i, i = P < 0 ? 0 : P,
205
205
  // Create version of divisor with leading zero.
206
- b.unshift(0); O++ < l; ) w.push(0);
206
+ d.unshift(0); O++ < l; ) w.push(0);
207
207
  do {
208
208
  // n is how many times the divisor goes into current remainder.
209
209
  for (f = 0; f < 10; f++) {
@@ -216,7 +216,7 @@ var OHLCV_INDICATORS;
216
216
  if (!(y < 0)) break;
217
217
  // Remainder can't be more than 1 digit longer than divisor.
218
218
  // Equalise lengths using divisor with extra leading zero?
219
- for (c = O == l ? o : b; O; ) {
219
+ for (c = O == l ? o : d; O; ) {
220
220
  if (w[--O] < c[O]) {
221
221
  for (v = O; v && !w[--v]; ) w[v] = 9;
222
222
  --w[v], w[O] += 10;
@@ -235,7 +235,7 @@ var OHLCV_INDICATORS;
235
235
  // There can't be more than one zero.
236
236
  _.shift(), S.e--, P--),
237
237
  // Round?
238
- j > P && d(S, P, r.RM, w[0] !== p), S;
238
+ j > P && b(S, P, r.RM, w[0] !== p), S;
239
239
  },
240
240
  /*
241
241
  * Return true if the value of this Big is equal to the value of Big y, otherwise return false.
@@ -378,7 +378,7 @@ var OHLCV_INDICATORS;
378
378
  */
379
379
  y.prec = function(t, e) {
380
380
  if (t !== ~~t || t < 1 || t > a) throw Error(c + "precision");
381
- return d(new this.constructor(this), t, e);
381
+ return b(new this.constructor(this), t, e);
382
382
  },
383
383
  /*
384
384
  * Return a new Big whose value is the value of this Big rounded to a maximum of dp decimal places
@@ -391,7 +391,7 @@ var OHLCV_INDICATORS;
391
391
  */
392
392
  y.round = function(t, e) {
393
393
  if (t === p) t = 0; else if (t !== ~~t || t < -a || t > a) throw Error(s);
394
- return d(new this.constructor(this), t + this.e + 1, e);
394
+ return b(new this.constructor(this), t + this.e + 1, e);
395
395
  },
396
396
  /*
397
397
  * Return a new Big whose value is the square root of the value of this Big, rounded, if
@@ -413,7 +413,7 @@ var OHLCV_INDICATORS;
413
413
  do {
414
414
  r = t, t = u.times(r.plus(n.div(r)));
415
415
  } while (r.c.slice(0, a).join("") !== t.c.slice(0, a).join(""));
416
- return d(t, (o.DP -= 4) + t.e + 1, o.RM);
416
+ return b(t, (o.DP -= 4) + t.e + 1, o.RM);
417
417
  },
418
418
  /*
419
419
  * Return a new Big whose value is the value of this Big times the value of Big y.
@@ -455,9 +455,9 @@ var OHLCV_INDICATORS;
455
455
  var r = this, n = r.c[0];
456
456
  if (t !== p) {
457
457
  if (t !== ~~t || t < 0 || t > a) throw Error(s);
458
- for (r = d(new r.constructor(r), ++t, e); r.c.length < t; ) r.c.push(0);
458
+ for (r = b(new r.constructor(r), ++t, e); r.c.length < t; ) r.c.push(0);
459
459
  }
460
- return b(r, !0, !!n);
460
+ return d(r, !0, !!n);
461
461
  },
462
462
  /*
463
463
  * Return a string representing the value of this Big in normal notation rounded to dp fixed
@@ -474,9 +474,9 @@ var OHLCV_INDICATORS;
474
474
  if (t !== p) {
475
475
  if (t !== ~~t || t < 0 || t > a) throw Error(s);
476
476
  // x.e may have changed if the value is rounded up.
477
- for (t = t + (r = d(new r.constructor(r), t + r.e + 1, e)).e + 1; r.c.length < t; ) r.c.push(0);
477
+ for (t = t + (r = b(new r.constructor(r), t + r.e + 1, e)).e + 1; r.c.length < t; ) r.c.push(0);
478
478
  }
479
- return b(r, !1, !!n);
479
+ return d(r, !1, !!n);
480
480
  },
481
481
  /*
482
482
  * Return a string representing the value of this Big.
@@ -486,13 +486,13 @@ var OHLCV_INDICATORS;
486
486
  */
487
487
  y[Symbol.for("nodejs.util.inspect.custom")] = y.toJSON = y.toString = function() {
488
488
  var t = this, e = t.constructor;
489
- return b(t, t.e <= e.NE || t.e >= e.PE, !!t.c[0]);
489
+ return d(t, t.e <= e.NE || t.e >= e.PE, !!t.c[0]);
490
490
  },
491
491
  /*
492
492
  * Return the value of this Big as a primitve number.
493
493
  */
494
494
  y.toNumber = function() {
495
- var t = Number(b(this, !0, !0));
495
+ var t = Number(d(this, !0, !0));
496
496
  if (!0 === this.constructor.strict && !this.eq(t.toString())) throw Error(l + "Imprecise conversion");
497
497
  return t;
498
498
  },
@@ -509,9 +509,9 @@ var OHLCV_INDICATORS;
509
509
  var r = this, n = r.constructor, o = r.c[0];
510
510
  if (t !== p) {
511
511
  if (t !== ~~t || t < 1 || t > a) throw Error(c + "precision");
512
- for (r = d(new n(r), t, e); r.c.length < t; ) r.c.push(0);
512
+ for (r = b(new n(r), t, e); r.c.length < t; ) r.c.push(0);
513
513
  }
514
- return b(r, t <= r.e || r.e <= n.NE || r.e >= n.PE, !!o);
514
+ return d(r, t <= r.e || r.e <= n.NE || r.e >= n.PE, !!o);
515
515
  },
516
516
  /*
517
517
  * Return a string representing the value of this Big.
@@ -522,7 +522,7 @@ var OHLCV_INDICATORS;
522
522
  y.valueOf = function() {
523
523
  var t = this, e = t.constructor;
524
524
  if (!0 === e.strict) throw Error(l + "valueOf disallowed");
525
- return b(t, t.e <= e.NE || t.e >= e.PE, !0);
525
+ return d(t, t.e <= e.NE || t.e >= e.PE, !0);
526
526
  };
527
527
  // Export
528
528
  (
@@ -1099,18 +1099,18 @@ var OHLCV_INDICATORS;
1099
1099
  }
1100
1100
  } ]);
1101
1101
  }(R);
1102
- function dt(t) {
1102
+ function bt(t) {
1103
1103
  return t.length ? t.reduce((function(t, e) {
1104
1104
  return t + e;
1105
1105
  }), 0) / t.length : 0;
1106
1106
  }
1107
1107
  // ./node_modules/trading-signals/dist/BBANDS/BollingerBands.js
1108
- function bt(t) {
1109
- return bt = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(t) {
1108
+ function dt(t) {
1109
+ return dt = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(t) {
1110
1110
  return typeof t;
1111
1111
  } : function(t) {
1112
1112
  return t && "function" == typeof Symbol && t.constructor === Symbol && t !== Symbol.prototype ? "symbol" : typeof t;
1113
- }, bt(t);
1113
+ }, dt(t);
1114
1114
  }
1115
1115
  function mt(t, e) {
1116
1116
  if (!(t instanceof e)) throw new TypeError("Cannot call a class as a function");
@@ -1137,16 +1137,16 @@ var OHLCV_INDICATORS;
1137
1137
  }
1138
1138
  function St(t) {
1139
1139
  var e = function(t, e) {
1140
- if ("object" != bt(t) || !t) return t;
1140
+ if ("object" != dt(t) || !t) return t;
1141
1141
  var r = t[Symbol.toPrimitive];
1142
1142
  if (void 0 !== r) {
1143
1143
  var n = r.call(t, e || "default");
1144
- if ("object" != bt(n)) return n;
1144
+ if ("object" != dt(n)) return n;
1145
1145
  throw new TypeError("@@toPrimitive must return a primitive value.");
1146
1146
  }
1147
1147
  return ("string" === e ? String : Number)(t);
1148
1148
  }(t, "string");
1149
- return "symbol" == bt(e) ? e : e + "";
1149
+ return "symbol" == dt(e) ? e : e + "";
1150
1150
  }
1151
1151
  var _t = function() {
1152
1152
  return wt((function t(e) {
@@ -1158,8 +1158,8 @@ var OHLCV_INDICATORS;
1158
1158
  value: function(t) {
1159
1159
  if (this.prices.push(t), this.prices.length > this.interval) {
1160
1160
  this.prices.shift();
1161
- var e = dt(this.prices), r = function(t, e) {
1162
- var r = e || dt(t), n = dt(t.map((function(t) {
1161
+ var e = bt(this.prices), r = function(t, e) {
1162
+ var r = e || bt(t), n = bt(t.map((function(t) {
1163
1163
  return t - r;
1164
1164
  })).map((function(t) {
1165
1165
  return t * t;
@@ -1586,7 +1586,7 @@ var OHLCV_INDICATORS;
1586
1586
  // Validate that value and bollingerBands are not null/undefined
1587
1587
  if (null == t || null == e) return null;
1588
1588
  var o = t >= 0, i = Math.abs(t), a = e.upper, u = e.lower, l = ne((i - u) / (a - u), r);
1589
- return n ? o ? Math.min(l, 1) : Math.max(-l, -1) : o ? l : -l;
1589
+ return 0 === l ? o ? .01 : -.01 : n ? o ? Math.min(l, 1) : Math.max(-l, -1) : o ? l : -l;
1590
1590
  };
1591
1591
  // ./src/moving-averages/movingAverages.js
1592
1592
  function se(t) {
@@ -1665,7 +1665,7 @@ var OHLCV_INDICATORS;
1665
1665
  var ve = {
1666
1666
  ema: Dt,
1667
1667
  sma: nt
1668
- }, de = function(t, e, r, n) {
1668
+ }, be = function(t, e, r, n) {
1669
1669
  if (!r || "object" !== se(r)) throw new Error('"options" must be an object in '.concat(t, ". eg: {target, height, range}"));
1670
1670
  var o = r.target, i = void 0 === o ? "close" : o, a = r.diff, u = void 0 === a ? null : a;
1671
1671
  if ("string" != typeof i) throw new Error('"target" must be a valid keyName '.concat(t, "."));
@@ -1676,17 +1676,17 @@ var OHLCV_INDICATORS;
1676
1676
  diff: null
1677
1677
  };
1678
1678
  if (null !== u && ("object" === se(u) || "boolean" == typeof u && !0 === u)) {
1679
- var c = u = !0 === u ? {} : u, s = c.stdDev, f = void 0 === s ? 2 : s, h = c.scale, y = void 0 === h ? .05 : h, p = c.targets, v = void 0 === p ? [ "close" ] : p, d = c.size, b = void 0 === d ? e : d, m = c.lag, g = void 0 === m ? 0 : m, w = c.autoMinMax, O = void 0 !== w && w;
1679
+ var c = u = !0 === u ? {} : u, s = c.stdDev, f = void 0 === s ? 2 : s, h = c.scale, y = void 0 === h ? .05 : h, p = c.targets, v = void 0 === p ? [ "close" ] : p, b = c.size, d = void 0 === b ? e : b, m = c.lag, g = void 0 === m ? 0 : m, w = c.autoMinMax, O = void 0 !== w && w;
1680
1680
  if ("number" != typeof f || f <= 0) throw new Error('"diff.stdDev" must be a number greater than 0 in '.concat(t, "."));
1681
1681
  if ("number" != typeof y || !n.includes(y)) throw new Error('"diff.scale" must be a number between 0.01 and 1 in '.concat(t, "."));
1682
- if ("number" != typeof b || !Number.isInteger(b) || b <= 0) throw new Error('"diff.size" must be an integer greater than or equal to size in '.concat(t, "."));
1682
+ if ("number" != typeof d || !Number.isInteger(d) || d <= 0) throw new Error('"diff.size" must be an integer greater than or equal to size in '.concat(t, "."));
1683
1683
  if (!Array.isArray(v)) throw new Error('"diff.targest" must be an array of keyNames with at least 1 item in '.concat(t, "."));
1684
1684
  if ("number" != typeof g || !Number.isInteger(g) || g < 0) throw new Error('"diff.lag" must be an integer greater than 0 in '.concat(t, "."));
1685
1685
  if ("boolean" != typeof O) throw new Error('"diff.autoMinMax" must be an boolean in '.concat(t, "."));
1686
1686
  l.diff = {
1687
1687
  stdDev: f,
1688
1688
  scale: y,
1689
- size: b,
1689
+ size: d,
1690
1690
  targets: v,
1691
1691
  lag: g,
1692
1692
  autoMinMax: O
@@ -1695,26 +1695,26 @@ var OHLCV_INDICATORS;
1695
1695
  return l;
1696
1696
  };
1697
1697
  // ./src/moving-averages/macd.js
1698
- function be(t) {
1699
- return be = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(t) {
1698
+ function de(t) {
1699
+ return de = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(t) {
1700
1700
  return typeof t;
1701
1701
  } : function(t) {
1702
1702
  return t && "function" == typeof Symbol && t.constructor === Symbol && t !== Symbol.prototype ? "symbol" : typeof t;
1703
- }, be(t);
1703
+ }, de(t);
1704
1704
  }
1705
1705
  function me(t, e, r) {
1706
1706
  return (e = function(t) {
1707
1707
  var e = function(t, e) {
1708
- if ("object" != be(t) || !t) return t;
1708
+ if ("object" != de(t) || !t) return t;
1709
1709
  var r = t[Symbol.toPrimitive];
1710
1710
  if (void 0 !== r) {
1711
1711
  var n = r.call(t, e || "default");
1712
- if ("object" != be(n)) return n;
1712
+ if ("object" != de(n)) return n;
1713
1713
  throw new TypeError("@@toPrimitive must return a primitive value.");
1714
1714
  }
1715
1715
  return ("string" === e ? String : Number)(t);
1716
1716
  }(t, "string");
1717
- return "symbol" == be(e) ? e : e + "";
1717
+ return "symbol" == de(e) ? e : e + "";
1718
1718
  }(e)) in t ? Object.defineProperty(t, e, {
1719
1719
  value: r,
1720
1720
  enumerable: !0,
@@ -2256,8 +2256,8 @@ var OHLCV_INDICATORS;
2256
2256
  var f, h = Qe(l.value, 2), y = h[0], p = h[1], v = Xe(y);
2257
2257
  try {
2258
2258
  for (v.s(); !(f = v.n()).done; ) {
2259
- var d = f.value;
2260
- if (a.includes(d)) for (var b = 1; b <= p; b++) a.push("".concat(d, "_lag_").concat(b));
2259
+ var b = f.value;
2260
+ if (a.includes(b)) for (var d = 1; d <= p; d++) a.push("".concat(b, "_lag_").concat(d));
2261
2261
  }
2262
2262
  } catch (t) {
2263
2263
  v.e(t);
@@ -2479,15 +2479,15 @@ var OHLCV_INDICATORS;
2479
2479
  if (!n.hasOwnProperty(f)) throw Error('slow "'.concat(f, ' not found in crossPairs"'));
2480
2480
  o[h] = new fr, n[h] = nr(r);
2481
2481
  }
2482
- var y = void 0, p = void 0, v = void 0, d = void 0, b = void 0;
2483
- "price" === s ? (p = n.close[e], v = n.high[e], d = n.low[e], b = n[f][e], o[h].update({
2482
+ var y = void 0, p = void 0, v = void 0, b = void 0, d = void 0;
2483
+ "price" === s ? (p = n.close[e], v = n.high[e], b = n.low[e], d = n[f][e], o[h].update({
2484
2484
  fast: p,
2485
- slow: b,
2485
+ slow: d,
2486
2486
  high: v,
2487
- low: d
2488
- })) : (y = n[s][e], b = n[f][e], o[h].update({
2487
+ low: b
2488
+ })) : (y = n[s][e], d = n[f][e], o[h].update({
2489
2489
  fast: y,
2490
- slow: b
2490
+ slow: d
2491
2491
  })), t.pushToMain({
2492
2492
  index: e,
2493
2493
  key: h,
@@ -2535,22 +2535,22 @@ var OHLCV_INDICATORS;
2535
2535
  };
2536
2536
  };
2537
2537
  // ./src/studies/priceVariations.js
2538
- function dr(t) {
2538
+ function br(t) {
2539
2539
  return function(t) {
2540
- if (Array.isArray(t)) return br(t);
2540
+ if (Array.isArray(t)) return dr(t);
2541
2541
  }(t) || function(t) {
2542
2542
  if ("undefined" != typeof Symbol && null != t[Symbol.iterator] || null != t["@@iterator"]) return Array.from(t);
2543
2543
  }(t) || function(t, e) {
2544
2544
  if (t) {
2545
- if ("string" == typeof t) return br(t, e);
2545
+ if ("string" == typeof t) return dr(t, e);
2546
2546
  var r = {}.toString.call(t).slice(8, -1);
2547
- return "Object" === r && t.constructor && (r = t.constructor.name), "Map" === r || "Set" === r ? Array.from(t) : "Arguments" === r || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r) ? br(t, e) : void 0;
2547
+ return "Object" === r && t.constructor && (r = t.constructor.name), "Map" === r || "Set" === r ? Array.from(t) : "Arguments" === r || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r) ? dr(t, e) : void 0;
2548
2548
  }
2549
2549
  }(t) || function() {
2550
2550
  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
2551
2551
  }();
2552
2552
  }
2553
- function br(t, e) {
2553
+ function dr(t, e) {
2554
2554
  (null == e || e > t.length) && (e = t.length);
2555
2555
  for (var r = 0, n = Array(e); r < e; r++) n[r] = t[r];
2556
2556
  return n;
@@ -2730,10 +2730,10 @@ var OHLCV_INDICATORS;
2730
2730
  }), r.dateTime.sessionIntradayIndexCount++;
2731
2731
  },
2732
2732
  priceVariations: function(t, e) {
2733
- 0 === e && (t.priceBased = dr(new Set([].concat(dr(t.priceBased), [ "mid_price_open_close", "mid_price_high_low" ]))),
2733
+ 0 === e && (t.priceBased = br(new Set([].concat(br(t.priceBased), [ "mid_price_open_close", "mid_price_high_low" ]))),
2734
2734
  Object.assign(t.verticalOhlcv, {
2735
- mid_price_open_close: dr(t.nullArray),
2736
- mid_price_high_low: dr(t.nullArray)
2735
+ mid_price_open_close: br(t.nullArray),
2736
+ mid_price_high_low: br(t.nullArray)
2737
2737
  }));
2738
2738
  var r = t.verticalOhlcv.open[e], n = t.verticalOhlcv.high[e], o = t.verticalOhlcv.low[e], i = t.verticalOhlcv.close[e];
2739
2739
  t.pushToMain({
@@ -2759,23 +2759,23 @@ var OHLCV_INDICATORS;
2759
2759
  }), Object.assign(c, le(le({}, h, new te(r)), y, new nt(r))), Object.assign(l, le(le({}, h, ae(v)), y, ae(v))),
2760
2760
  a > 0 && t.lag([ h, y ], a), u && t.autoMinMaxKeys.push(h, y);
2761
2761
  }
2762
- var d = l[i][e], b = null, m = null;
2762
+ var b = l[i][e], d = null, m = null;
2763
2763
  // Update the RSI indicator.
2764
- c[h].update(d, s);
2764
+ c[h].update(b, s);
2765
2765
  try {
2766
- b = c[h].getResult();
2766
+ d = c[h].getResult();
2767
2767
  } catch (t) {
2768
- b = null;
2768
+ d = null;
2769
2769
  }
2770
- null !== b && "number" == typeof b && o && (b = ne(b, o)),
2770
+ null !== d && "number" == typeof d && o && (d = ne(d, o)),
2771
2771
  // Always push the RSI value, using null as a fallback.
2772
2772
  t.pushToMain({
2773
2773
  index: e,
2774
2774
  key: h,
2775
- value: b
2775
+ value: d
2776
2776
  }),
2777
2777
  // Update the SMA indicator only if a valid RSI value is available.
2778
- null !== b && "number" == typeof b && c[y].update(b, s);
2778
+ null !== d && "number" == typeof d && c[y].update(d, s);
2779
2779
  try {
2780
2780
  m = c[y].getResult();
2781
2781
  } catch (t) {
@@ -2800,19 +2800,19 @@ var OHLCV_INDICATORS;
2800
2800
  maInstance: new ve[r](n)
2801
2801
  }, u[h] = he(p), null !== a) {
2802
2802
  l[h].diffInstance = new _t(a.size, a.stdDev);
2803
- var v, d = [], b = fe(a.targets);
2803
+ var v, b = [], d = fe(a.targets);
2804
2804
  try {
2805
- for (b.s(); !(v = b.n()).done; ) {
2805
+ for (d.s(); !(v = d.n()).done; ) {
2806
2806
  var m = v.value;
2807
2807
  u["".concat(y, "_").concat(m)] = he(p), a.autoMinMax && t.autoMinMaxKeys.push("".concat(y, "_").concat(m)),
2808
- a.lag > 0 && d.push("".concat(y, "_").concat(m));
2808
+ a.lag > 0 && b.push("".concat(y, "_").concat(m));
2809
2809
  }
2810
2810
  } catch (t) {
2811
- b.e(t);
2811
+ d.e(t);
2812
2812
  } finally {
2813
- b.f();
2813
+ d.f();
2814
2814
  }
2815
- a.lag > 0 && t.lag(d, a.lag);
2815
+ a.lag > 0 && t.lag(b, a.lag);
2816
2816
  }
2817
2817
  c.push(h);
2818
2818
  }
@@ -2870,17 +2870,17 @@ var OHLCV_INDICATORS;
2870
2870
  if (!u.hasOwnProperty(a)) throw new Error("Target property ".concat(a, " not found in verticalOhlcv for macd."));
2871
2871
  var v = f.filter((function(t) {
2872
2872
  return "macd" === t.key;
2873
- })).length, d = v > 1 ? "macd_".concat(r, "_").concat(n, "_").concat(o) : "macd", b = a === Oe ? "".concat(d, "_diff") : "".concat(d, "_diff_").concat(a), m = a === Oe ? "".concat(d, "_dea") : "".concat(d, "_dea_").concat(a), g = a === Oe ? "".concat(d, "_histogram") : "".concat(d, "_histogram_").concat(a);
2873
+ })).length, b = v > 1 ? "macd_".concat(r, "_").concat(n, "_").concat(o) : "macd", d = a === Oe ? "".concat(b, "_diff") : "".concat(b, "_diff_").concat(a), m = a === Oe ? "".concat(b, "_dea") : "".concat(b, "_dea_").concat(a), g = a === Oe ? "".concat(b, "_histogram") : "".concat(b, "_histogram_").concat(a);
2874
2874
  // Choose a display prefix based on the number of indicators.
2875
2875
  h.push({
2876
- fast: b,
2876
+ fast: d,
2877
2877
  slow: m,
2878
2878
  isDefault: !0
2879
2879
  }), l.hasOwnProperty("macd") || (l.macd = {
2880
2880
  numberOfIndicators: v,
2881
2881
  settings: {}
2882
- }), l.macd.settings[s] = new zt(new Dt(r), new Dt(n), new Dt(o)), Object.assign(u, me(me(me({}, b, ge(y)), m, ge(y)), g, ge(y))),
2883
- p.push(b, m, g);
2882
+ }), l.macd.settings[s] = new zt(new Dt(r), new Dt(n), new Dt(o)), Object.assign(u, me(me(me({}, d, ge(y)), m, ge(y)), g, ge(y))),
2883
+ p.push(d, m, g);
2884
2884
  }
2885
2885
  var w = l.macd, O = w.numberOfIndicators, S = w.settings, _ = O > 1 ? "macd_".concat(r, "_").concat(n, "_").concat(o) : "macd", j = a === Oe ? "".concat(_, "_diff") : "".concat(_, "_diff_").concat(a), P = a === Oe ? "".concat(_, "_dea") : "".concat(_, "_dea_").concat(a), A = a === Oe ? "".concat(_, "_histogram") : "".concat(_, "_histogram_").concat(a), E = S[s], M = u[a][e];
2886
2886
  E.update(M, c);
@@ -2936,11 +2936,11 @@ var OHLCV_INDICATORS;
2936
2936
  var i = o.height, a = o.range, u = o.scale, l = o.lag, c = o.autoMinMax, s = "".concat(r, "_").concat(n), f = t.verticalOhlcv, h = t.instances, y = t.len;
2937
2937
  // Initialization: create output arrays and indicator instance on the first call.
2938
2938
  if (0 === e) {
2939
- var p = t.inputParams, v = t.priceBased, d = t.nullArray, b = p.filter((function(t) {
2939
+ var p = t.inputParams, v = t.priceBased, b = t.nullArray, d = p.filter((function(t) {
2940
2940
  return "donchianChannels" === t.key;
2941
- })).length, m = b > 1 ? "donchian_channel_".concat(s) : "donchian_channel", g = [ "".concat(m, "_upper"), "".concat(m, "_basis"), "".concat(m, "_lower") ];
2941
+ })).length, m = d > 1 ? "donchian_channel_".concat(s) : "donchian_channel", g = [ "".concat(m, "_upper"), "".concat(m, "_basis"), "".concat(m, "_lower") ];
2942
2942
  i && g.push("".concat(m, "_height")), h.hasOwnProperty("donchian_channel") || (h.donchian_channel = {
2943
- numberOfIndicators: b,
2943
+ numberOfIndicators: d,
2944
2944
  settings: {}
2945
2945
  });
2946
2946
  // Set up additional arrays for each range property.
@@ -2957,7 +2957,7 @@ var OHLCV_INDICATORS;
2957
2957
  O.f();
2958
2958
  }
2959
2959
  var _ = Object.fromEntries(g.map((function(t) {
2960
- return [ t, Ee(d) ];
2960
+ return [ t, Ee(b) ];
2961
2961
  })));
2962
2962
  Object.assign(f, function(t) {
2963
2963
  for (var e = 1; e < arguments.length; e++) {
@@ -3067,7 +3067,7 @@ var OHLCV_INDICATORS;
3067
3067
  return !0;
3068
3068
  },
3069
3069
  bollingerBands: function(t, e, r, n, o) {
3070
- var i, a, u, l, c, s, f, h = o.height, y = o.range, p = void 0 === y ? [] : y, v = o.target, d = o.scale, b = o.lag, m = o.autoMinMax, g = t.verticalOhlcv, w = t.instances, O = t.lastIndexReplace, S = "close" === v ? "" : "_".concat(v), _ = "".concat(r, "_").concat(n).concat(S);
3070
+ var i, a, u, l, c, s, f, h = o.height, y = o.range, p = void 0 === y ? [] : y, v = o.target, b = o.scale, d = o.lag, m = o.autoMinMax, g = t.verticalOhlcv, w = t.instances, O = t.lastIndexReplace, S = "close" === v ? "" : "_".concat(v), _ = "".concat(r, "_").concat(n).concat(S);
3071
3071
  // Initialization on the first call.
3072
3072
  if (0 === e) {
3073
3073
  var j = t.priceBased, P = t.inputParams, A = t.nullArray, E = t.verticalOhlcv;
@@ -3111,7 +3111,7 @@ var OHLCV_INDICATORS;
3111
3111
  }));
3112
3112
  }
3113
3113
  return t;
3114
- }({}, R)), b > 0 && t.lag(x, b), j.push("".concat(f, "_upper"), "".concat(f, "_middle"), "".concat(f, "_lower"));
3114
+ }({}, R)), d > 0 && t.lag(x, d), j.push("".concat(f, "_upper"), "".concat(f, "_middle"), "".concat(f, "_lower"));
3115
3115
  }
3116
3116
  // Derive prefix for subsequent calls if not set.
3117
3117
  f || (f = w.bollinger_bands.numberOfIndicators > 1 ? "bollinger_bands_".concat(_) : "bollinger_bands".concat(S));
@@ -3157,7 +3157,7 @@ var OHLCV_INDICATORS;
3157
3157
  for (q.s(); !(z = q.n()).done; ) {
3158
3158
  var $ = z.value, F = null, K = g[$][e];
3159
3159
  "number" == typeof K && "number" == typeof H && "number" == typeof N && N - H != 0 && (F = m ? Math.max(Math.min((K - H) / (N - H), 1), 0) : (K - H) / (N - H),
3160
- d && (F = ne(F, d))), t.pushToMain({
3160
+ b && (F = ne(F, b))), t.pushToMain({
3161
3161
  index: e,
3162
3162
  key: "".concat(C, "_range_").concat($),
3163
3163
  value: F
@@ -3187,19 +3187,19 @@ var OHLCV_INDICATORS;
3187
3187
  }
3188
3188
  var y = u[s], p = y.fastEMA, v = y.slowEMA;
3189
3189
  p.update(c, l), v.update(c, l);
3190
- var d = null, b = null;
3190
+ var b = null, d = null;
3191
3191
  try {
3192
- d = p.getResult();
3192
+ b = p.getResult();
3193
3193
  } catch (t) {
3194
- d = null;
3194
+ b = null;
3195
3195
  }
3196
3196
  try {
3197
- b = v.getResult();
3197
+ d = v.getResult();
3198
3198
  } catch (t) {
3199
- b = null;
3199
+ d = null;
3200
3200
  }
3201
3201
  var m = null;
3202
- return "number" == typeof d && "number" == typeof b && 0 !== b && (m = 100 * (d - b) / b,
3202
+ return "number" == typeof b && "number" == typeof d && 0 !== d && (m = 100 * (b - d) / d,
3203
3203
  i && (m = ne(m, i))), t.pushToMain({
3204
3204
  index: e,
3205
3205
  key: s,
@@ -3211,12 +3211,12 @@ var OHLCV_INDICATORS;
3211
3211
  return ce(t, e, u, l);
3212
3212
  };
3213
3213
  if (0 === e) {
3214
- for (var y = t.nullArray, p = [ [ "close", "open" ], [ "close", "high" ], [ "close", "low" ], [ "open", "high" ], [ "open", "low" ], [ "high", "low" ] ], v = [ [ "open", "open" ], [ "high", "high" ], [ "low", "low" ], [ "close", "close" ] ].concat(p), d = [], b = {}, m = 0; m < i; m++) {
3214
+ for (var y = t.nullArray, p = [ [ "close", "open" ], [ "close", "high" ], [ "close", "low" ], [ "open", "high" ], [ "open", "low" ], [ "high", "low" ] ], v = [ [ "open", "open" ], [ "high", "high" ], [ "low", "low" ], [ "close", "close" ] ].concat(p), b = [], d = {}, m = 0; m < i; m++) {
3215
3215
  var g, w = Ke(v);
3216
3216
  try {
3217
3217
  for (w.s(); !(g = w.n()).done; ) {
3218
3218
  var O = Fe(g.value, 2), S = O[0], _ = O[1];
3219
- d.push("candle_change_".concat(m + 1, "_").concat(S, "_").concat(_)), b["candle_change_".concat(m + 1, "_").concat(S, "_").concat(_)] = $e(y),
3219
+ b.push("candle_change_".concat(m + 1, "_").concat(S, "_").concat(_)), d["candle_change_".concat(m + 1, "_").concat(S, "_").concat(_)] = $e(y),
3220
3220
  l && t.autoMinMaxKeys.push("candle_change_".concat(m + 1, "_").concat(S, "_").concat(_));
3221
3221
  }
3222
3222
  } catch (t) {
@@ -3230,8 +3230,8 @@ var OHLCV_INDICATORS;
3230
3230
  j.push("candle_body_".concat(x, "_").concat(k)), P["candle_body_".concat(x, "_").concat(k)] = $e(y),
3231
3231
  l && t.autoMinMaxKeys.push("candle_body_".concat(x, "_").concat(k));
3232
3232
  }
3233
- var T = [].concat(j, d);
3234
- Object.assign(c, ze(ze({}, P), b)), Object.assign(s, {
3233
+ var T = [].concat(j, b);
3234
+ Object.assign(c, ze(ze({}, P), d)), Object.assign(s, {
3235
3235
  candleVectors: {
3236
3236
  bodyVectors: p,
3237
3237
  lookBackVectors: v,
@@ -3243,7 +3243,7 @@ var OHLCV_INDICATORS;
3243
3243
  if (0 === e) return !0;
3244
3244
  var I = s.candleVectors, R = I.bodyVectors, C = I.lookBackVectors, D = I.bodyInstance, V = null, B = c.open[e], N = c.close[e], L = We(N, B);
3245
3245
  // Update instances with current absolute values
3246
- D.update(L, f);
3246
+ D.update(Math.abs(L), f);
3247
3247
  try {
3248
3248
  V = D.getResult();
3249
3249
  } catch (t) {
@@ -3359,7 +3359,7 @@ var OHLCV_INDICATORS;
3359
3359
  };
3360
3360
  })) : [];
3361
3361
  }(i), f = n; f < o; f++) {
3362
- var h = t[f], y = h.open, p = h.high, v = h.low, d = h.close, b = wr(h, mr), m = e.precisionMultiplier, g = Ar(y, e.inputTypes.open, m), w = Ar(p, e.inputTypes.high, m), O = Ar(v, e.inputTypes.low, m), S = Ar(d, e.inputTypes.close, m);
3362
+ var h = t[f], y = h.open, p = h.high, v = h.low, b = h.close, d = wr(h, mr), m = e.precisionMultiplier, g = Ar(y, e.inputTypes.open, m), w = Ar(p, e.inputTypes.high, m), O = Ar(v, e.inputTypes.low, m), S = Ar(b, e.inputTypes.close, m);
3363
3363
  // Destructure the base keys and use the rest for other properties
3364
3364
  //sets volume to 0
3365
3365
  if (e.pushToMain({
@@ -3385,7 +3385,7 @@ var OHLCV_INDICATORS;
3385
3385
  key: "volume",
3386
3386
  value: j
3387
3387
  });
3388
- } else delete b.volume;
3388
+ } else delete d.volume;
3389
3389
  // Populate any extra keys identified during initialization
3390
3390
  var P, A = gr(e.otherKeys);
3391
3391
  try {
@@ -3394,7 +3394,7 @@ var OHLCV_INDICATORS;
3394
3394
  e.pushToMain({
3395
3395
  index: f,
3396
3396
  key: E,
3397
- value: b[E]
3397
+ value: d[E]
3398
3398
  });
3399
3399
  }
3400
3400
  // Run all indicator functions except for the ones processed later
@@ -3441,8 +3441,8 @@ var OHLCV_INDICATORS;
3441
3441
  // No valid data points
3442
3442
  return new Array(i).fill(0);
3443
3443
  for (var v = y; v < i; v++) {
3444
- var d = n[v], b = o[v];
3445
- if (null !== d && null !== b) if (u += d, l += b, c += d * b, s += d * d, f += b * b,
3444
+ var b = n[v], d = o[v];
3445
+ if (null !== b && null !== d) if (u += b, l += d, c += b * d, s += b * b, f += d * d,
3446
3446
  ++h < 2) a.push(0); else {
3447
3447
  var m = h * c - u * l, g = Math.sqrt((h * s - u * u) * (h * f - l * l)), w = 0 === g ? 0 : m / g;
3448
3448
  a.push(w);
@@ -3567,30 +3567,35 @@ var OHLCV_INDICATORS;
3567
3567
  var e = t.index, n = t.key, o = t.value;
3568
3568
  return function(t) {
3569
3569
  var e = t.main, r = t.index, n = t.key, o = t.value, i = e.precision, a = e.priceBased, u = e.minMaxRanges, l = e.verticalOhlcv, c = e.autoMinMaxKeys, s = e.precisionMultiplier;
3570
- if (e.invalidValueIndex, null == o) for (var f in u) u[f] = {
3571
- min: 1 / 0,
3572
- max: -1 / 0
3573
- };
3570
+ if (null == o) {
3571
+ e.invalidValueIndex = r;
3572
+ //do not use let for main.invalidValueIndex
3573
+ for (var f = 0, h = Object.keys(u); f < h.length; f++) u[h[f]] = {
3574
+ min: 1 / 0,
3575
+ max: -1 / 0
3576
+ };
3577
+ return l[n][r] = null, !1;
3578
+ }
3574
3579
  if (l[n][r] = o, "number" == typeof o && !n.includes("_x_")) {
3575
- var h = c.includes(n);
3576
- if (n.includes("_diff_") && h) u.hasOwnProperty(n) && u[n].min !== 1 / 0 && u[n].max !== -1 / 0 || (u[n] = {
3580
+ var y = c.includes(n);
3581
+ if (n.includes("_diff_") && y) u.hasOwnProperty(n) && u[n].min !== 1 / 0 && u[n].max !== -1 / 0 || (u[n] = {
3577
3582
  min: -1,
3578
3583
  max: 1
3579
- }); else if (n.startsWith("candle_") && h) u[n] = {
3584
+ }); else if (n.startsWith("candle_") && y) u[n] = {
3580
3585
  min: -1,
3581
3586
  max: 1
3582
- }; else if (n.includes("_range_") && h) u[n] = {
3587
+ }; else if (n.includes("_range_") && y) u[n] = {
3583
3588
  min: 0,
3584
3589
  max: 1
3585
- }; else if (n.startsWith("rsi_") && h) u[n] = {
3590
+ }; else if (n.startsWith("rsi_") && y) u[n] = {
3586
3591
  min: 0,
3587
3592
  max: 1
3588
3593
  }; else {
3589
- var y = i && a.includes(n) ? o / s : o;
3594
+ var p = i && a.includes(n) ? o / s : o;
3590
3595
  u.hasOwnProperty(n) || (u[n] = {
3591
3596
  min: 1 / 0,
3592
3597
  max: -1 / 0
3593
- }), y < u[n].min && (u[n].min = y), y > u[n].max && (u[n].max = y);
3598
+ }), p < u[n].min && (u[n].min = p), p > u[n].max && (u[n].max = p);
3594
3599
  }
3595
3600
  }
3596
3601
  return !0;
@@ -3733,7 +3738,7 @@ var OHLCV_INDICATORS;
3733
3738
  value: function(t) {
3734
3739
  var e = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
3735
3740
  i(this);
3736
- var r = de("ema", t, e, Nr);
3741
+ var r = be("ema", t, e, Nr);
3737
3742
  return this.inputParams.push({
3738
3743
  key: "movingAverages",
3739
3744
  params: [ "ema", t, r ]
@@ -3744,7 +3749,7 @@ var OHLCV_INDICATORS;
3744
3749
  value: function(t) {
3745
3750
  var e = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
3746
3751
  i(this);
3747
- var r = de("sma", t, e, Nr);
3752
+ var r = be("sma", t, e, Nr);
3748
3753
  return this.inputParams.push({
3749
3754
  key: "movingAverages",
3750
3755
  params: [ "sma", t, r ]
@@ -3838,9 +3843,9 @@ var OHLCV_INDICATORS;
3838
3843
  }, {
3839
3844
  key: "candleVectors",
3840
3845
  value: function() {
3841
- var t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 20, e = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
3846
+ var t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 200, e = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
3842
3847
  if (i(this), "number" != typeof t || t <= 0) throw new Error('"size" must be a positive number greater than 0 in candleVectors.');
3843
- var r = e.stdDev, n = void 0 === r ? .5 : r, o = e.lag, a = void 0 === o ? 0 : o, u = e.scale, l = void 0 === u ? .05 : u, c = e.patternSize, s = void 0 === c ? 1 : c, f = e.autoMinMax, h = void 0 !== f && f;
3848
+ var r = e.stdDev, n = void 0 === r ? 1 : r, o = e.lag, a = void 0 === o ? 0 : o, u = e.scale, l = void 0 === u ? .05 : u, c = e.patternSize, s = void 0 === c ? 1 : c, f = e.autoMinMax, h = void 0 !== f && f;
3844
3849
  if ("number" != typeof n || n <= 0) throw new Error('"stdDev" must be a positive number greater than 0 in candleVectors.');
3845
3850
  if ("number" == typeof l && !Nr.includes(l)) throw new Error('"scale" value in candleVectors must be any of the following numbers: '.concat(Nr.join(", ")));
3846
3851
  if ("number" != typeof s || !Number.isInteger(s) || s < 1) throw new Error('"patternSize" value in candleVectors must be an integer greater than 0.');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ohlcv-indicators",
3
- "version": "3.2.5",
3
+ "version": "3.2.7",
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",
@@ -33,6 +33,11 @@ export const classifyBoll = (value, bollingerBands, scale = 0.05, autoMinMax = f
33
33
  const rangeValue = (absValue - lower) / (upper - lower)
34
34
  let magnitude = calcMagnitude(rangeValue, scale)
35
35
 
36
+ if(magnitude === 0)
37
+ {
38
+ return (positive) ? 0.01 : -0.01
39
+ }
40
+
36
41
  if(autoMinMax)
37
42
  {
38
43
  return positive ? Math.min(magnitude, 1) : Math.max(-magnitude, -1)
@@ -1,19 +1,21 @@
1
1
  export const pushToMain = ({main, index, key, value}) => {
2
2
 
3
3
  const {precision, priceBased, minMaxRanges, verticalOhlcv, autoMinMaxKeys, precisionMultiplier} = main
4
- let {invalidValueIndex } = main
5
4
 
6
5
  if(value === null || typeof value === 'undefined')
7
6
  {
8
- invalidValueIndex = index
7
+ main.invalidValueIndex = index //do not use let for main.invalidValueIndex
9
8
 
10
- for(let k in minMaxRanges)
9
+ for(const k of Object.keys(minMaxRanges))
11
10
  {
12
11
  minMaxRanges[k] = {min: Infinity, max: -Infinity}
13
12
  }
13
+
14
+ verticalOhlcv[key][index] = null
15
+ return false
14
16
  }
15
-
16
- verticalOhlcv[key][index] = value
17
+
18
+ verticalOhlcv[key][index] = value
17
19
 
18
20
  if(typeof value === 'number' && !key.includes('_x_'))
19
21
  {