ohlcv-indicators 1.7.0 → 1.7.2
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 +25 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ohlcv-indicators",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.2",
|
|
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)
|
|
@@ -128,14 +136,22 @@ 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); // Adjusted threshold for 'large'
|
|
143
|
+
const smallThreshold = mean * (1 - threshold * 2); // Adjusted threshold for 'small'
|
|
144
|
+
|
|
145
|
+
if (value > largeThreshold) {
|
|
146
|
+
return 1; // Large
|
|
147
|
+
} else if (value > smallThreshold) {
|
|
148
|
+
return 0.5; // Medium
|
|
149
|
+
} else {
|
|
150
|
+
return 0; // Small
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
133
154
|
|
|
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
155
|
|
|
140
156
|
const calculateHighLowEmptyGaps = (current, prev) => {
|
|
141
157
|
// This function calculates the empty gaps between the current high/low and the previous high/low.
|