ohlcv-indicators 1.8.8 → 1.9.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/index.js +32 -0
- package/package.json +1 -1
- package/src/studies/candleStudies.js +51 -51
package/index.js
CHANGED
|
@@ -236,4 +236,36 @@ export default class OHLCV_INDICATORS {
|
|
|
236
236
|
return this
|
|
237
237
|
}
|
|
238
238
|
|
|
239
|
+
map(callback)
|
|
240
|
+
{
|
|
241
|
+
this.compute()
|
|
242
|
+
|
|
243
|
+
const keyNames = Object.keys(this.verticalOhlcv)
|
|
244
|
+
const result = {}
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
for(let x = 0; x < this.len; x++)
|
|
248
|
+
{
|
|
249
|
+
let row = {}
|
|
250
|
+
|
|
251
|
+
for(let k = 0; k < keyNames.length; k++)
|
|
252
|
+
{
|
|
253
|
+
Object.assign(row, {[keyNames[k]]: this.verticalOhlcv[keyNames[k]][x]})
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
for(const [k, value] of Object.entries(callback(row)))
|
|
257
|
+
{
|
|
258
|
+
if(x === 0)
|
|
259
|
+
{
|
|
260
|
+
result[k] = new Array(this.len).fill(null)
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
result[k][x] = value
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
Object.assign(this.indicators, result)
|
|
268
|
+
|
|
269
|
+
return this
|
|
270
|
+
}
|
|
239
271
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ohlcv-indicators",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.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",
|
|
@@ -19,10 +19,10 @@ const getCandlesStudies = (inputOhlcv, period = 20, len, classify = true, classi
|
|
|
19
19
|
let candle_bottom_size = new Array(len).fill(null) //scaled bottom size(0, 0.5 and 1)
|
|
20
20
|
let candle_gap_size = new Array(len).fill(null) //scaled gap between the current open and previous close (-1 to 1)
|
|
21
21
|
let candle_shadow_size = new Array(len).fill(null) //scaled shadow size high - slow
|
|
22
|
-
let
|
|
23
|
-
let
|
|
24
|
-
let
|
|
25
|
-
let
|
|
22
|
+
let candle_close_direction = new Array(len).fill(null) //scaled shadow size curr.close - prev.close
|
|
23
|
+
let candle_high_direction = new Array(len).fill(null) //scaled shadow size curr.high - prev.high
|
|
24
|
+
let candle_low_direction = new Array(len).fill(null) //scaled shadow size curr.low - prev.low
|
|
25
|
+
let candle_open_direction = new Array(len).fill(null) //scaled shadow size curr.open - prev.open
|
|
26
26
|
|
|
27
27
|
//instances
|
|
28
28
|
let topInstance
|
|
@@ -30,10 +30,10 @@ const getCandlesStudies = (inputOhlcv, period = 20, len, classify = true, classi
|
|
|
30
30
|
let gapInstance
|
|
31
31
|
let bodySizeInstance
|
|
32
32
|
let shadowSizeInstance
|
|
33
|
-
let
|
|
34
|
-
let
|
|
35
|
-
let
|
|
36
|
-
let
|
|
33
|
+
let closeDirectionInstance
|
|
34
|
+
let highDirectionInstance
|
|
35
|
+
let lowDirectionInstance
|
|
36
|
+
let openDirectionInstance
|
|
37
37
|
|
|
38
38
|
if(classify)
|
|
39
39
|
{
|
|
@@ -42,10 +42,10 @@ const getCandlesStudies = (inputOhlcv, period = 20, len, classify = true, classi
|
|
|
42
42
|
gapInstance = new FasterSMA(period)
|
|
43
43
|
bodySizeInstance = new FasterSMA(period)
|
|
44
44
|
shadowSizeInstance = new FasterSMA(period)
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
closeDirectionInstance = new FasterSMA(period)
|
|
46
|
+
highDirectionInstance = new FasterSMA(period)
|
|
47
|
+
lowDirectionInstance = new FasterSMA(period)
|
|
48
|
+
openDirectionInstance = new FasterSMA(period)
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
for(let x = 0; x < len; x++)
|
|
@@ -64,10 +64,10 @@ const getCandlesStudies = (inputOhlcv, period = 20, len, classify = true, classi
|
|
|
64
64
|
let topSizeMean = null
|
|
65
65
|
let bodySizeMean = null
|
|
66
66
|
let shadowSizeMean = null
|
|
67
|
-
let
|
|
68
|
-
let
|
|
69
|
-
let
|
|
70
|
-
let
|
|
67
|
+
let closeDirectionMean = null
|
|
68
|
+
let highDirectionMean = null
|
|
69
|
+
let lowDirectionMean = null
|
|
70
|
+
let openDirectionMean = null
|
|
71
71
|
|
|
72
72
|
//directions
|
|
73
73
|
const isUp = close > open
|
|
@@ -78,10 +78,10 @@ const getCandlesStudies = (inputOhlcv, period = 20, len, classify = true, classi
|
|
|
78
78
|
const topSize = high - Math.max(open, close)
|
|
79
79
|
const bottomSize = Math.min(open, close) - low
|
|
80
80
|
const gapSize = Math.abs(prev.close - curr.open)
|
|
81
|
-
const
|
|
82
|
-
const
|
|
83
|
-
const
|
|
84
|
-
const
|
|
81
|
+
const closeDirection = Math.abs(curr.close - prev.close)
|
|
82
|
+
const highDirection = Math.abs(curr.high - prev.high)
|
|
83
|
+
const lowDirection = Math.abs(curr.low - prev.low)
|
|
84
|
+
const openDirection = Math.abs(curr.open - prev.open)
|
|
85
85
|
|
|
86
86
|
if(classify)
|
|
87
87
|
{
|
|
@@ -92,10 +92,10 @@ const getCandlesStudies = (inputOhlcv, period = 20, len, classify = true, classi
|
|
|
92
92
|
|
|
93
93
|
gapInstance.update(gapSize)
|
|
94
94
|
bodySizeInstance.update(candleBodySize)
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
closeDirectionInstance.update(closeDirection)
|
|
96
|
+
highDirectionInstance.update(highDirection)
|
|
97
|
+
lowDirectionInstance.update(lowDirection)
|
|
98
|
+
openDirectionInstance.update(openDirection)
|
|
99
99
|
|
|
100
100
|
try
|
|
101
101
|
{
|
|
@@ -104,10 +104,10 @@ const getCandlesStudies = (inputOhlcv, period = 20, len, classify = true, classi
|
|
|
104
104
|
gapMean = gapInstance.getResult()
|
|
105
105
|
bodySizeMean = bodySizeInstance.getResult()
|
|
106
106
|
shadowSizeMean = shadowSizeInstance.getResult()
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
107
|
+
closeDirectionMean = closeDirectionInstance.getResult()
|
|
108
|
+
highDirectionMean = highDirectionInstance.getResult()
|
|
109
|
+
lowDirectionMean = lowDirectionInstance.getResult()
|
|
110
|
+
openDirectionMean = openDirectionInstance.getResult()
|
|
111
111
|
}
|
|
112
112
|
catch(err)
|
|
113
113
|
{
|
|
@@ -116,10 +116,10 @@ const getCandlesStudies = (inputOhlcv, period = 20, len, classify = true, classi
|
|
|
116
116
|
topSizeMean = null
|
|
117
117
|
bottomSizeMean = null
|
|
118
118
|
shadowSizeMean = null
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
119
|
+
closeDirectionMean = null
|
|
120
|
+
highDirectionMean = null
|
|
121
|
+
lowDirectionMean = null
|
|
122
|
+
openDirectionMean = null
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
//negatives and positives
|
|
@@ -131,22 +131,22 @@ const getCandlesStudies = (inputOhlcv, period = 20, len, classify = true, classi
|
|
|
131
131
|
? classifySize(gapSize, gapMean, 2, changeLevel)
|
|
132
132
|
: -Math.abs(classifySize(gapSize, gapMean, 2, changeLevel)) || 0;
|
|
133
133
|
|
|
134
|
-
|
|
135
|
-
? classifySize(
|
|
136
|
-
: -Math.abs(classifySize(
|
|
134
|
+
candle_close_direction[x] = (isUp)
|
|
135
|
+
? classifySize(closeDirection, closeDirectionMean, 2, changeLevel)
|
|
136
|
+
: -Math.abs(classifySize(closeDirection, closeDirectionMean, 2, changeLevel)) || 0;
|
|
137
137
|
|
|
138
|
-
|
|
139
|
-
? classifySize(
|
|
140
|
-
: -Math.abs(classifySize(
|
|
138
|
+
candle_high_direction[x] = (isUp)
|
|
139
|
+
? classifySize(highDirection, highDirectionMean, 2, changeLevel)
|
|
140
|
+
: -Math.abs(classifySize(highDirection, highDirectionMean, 2, changeLevel)) || 0;
|
|
141
141
|
|
|
142
142
|
|
|
143
|
-
|
|
144
|
-
? classifySize(
|
|
145
|
-
: -Math.abs(classifySize(
|
|
143
|
+
candle_low_direction[x] = (isUp)
|
|
144
|
+
? classifySize(lowDirection, lowDirectionMean, 2, changeLevel)
|
|
145
|
+
: -Math.abs(classifySize(lowDirection, lowDirectionMean, 2, changeLevel)) || 0;
|
|
146
146
|
|
|
147
|
-
|
|
148
|
-
? classifySize(
|
|
149
|
-
: -Math.abs(classifySize(
|
|
147
|
+
candle_open_direction[x] = (isUp)
|
|
148
|
+
? classifySize(openDirection, openDirectionMean, 2, changeLevel)
|
|
149
|
+
: -Math.abs(classifySize(openDirection, openDirectionMean, 2, changeLevel)) || 0;
|
|
150
150
|
|
|
151
151
|
|
|
152
152
|
//positives only
|
|
@@ -158,9 +158,9 @@ const getCandlesStudies = (inputOhlcv, period = 20, len, classify = true, classi
|
|
|
158
158
|
//negatives and positives
|
|
159
159
|
candle_body_size[x] = candleBodySize
|
|
160
160
|
candle_gap_size[x] = gapSize
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
161
|
+
candle_close_direction[x] = closeDirection
|
|
162
|
+
candle_high_direction[x] = highDirection
|
|
163
|
+
candle_low_direction[x] = lowDirection
|
|
164
164
|
|
|
165
165
|
//positives only
|
|
166
166
|
candle_top_size[x] = topSize
|
|
@@ -176,9 +176,9 @@ const getCandlesStudies = (inputOhlcv, period = 20, len, classify = true, classi
|
|
|
176
176
|
candle_top_size,
|
|
177
177
|
candle_bottom_size,
|
|
178
178
|
candle_shadow_size,
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
179
|
+
candle_close_direction,
|
|
180
|
+
candle_high_direction,
|
|
181
|
+
candle_low_direction,
|
|
182
|
+
candle_open_direction
|
|
183
183
|
}
|
|
184
184
|
}
|