ohlcv-indicators 1.9.0 → 1.9.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/dist/ohlcv-indicators.min.js +1 -1
- package/index.js +64 -28
- package/package.json +2 -2
- package/src/oscillators/rsi.js +1 -1
- package/src/oscillators/volumeOscillator.js +47 -0
- package/src/utilities/parsing-utilities.js +0 -12
- package/src/utilities/setIndicatorsFromInputParams.js +45 -0
- package/dist/ohlcv-indicators.min.js.LICENSE.txt +0 -1
- package/knn-model.json +0 -1
- package/src/moving-averages/vwap.js +0 -40
- package/src/utilities/math-array.js +0 -64
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export const vwap = (main) => {
|
|
4
|
-
const { verticalOhlcv } = main;
|
|
5
|
-
|
|
6
|
-
const vwapValues = calculateVWAP(verticalOhlcv);
|
|
7
|
-
|
|
8
|
-
return {
|
|
9
|
-
[`vwap`]: vwapValues,
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const calculateVWAP = data => {
|
|
14
|
-
const { high, low, close, volume } = data;
|
|
15
|
-
const output = new Array(close.length).fill(null)
|
|
16
|
-
|
|
17
|
-
// Cumulative sums for VWAP calculation
|
|
18
|
-
let cumulativePriceVolume = 0;
|
|
19
|
-
let cumulativeVolume = 0;
|
|
20
|
-
|
|
21
|
-
for (let x = 0; x < close.length; x++) {
|
|
22
|
-
|
|
23
|
-
const typicalPrice = (high[x] + low[x] + close[x]) / 3;
|
|
24
|
-
|
|
25
|
-
// Calculate Price * Volume for this interval
|
|
26
|
-
const priceVolume = typicalPrice * volume[x];
|
|
27
|
-
|
|
28
|
-
// Update cumulative sums
|
|
29
|
-
cumulativePriceVolume += priceVolume;
|
|
30
|
-
cumulativeVolume += volume[x];
|
|
31
|
-
|
|
32
|
-
// Calculate VWAP for this interval
|
|
33
|
-
const vwap = cumulativePriceVolume / cumulativeVolume;
|
|
34
|
-
|
|
35
|
-
// Push the VWAP value into the array
|
|
36
|
-
output[x] = vwap
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return output
|
|
40
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
//change between current and prev
|
|
2
|
-
export const arrayChange = data => {
|
|
3
|
-
|
|
4
|
-
if(!Array.isArray(data))
|
|
5
|
-
{
|
|
6
|
-
throw Error('data param in arrayGt function must be array')
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const output = Array(data.length).fill(0)
|
|
10
|
-
|
|
11
|
-
for (let x = 1; x < output.length; x++) {
|
|
12
|
-
|
|
13
|
-
if(data[x] === null || data[x - 1] === null)
|
|
14
|
-
{
|
|
15
|
-
output[x] === null
|
|
16
|
-
}
|
|
17
|
-
else
|
|
18
|
-
{
|
|
19
|
-
const curr = data[x]
|
|
20
|
-
const prev = data[x - 1]
|
|
21
|
-
output[x] = ((curr - prev) / prev) * 100
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return output
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
//tells if array a is greater than array b
|
|
29
|
-
|
|
30
|
-
export const arrayGt = (a, b) => {
|
|
31
|
-
|
|
32
|
-
if(!Array.isArray(a) || !Array.isArray(b))
|
|
33
|
-
{
|
|
34
|
-
throw Error('a and b params in arrayGt function must be arrays')
|
|
35
|
-
}
|
|
36
|
-
if(a.length !== b.length)
|
|
37
|
-
{
|
|
38
|
-
throw Error('array a and b must be the same length in arrayGt function')
|
|
39
|
-
}
|
|
40
|
-
if(a.length < 2)
|
|
41
|
-
{
|
|
42
|
-
throw Error('arrays in arrayGt function must have at least 2 numeric items')
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const output = Array(a.length).fill(0.5)
|
|
46
|
-
|
|
47
|
-
for (let x = 1; x < output.length; x++) {
|
|
48
|
-
|
|
49
|
-
if(a[x] === null || b[x] === null)
|
|
50
|
-
{
|
|
51
|
-
output[x] = null
|
|
52
|
-
}
|
|
53
|
-
if(a[x] > b[x])
|
|
54
|
-
{
|
|
55
|
-
output[x] = 1
|
|
56
|
-
}
|
|
57
|
-
else if(a[x] < b[x])
|
|
58
|
-
{
|
|
59
|
-
output[x] = 0
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return output
|
|
64
|
-
}
|