ohlcv-indicators 1.6.6 → 1.6.8
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 +1 -1
- package/src/studies/candleStudies.js +34 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ohlcv-indicators",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.8",
|
|
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",
|
|
@@ -12,6 +12,10 @@ const getCandlesStudies = (inputOhlcv, period = 20, len) => {
|
|
|
12
12
|
|
|
13
13
|
let getSize = (a, b) => Math.abs(a - b)
|
|
14
14
|
|
|
15
|
+
//candle_label
|
|
16
|
+
let candle_label = new Array(len).fill(null)
|
|
17
|
+
|
|
18
|
+
//close > open
|
|
15
19
|
let candle_direction = new Array(len).fill(null)
|
|
16
20
|
|
|
17
21
|
//body
|
|
@@ -76,19 +80,45 @@ const getCandlesStudies = (inputOhlcv, period = 20, len) => {
|
|
|
76
80
|
candle_direction[x] = candleDirection
|
|
77
81
|
|
|
78
82
|
//body
|
|
79
|
-
candle_body_size[x] =
|
|
83
|
+
candle_body_size[x] = classifySize(bodySize, bodySizeMean, 0.25)
|
|
80
84
|
|
|
81
85
|
//top
|
|
82
|
-
candle_top_size[x] =
|
|
86
|
+
candle_top_size[x] = classifySize(topSize, bodySizeMean, 0.25)
|
|
83
87
|
|
|
84
88
|
//bottom
|
|
85
|
-
candle_bottom_size[x] =
|
|
89
|
+
candle_bottom_size[x] = classifySize(bottomSize, bodySizeMean, 0.25)
|
|
86
90
|
|
|
87
91
|
//gap
|
|
88
|
-
candle_gap_size[x] =
|
|
92
|
+
candle_gap_size[x] = classifySize(gapSize, gapSizeMean, 0.25)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
//label
|
|
96
|
+
|
|
97
|
+
const labelArr = [candle_direction[x], candle_body_size[x], candle_top_size[x], candle_bottom_size[x]]
|
|
98
|
+
|
|
99
|
+
if(labelArr.every(v => typeof v === 'number'))
|
|
100
|
+
{
|
|
101
|
+
candle_label[x] = labelArr.join('_')
|
|
102
|
+
}
|
|
89
103
|
}
|
|
90
104
|
|
|
105
|
+
|
|
106
|
+
// Create a Map for unique labels with indices
|
|
107
|
+
const labelMap = new Map();
|
|
108
|
+
let labelIndex = 0;
|
|
109
|
+
|
|
110
|
+
// Populate the label map and assign indices only once
|
|
111
|
+
for (const label of candle_label) {
|
|
112
|
+
if (label !== null && !labelMap.has(label)) {
|
|
113
|
+
labelMap.set(label, labelIndex++);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Transform candle_label in place using the labelMap for quick lookup
|
|
118
|
+
candle_label = candle_label.map(v => (v !== null && labelMap.has(v)) ? labelMap.get(v) : null);
|
|
119
|
+
|
|
91
120
|
return {
|
|
121
|
+
candle_label,
|
|
92
122
|
candle_direction,
|
|
93
123
|
candle_gap_size,
|
|
94
124
|
candle_body_size,
|