ohlcv-indicators 3.4.9 → 3.5.1

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
@@ -268,14 +268,15 @@ export default class OHLCV_INDICATORS {
268
268
  validateNumber(size, {min: 1, max: this.len, allowDecimals: false}, 'size', methodName)
269
269
  validateObject(options, 'options', methodName)
270
270
 
271
- const {lag = 0, tp = null, sl = null} = options
271
+ const {lag = 0, percentage = false, upper = null, lower = null} = options
272
272
 
273
273
  validateNumber(lag, {min: 0, max: this.len, allowDecimals: false}, 'options.lag', methodName)
274
+ validateBoolean(percentage, 'options.percentage', 'atr')
274
275
 
275
- if(tp !== null) validateNumber(tp, {min: 0.01, max: 100, allowDecimals: true}, 'options.tp', methodName)
276
- if(sl !== null) validateNumber(sl, {min: 0.01, max: 100, allowDecimals: true}, 'options.tp', methodName)
276
+ if(upper !== null) validateNumber(upper, {min: 0.001, max: 100, allowDecimals: true}, 'options.upper', 'atr')
277
+ if(lower !== null) validateNumber(lower, {min: 0.001, max: 100, allowDecimals: true}, 'options.lower', 'atr')
277
278
 
278
- this.inputParams.push({key: methodName, params: [size, {lag, tp, sl}]})
279
+ this.inputParams.push({key: methodName, params: [size, {lag, percentage, upper, lower}]})
279
280
 
280
281
  return this
281
282
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ohlcv-indicators",
3
- "version": "3.4.9",
3
+ "version": "3.5.1",
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,35 +1,32 @@
1
1
 
2
2
  import {FasterATR, FasterWSMA} from 'trading-signals';
3
3
 
4
- export const atr = (main, index, size, {lag, tp, sl}) => {
4
+ export const atr = (main, index, size, {lag, percentage, upper, lower}) => {
5
5
  const { verticalOhlcv, instances } = main
6
- const keyName = `atr_${size}`
6
+ const baseKeyName = `atr_${size}`
7
7
 
8
8
  if (index === 0) {
9
9
 
10
10
  const {instances, verticalOhlcv, arrayTypes, len, priceBased} = main
11
11
 
12
- instances[keyName] = new FasterATR(size, FasterWSMA)
13
-
14
- const keyNames = [keyName]
12
+ instances[baseKeyName] = new FasterATR(size, FasterWSMA)
15
13
 
16
- if(tp !== null)
17
- {
18
- keyNames.push(`${keyName}_tp`)
19
- }
14
+ const keyNames = [baseKeyName]
20
15
 
21
- if(sl !== null)
22
- {
23
- keyNames.push(`${keyName}_sl`)
24
- }
16
+ if(percentage) keyNames.push(`${baseKeyName}_percentage`)
17
+ if(upper !== null) keyNames.push(`${baseKeyName}_upper`)
18
+ if(lower !== null) keyNames.push(`${baseKeyName}_lower`)
25
19
 
26
20
  for(const k of keyNames)
27
21
  {
28
- priceBased.add(k)
22
+ if(!k.endsWith('_percentage'))
23
+ {
24
+ priceBased.add(k)
25
+ }
26
+
29
27
  verticalOhlcv[k] = new Float64Array(len).fill(NaN)
30
28
  arrayTypes[k] = 'Float64Array'
31
29
  }
32
-
33
30
 
34
31
  if(lag > 0)
35
32
  {
@@ -43,7 +40,7 @@ export const atr = (main, index, size, {lag, tp, sl}) => {
43
40
  low: verticalOhlcv.low[index],
44
41
  close: verticalOhlcv.close[index],
45
42
  }
46
- const instance = instances[keyName]
43
+ const instance = instances[baseKeyName]
47
44
 
48
45
  // Update the moving average instance.
49
46
  instance.update(curr);
@@ -54,18 +51,24 @@ export const atr = (main, index, size, {lag, tp, sl}) => {
54
51
 
55
52
  }
56
53
 
57
- if(tp !== null)
54
+ if(percentage)
58
55
  {
59
- main.pushToMain({ index, key: `${keyName}_tp`, value: (!Number.isNaN(currAtr)) ? curr.close + (currAtr*tp) : NaN });
56
+ const percentageValue = (Number.isNaN(currAtr)) ? NaN : (currAtr / curr.close)
57
+ main.pushToMain({ index, key: `${baseKeyName}_percentage`, value: percentageValue });
60
58
  }
61
-
62
- if(sl !== null)
59
+ if(upper !== null)
60
+ {
61
+ const upperValue = (Number.isNaN(currAtr)) ? NaN : (curr.close + (currAtr * upper))
62
+ main.pushToMain({ index, key: `${baseKeyName}_upper`, value: upperValue });
63
+ }
64
+ if(lower !== null)
63
65
  {
64
- main.pushToMain({ index, key: `${keyName}_sl`, value: (!Number.isNaN(currAtr)) ? curr.close - (currAtr*sl) : NaN });
66
+ const lowerValue = (Number.isNaN(currAtr)) ? NaN : (curr.close - (currAtr * lower))
67
+ main.pushToMain({ index, key: `${baseKeyName}_lower`, value: lowerValue });
65
68
  }
66
69
 
67
70
  // Always push the MA value (even if NaN).
68
- main.pushToMain({ index, key: keyName, value: currAtr });
71
+ main.pushToMain({ index, key: baseKeyName, value: currAtr });
69
72
 
70
73
  return true;
71
74
  }
package/webpack.config.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { resolve, dirname } from 'path';
2
2
  import { fileURLToPath } from 'url';
3
- import TerserPlugin from 'terser-webpack-plugin';
3
+ //import TerserPlugin from 'terser-webpack-plugin';
4
4
 
5
5
  const __dirname = dirname(fileURLToPath(import.meta.url));
6
6
 
@@ -16,7 +16,7 @@ export default {
16
16
  output,
17
17
  mode: 'production',
18
18
  target: 'web',
19
- optimization: { //TerserPlugin start
19
+ /* optimization: { //TerserPlugin start
20
20
  minimize: true,
21
21
  minimizer: [
22
22
  new TerserPlugin({
@@ -28,7 +28,7 @@ export default {
28
28
  },
29
29
  }),
30
30
  ],
31
- }, // TerserPlugin end
31
+ }, // TerserPlugin end */
32
32
  module: {
33
33
  rules: [
34
34
  {