ohlcv-indicators 3.2.8 → 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",
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
|
|
2
2
|
import {FasterEMA, FasterSMA, FasterBollingerBands} from 'trading-signals';
|
|
3
|
-
import { classifyBoll } from '../utilities/classification.js'
|
|
3
|
+
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' &&
|
|
@@ -89,6 +89,7 @@ export const movingAverages = (main, index, indicatorName, size, { target, diff,
|
|
|
89
89
|
// Update the diff indicator only if diffValue is a valid number.
|
|
90
90
|
if (diffValue !== null && typeof diffValue === 'number') {
|
|
91
91
|
diffInstance.update(Math.abs(diffValue), lastIndexReplace);
|
|
92
|
+
|
|
92
93
|
}
|
|
93
94
|
|
|
94
95
|
let diffBoll = null;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
const diff = (a, b) => (a - b)
|
|
2
2
|
|
|
3
|
+
import { calcZScore } from "../utilities/classification.js"
|
|
4
|
+
|
|
3
5
|
export const candleVectors = (main, index, size, {patternSize, lag, autoMinMax}) => {
|
|
4
6
|
|
|
5
7
|
const { verticalOhlcv, instances, lastIndexReplace } = main
|
|
@@ -117,29 +119,3 @@ export const candleVectors = (main, index, size, {patternSize, lag, autoMinMax})
|
|
|
117
119
|
}
|
|
118
120
|
|
|
119
121
|
|
|
120
|
-
const calcZScore = (arrayChunk, key, size, difference, lastIndexReplace) => {
|
|
121
|
-
|
|
122
|
-
if(lastIndexReplace)
|
|
123
|
-
{
|
|
124
|
-
arrayChunk[key][arrayChunk[key].length - 1] = difference
|
|
125
|
-
}
|
|
126
|
-
else
|
|
127
|
-
{
|
|
128
|
-
arrayChunk[key].push(difference)
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
if (arrayChunk[key].length > size) {
|
|
133
|
-
arrayChunk[key].shift(); // Removes the first element to maintain array size
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if(arrayChunk.length < size) return null
|
|
137
|
-
|
|
138
|
-
const mean = arrayChunk[key].reduce((sum, value) => sum + value, 0) / size
|
|
139
|
-
|
|
140
|
-
const stdDev = Math.sqrt(
|
|
141
|
-
arrayChunk[key].reduce((sum, value) => sum + (value - mean) ** 2, 0) / size
|
|
142
|
-
)
|
|
143
|
-
|
|
144
|
-
return (difference - mean) / stdDev
|
|
145
|
-
}
|
|
@@ -47,3 +47,31 @@ export const classifyBoll = (value, bollingerBands, scale = 0.05, autoMinMax = f
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
export const calcZScore = (arrayChunk, key, size, difference, lastIndexReplace) => {
|
|
53
|
+
|
|
54
|
+
if(lastIndexReplace)
|
|
55
|
+
{
|
|
56
|
+
arrayChunk[key][arrayChunk[key].length - 1] = difference
|
|
57
|
+
}
|
|
58
|
+
else
|
|
59
|
+
{
|
|
60
|
+
arrayChunk[key].push(difference)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
if (arrayChunk[key].length > size) {
|
|
65
|
+
arrayChunk[key].shift(); // Removes the first element to maintain array size
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if(arrayChunk.length < size) return null
|
|
69
|
+
|
|
70
|
+
const mean = arrayChunk[key].reduce((sum, value) => sum + value, 0) / size
|
|
71
|
+
|
|
72
|
+
const stdDev = Math.sqrt(
|
|
73
|
+
arrayChunk[key].reduce((sum, value) => sum + (value - mean) ** 2, 0) / size
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
return (difference - mean) / stdDev
|
|
77
|
+
}
|