ohlcv-indicators 3.5.0 → 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/dist/ohlcv-indicators.min.js +1 -4225
- package/index.js +6 -3
- package/package.json +1 -1
- package/src/volatility/atr.js +34 -14
- package/webpack.config.js +3 -3
package/index.js
CHANGED
|
@@ -268,12 +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,
|
|
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
|
-
|
|
274
|
+
validateBoolean(percentage, 'options.percentage', 'atr')
|
|
275
275
|
|
|
276
|
-
|
|
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')
|
|
278
|
+
|
|
279
|
+
this.inputParams.push({key: methodName, params: [size, {lag, percentage, upper, lower}]})
|
|
277
280
|
|
|
278
281
|
return this
|
|
279
282
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ohlcv-indicators",
|
|
3
|
-
"version": "3.5.
|
|
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",
|
package/src/volatility/atr.js
CHANGED
|
@@ -1,27 +1,36 @@
|
|
|
1
1
|
|
|
2
2
|
import {FasterATR, FasterWSMA} from 'trading-signals';
|
|
3
3
|
|
|
4
|
-
export const atr = (main, index, size, {lag,
|
|
4
|
+
export const atr = (main, index, size, {lag, percentage, upper, lower}) => {
|
|
5
5
|
const { verticalOhlcv, instances } = main
|
|
6
|
-
const
|
|
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[
|
|
12
|
+
instances[baseKeyName] = new FasterATR(size, FasterWSMA)
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
const keyNames = [baseKeyName]
|
|
15
|
+
|
|
16
|
+
if(percentage) keyNames.push(`${baseKeyName}_percentage`)
|
|
17
|
+
if(upper !== null) keyNames.push(`${baseKeyName}_upper`)
|
|
18
|
+
if(lower !== null) keyNames.push(`${baseKeyName}_lower`)
|
|
19
|
+
|
|
20
|
+
for(const k of keyNames)
|
|
15
21
|
{
|
|
16
|
-
|
|
22
|
+
if(!k.endsWith('_percentage'))
|
|
23
|
+
{
|
|
24
|
+
priceBased.add(k)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
verticalOhlcv[k] = new Float64Array(len).fill(NaN)
|
|
28
|
+
arrayTypes[k] = 'Float64Array'
|
|
17
29
|
}
|
|
18
|
-
|
|
19
|
-
verticalOhlcv[keyName] = new Float64Array(len).fill(NaN)
|
|
20
|
-
arrayTypes[keyName] = 'Float64Array'
|
|
21
|
-
|
|
30
|
+
|
|
22
31
|
if(lag > 0)
|
|
23
32
|
{
|
|
24
|
-
main.lag(
|
|
33
|
+
main.lag(keyNames, lag)
|
|
25
34
|
}
|
|
26
35
|
}
|
|
27
36
|
|
|
@@ -31,7 +40,7 @@ export const atr = (main, index, size, {lag, type}) => {
|
|
|
31
40
|
low: verticalOhlcv.low[index],
|
|
32
41
|
close: verticalOhlcv.close[index],
|
|
33
42
|
}
|
|
34
|
-
const instance = instances[
|
|
43
|
+
const instance = instances[baseKeyName]
|
|
35
44
|
|
|
36
45
|
// Update the moving average instance.
|
|
37
46
|
instance.update(curr);
|
|
@@ -42,13 +51,24 @@ export const atr = (main, index, size, {lag, type}) => {
|
|
|
42
51
|
|
|
43
52
|
}
|
|
44
53
|
|
|
45
|
-
if(
|
|
54
|
+
if(percentage)
|
|
55
|
+
{
|
|
56
|
+
const percentageValue = (Number.isNaN(currAtr)) ? NaN : (currAtr / curr.close)
|
|
57
|
+
main.pushToMain({ index, key: `${baseKeyName}_percentage`, value: percentageValue });
|
|
58
|
+
}
|
|
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)
|
|
46
65
|
{
|
|
47
|
-
|
|
66
|
+
const lowerValue = (Number.isNaN(currAtr)) ? NaN : (curr.close - (currAtr * lower))
|
|
67
|
+
main.pushToMain({ index, key: `${baseKeyName}_lower`, value: lowerValue });
|
|
48
68
|
}
|
|
49
69
|
|
|
50
70
|
// Always push the MA value (even if NaN).
|
|
51
|
-
main.pushToMain({ index, key:
|
|
71
|
+
main.pushToMain({ index, key: baseKeyName, value: currAtr });
|
|
52
72
|
|
|
53
73
|
return true;
|
|
54
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
|
-
|
|
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
|
{
|