ohlcv-indicators 3.2.9 → 3.3.0
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.
|
|
3
|
+
"version": "3.3.0",
|
|
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",
|
|
@@ -4,7 +4,7 @@ import { classifyBoll, calcZScore } from '../utilities/classification.js'
|
|
|
4
4
|
|
|
5
5
|
const indicatorClasses = {ema: FasterEMA, sma: FasterSMA}
|
|
6
6
|
|
|
7
|
-
export const movingAverages = (main, index, indicatorName, size, { target, diff
|
|
7
|
+
export const movingAverages = (main, index, indicatorName, size, { target, diff }) => {
|
|
8
8
|
const { verticalOhlcv, instances, priceBased, lastIndexReplace } = main;
|
|
9
9
|
let suffix =
|
|
10
10
|
typeof target === 'string' &&
|
|
@@ -26,8 +26,7 @@ export const movingAverages = (main, index, indicatorName, size, { target, diff,
|
|
|
26
26
|
|
|
27
27
|
// Create the main moving average instance.
|
|
28
28
|
instances[keyName] = {
|
|
29
|
-
maInstance: new indicatorClasses[indicatorName](size)
|
|
30
|
-
arrayChunk: {[diffKeyName]: []}
|
|
29
|
+
maInstance: new indicatorClasses[indicatorName](size)
|
|
31
30
|
};
|
|
32
31
|
|
|
33
32
|
verticalOhlcv[keyName] = [...nullArray];
|
|
@@ -64,7 +63,7 @@ export const movingAverages = (main, index, indicatorName, size, { target, diff,
|
|
|
64
63
|
|
|
65
64
|
// Retrieve the current price value.
|
|
66
65
|
const value = verticalOhlcv[target][index];
|
|
67
|
-
const { maInstance, diffInstance
|
|
66
|
+
const { maInstance, diffInstance } = instances[keyName];
|
|
68
67
|
|
|
69
68
|
// Update the moving average instance.
|
|
70
69
|
maInstance.update(value, lastIndexReplace);
|
|
@@ -83,7 +82,6 @@ export const movingAverages = (main, index, indicatorName, size, { target, diff,
|
|
|
83
82
|
for (const targetKey of diff.targets) {
|
|
84
83
|
// Compute diffValue only if we have a valid MA value.
|
|
85
84
|
let diffValue = null;
|
|
86
|
-
let zScore = null
|
|
87
85
|
if (currMa !== null && typeof currMa === 'number') {
|
|
88
86
|
diffValue = verticalOhlcv[targetKey][index] - currMa;
|
|
89
87
|
}
|
|
@@ -92,7 +90,6 @@ export const movingAverages = (main, index, indicatorName, size, { target, diff,
|
|
|
92
90
|
if (diffValue !== null && typeof diffValue === 'number') {
|
|
93
91
|
diffInstance.update(Math.abs(diffValue), lastIndexReplace);
|
|
94
92
|
|
|
95
|
-
zScore = calcZScore(arrayChunk, diffKeyName, diff.size, diffValue, lastIndexReplace)
|
|
96
93
|
}
|
|
97
94
|
|
|
98
95
|
let diffBoll = null;
|
|
@@ -106,7 +103,7 @@ export const movingAverages = (main, index, indicatorName, size, { target, diff,
|
|
|
106
103
|
main.pushToMain({
|
|
107
104
|
index,
|
|
108
105
|
key: `${diffKeyName}_${targetKey}`,
|
|
109
|
-
value:
|
|
106
|
+
value: classified
|
|
110
107
|
});
|
|
111
108
|
}
|
|
112
109
|
}
|