ohlcv-indicators 1.6.9 → 1.7.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/package.json +1 -1
- package/src/studies/candleStudies.js +31 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ohlcv-indicators",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.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",
|
|
@@ -32,6 +32,8 @@ const getCandlesStudies = (inputOhlcv, period = 20, len) => {
|
|
|
32
32
|
|
|
33
33
|
//instances
|
|
34
34
|
let bodyInstance = new FasterSMA(period)
|
|
35
|
+
let topInstance = new FasterSMA(period)
|
|
36
|
+
let bottomInstance = new FasterSMA(period)
|
|
35
37
|
let gapInstance = new FasterSMA(parseInt(period/2))
|
|
36
38
|
|
|
37
39
|
for(let x = 0; x < len; x++)
|
|
@@ -42,6 +44,8 @@ const getCandlesStudies = (inputOhlcv, period = 20, len) => {
|
|
|
42
44
|
: null
|
|
43
45
|
let bodySizeMean = null
|
|
44
46
|
let gapSizeMean = null
|
|
47
|
+
let bottomSizeMean = null
|
|
48
|
+
let topSizeMean = null
|
|
45
49
|
const bodySize = getSize(open, close)
|
|
46
50
|
let topSize
|
|
47
51
|
let bottomSize
|
|
@@ -59,6 +63,8 @@ const getCandlesStudies = (inputOhlcv, period = 20, len) => {
|
|
|
59
63
|
}
|
|
60
64
|
|
|
61
65
|
bodyInstance.update(bodySize)
|
|
66
|
+
topInstance.update(topSize)
|
|
67
|
+
bottomInstance.update(bottomSize)
|
|
62
68
|
|
|
63
69
|
if(gapSize)
|
|
64
70
|
{
|
|
@@ -69,6 +75,8 @@ const getCandlesStudies = (inputOhlcv, period = 20, len) => {
|
|
|
69
75
|
try
|
|
70
76
|
{
|
|
71
77
|
bodySizeMean = bodyInstance.getResult()
|
|
78
|
+
topSizeMean = topInstance.getResult()
|
|
79
|
+
bottomSizeMean = bottomInstance.getResult()
|
|
72
80
|
gapSizeMean = gapInstance.getResult()
|
|
73
81
|
}
|
|
74
82
|
catch(err)
|
|
@@ -83,10 +91,10 @@ const getCandlesStudies = (inputOhlcv, period = 20, len) => {
|
|
|
83
91
|
candle_body_size[x] = classifySize(bodySize, bodySizeMean, 0.25)
|
|
84
92
|
|
|
85
93
|
//top
|
|
86
|
-
candle_top_size[x] = classifySize(topSize,
|
|
94
|
+
candle_top_size[x] = classifySize(topSize, topSizeMean, 0.1)
|
|
87
95
|
|
|
88
96
|
//bottom
|
|
89
|
-
candle_bottom_size[x] = classifySize(bottomSize,
|
|
97
|
+
candle_bottom_size[x] = classifySize(bottomSize, bottomSizeMean, 0.1)
|
|
90
98
|
|
|
91
99
|
//gap
|
|
92
100
|
candle_gap_size[x] = classifySize(gapSize, gapSizeMean, 0.25)
|
|
@@ -94,7 +102,7 @@ const getCandlesStudies = (inputOhlcv, period = 20, len) => {
|
|
|
94
102
|
|
|
95
103
|
//label
|
|
96
104
|
|
|
97
|
-
const labelArr = [
|
|
105
|
+
const labelArr = [candle_direction[x], candle_body_size[x], candle_top_size[x], candle_bottom_size[x]]
|
|
98
106
|
|
|
99
107
|
if(labelArr.every(v => typeof v === 'number'))
|
|
100
108
|
{
|
|
@@ -128,14 +136,27 @@ const getCandlesStudies = (inputOhlcv, period = 20, len) => {
|
|
|
128
136
|
}
|
|
129
137
|
|
|
130
138
|
|
|
131
|
-
|
|
132
|
-
|
|
139
|
+
const classifySize = (value, mean, threshold = 0.25) => {
|
|
140
|
+
if (value === null || mean === null) return null;
|
|
141
|
+
|
|
142
|
+
const largeThreshold = mean * (1 + threshold * 4); // Sensitively tuned for large
|
|
143
|
+
const mediumThreshold = mean * (1 + threshold * 2); // Sensitively tuned for medium
|
|
144
|
+
const smallThreshold = mean * (1 - threshold * 2); // Sensitively tuned for small
|
|
145
|
+
|
|
146
|
+
if (value > largeThreshold) {
|
|
147
|
+
return 1; // Large
|
|
148
|
+
} else if (value > mediumThreshold) {
|
|
149
|
+
return 0.75; // Medium-Large
|
|
150
|
+
} else if (value > mean) {
|
|
151
|
+
return 0.5; // Medium
|
|
152
|
+
} else if (value > smallThreshold) {
|
|
153
|
+
return 0.25; // Small-Medium
|
|
154
|
+
} else {
|
|
155
|
+
return 0; // Small
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
133
159
|
|
|
134
|
-
if(value === null || mean === null) return null
|
|
135
|
-
if(value > mean * (number*5)) return 1
|
|
136
|
-
else if(value < mean * (number*3)) return 0
|
|
137
|
-
else return number * 2
|
|
138
|
-
}
|
|
139
160
|
|
|
140
161
|
const calculateHighLowEmptyGaps = (current, prev) => {
|
|
141
162
|
// This function calculates the empty gaps between the current high/low and the previous high/low.
|