ohlcv-indicators 1.8.6 → 1.8.7
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": "1.8.
|
|
3
|
+
"version": "1.8.7",
|
|
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,5 +1,5 @@
|
|
|
1
1
|
import {FasterSMA} from 'trading-signals'
|
|
2
|
-
import {
|
|
2
|
+
import { classifySize } from '../utilities/classification.js'
|
|
3
3
|
|
|
4
4
|
export const candlesStudies = (main, period, classify, classificationLevels) => {
|
|
5
5
|
|
|
@@ -62,14 +62,15 @@ const getCandlesStudies = (inputOhlcv, period = 20, len, classify = true, classi
|
|
|
62
62
|
let positionMean = null
|
|
63
63
|
|
|
64
64
|
//directions
|
|
65
|
-
const
|
|
66
|
-
const
|
|
65
|
+
const isUp = close > open
|
|
66
|
+
const candleBodySize = Math.abs(close - open)
|
|
67
|
+
const shadowSize = Math.abs(curr.high - curr.low)
|
|
67
68
|
|
|
68
69
|
//sizes
|
|
69
70
|
const topSize = high - Math.max(open, close)
|
|
70
71
|
const bottomSize = Math.min(open, close) - low
|
|
71
|
-
const gapSize = prev.close - curr.open
|
|
72
|
-
const position = curr.close - prev.close
|
|
72
|
+
const gapSize = Math.abs(prev.close - curr.open)
|
|
73
|
+
const position = Math.abs(curr.close - prev.close)
|
|
73
74
|
|
|
74
75
|
if(classify)
|
|
75
76
|
{
|
|
@@ -103,10 +104,18 @@ const getCandlesStudies = (inputOhlcv, period = 20, len, classify = true, classi
|
|
|
103
104
|
}
|
|
104
105
|
|
|
105
106
|
//negatives and positives
|
|
106
|
-
candle_body_size[x] =
|
|
107
|
-
|
|
108
|
-
|
|
107
|
+
candle_body_size[x] = (isUp)
|
|
108
|
+
? classifySize(candleBodySize, bodySizeMean, 2, changeLevel)
|
|
109
|
+
: -Math.abs(classifySize(candleBodySize, bodySizeMean, 2, changeLevel)) || 0;
|
|
109
110
|
|
|
111
|
+
candle_gap_size[x] = (isUp)
|
|
112
|
+
? classifySize(gapSize, gapMean, 2, changeLevel)
|
|
113
|
+
: -Math.abs(classifySize(gapSize, gapMean, 2, changeLevel)) || 0;
|
|
114
|
+
|
|
115
|
+
candle_position[x] = (isUp)
|
|
116
|
+
? classifySize(position, positionMean, 2, changeLevel)
|
|
117
|
+
: -Math.abs(classifySize(position, positionMean, 2, changeLevel)) || 0;
|
|
118
|
+
|
|
110
119
|
//positives only
|
|
111
120
|
candle_top_size[x] = classifySize(topSize, topSizeMean, 0.5, sizeLevel)
|
|
112
121
|
candle_bottom_size[x] = classifySize(bottomSize, bottomSizeMean, 0.5, sizeLevel)
|
|
@@ -18,32 +18,4 @@ export const classifySize = (value, mean, standardDeviation = 1.5, numLevels = 5
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
return 0
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export const classifyChange = (value, mean, standardDeviation = 0.5, numLevels = 7) => {
|
|
25
|
-
if (value === null || mean === null || standardDeviation === null) return null;
|
|
26
|
-
if (numLevels < 2) throw new Error("numLevels must be at least 2");
|
|
27
|
-
|
|
28
|
-
// Handle numLevels == 2 explicitly
|
|
29
|
-
if (numLevels === 2) {
|
|
30
|
-
return value >= mean ? 1 : -1;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Calculate the range for each level
|
|
34
|
-
const step = (4 * standardDeviation) / (numLevels - 1);
|
|
35
|
-
const thresholds = [];
|
|
36
|
-
|
|
37
|
-
for (let i = 0; i < numLevels - 1; i++) {
|
|
38
|
-
thresholds.push(mean - (2 * standardDeviation) + (i * step));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Classify the value based on calculated thresholds
|
|
42
|
-
for (let i = thresholds.length - 1; i >= 0; i--) {
|
|
43
|
-
if (value > thresholds[i]) {
|
|
44
|
-
return (i - Math.floor((numLevels - 1) / 2)) / Math.floor((numLevels - 1) / 2);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return -1;
|
|
49
|
-
};
|
|
21
|
+
}
|