ohlcv-indicators 1.0.4 → 1.0.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 +1 -1
- package/src/studies/volumeProfile.js +34 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ohlcv-indicators",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "A JavaScript library featuring optimized trading indicators for OHLCV arrays [{open, high, low, close, value}], utilizing BigNumber precision for enhanced accuracy.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const VolumeProfile = (BigNumber, ohlcv, numBins = 10) => {
|
|
1
|
+
export const VolumeProfile = (BigNumber, ohlcv, numBins = 10, position) => {
|
|
2
2
|
const { open, high, low, close, volume } = ohlcv;
|
|
3
3
|
|
|
4
4
|
// Determine the range of prices
|
|
@@ -26,7 +26,8 @@ export const VolumeProfile = (BigNumber, ohlcv, numBins = 10) => {
|
|
|
26
26
|
const inverseBinSize = BigNumber(1).dividedBy(binSize);
|
|
27
27
|
|
|
28
28
|
// Distribute volume into bins
|
|
29
|
-
close.
|
|
29
|
+
for (let i = 0; i < close.length; i++) {
|
|
30
|
+
const currentClose = close[i];
|
|
30
31
|
const currentOpen = open[i];
|
|
31
32
|
const currentHigh = high[i];
|
|
32
33
|
const currentLow = low[i];
|
|
@@ -41,24 +42,43 @@ export const VolumeProfile = (BigNumber, ohlcv, numBins = 10) => {
|
|
|
41
42
|
for (let j = lowIndex; j < highIndex; j++) {
|
|
42
43
|
bins[j].upVolume = bins[j].upVolume.plus(upVolume);
|
|
43
44
|
bins[j].downVolume = bins[j].downVolume.plus(downVolume);
|
|
44
|
-
bins[j].grossVolume = bins[j].upVolume.plus(
|
|
45
|
-
|
|
45
|
+
bins[j].grossVolume = bins[j].grossVolume.plus(upVolume.plus(downVolume));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
46
48
|
|
|
47
49
|
// Sum totals outside the loop
|
|
48
|
-
|
|
50
|
+
for (const { upVolume, downVolume, grossVolume } of bins) {
|
|
49
51
|
totals.upVolume = totals.upVolume.plus(upVolume);
|
|
50
52
|
totals.downVolume = totals.downVolume.plus(downVolume);
|
|
51
53
|
totals.grossVolume = totals.grossVolume.plus(grossVolume);
|
|
52
|
-
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
const nodes = findVolumeNodes(bins)
|
|
58
|
+
return {bins, nodes};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
const findVolumeNodes = bins => {
|
|
63
|
+
if (!bins || bins.length === 0) {
|
|
64
|
+
throw new Error('Bins array is empty or not provided');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
let highestVolumeNode = bins[0];
|
|
68
|
+
let lowestVolumeNode = bins[0];
|
|
53
69
|
|
|
54
|
-
// Calculate percentage volumes
|
|
55
70
|
bins.forEach(bin => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
71
|
+
if (bin.grossVolume.isGreaterThan(highestVolumeNode.grossVolume)) {
|
|
72
|
+
highestVolumeNode = bin;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (bin.grossVolume.isLessThan(lowestVolumeNode.grossVolume)) {
|
|
76
|
+
lowestVolumeNode = bin;
|
|
77
|
+
}
|
|
61
78
|
});
|
|
62
79
|
|
|
63
|
-
return
|
|
64
|
-
|
|
80
|
+
return {
|
|
81
|
+
highestVolumeNode,
|
|
82
|
+
lowestVolumeNode
|
|
83
|
+
}
|
|
84
|
+
}
|