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.
@@ -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
- }