ohlcv-indicators 3.5.76 → 3.5.77

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.76",
3
+ "version": "3.5.77",
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",
@@ -1,11 +1,26 @@
1
1
  export const isNumber = v => v != null && Number.isFinite(v)
2
2
 
3
+
3
4
  export const mathLog = (a, b) => {
4
5
 
6
+
7
+ const epsilon = 0.001
8
+
9
+ // Add epsilon to avoid log(0)
10
+ if (a === 0) a = epsilon
11
+ if (b === 0) b = epsilon
12
+
13
+ // Validate a and b have the same sign
14
+ if (Math.sign(a) !== Math.sign(b)) {
15
+ throw new Error(`[BUG] Params must have the same sign in mathLog a=${a} b=${b}.`)
16
+ }
17
+
18
+ // If both negative, flip signs — log requires positive values
19
+ if (a < 0) { a = -a; b = -b }
20
+
5
21
  const log = Math.log(a / b)
6
22
 
7
- //checks if NaN, Infinity
8
- if(!isNumber(log)) throw new Error(`[BUG] Invalid params passed to mathLog a=${a} b=${b}.`)
23
+ if (!isNumber(log)) throw new Error(`[BUG] Invalid params passed to mathLog a=${a} b=${b}.`)
9
24
 
10
25
  return log
11
26
  }