ohlcv-indicators 1.0.9 → 1.1.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/index.js +2 -1
- package/package.json +1 -1
- package/src/moving-averages/ichimokuCloud.js +4 -3
- package/test/fetchLiveData.js +3 -0
- package/test/test.js +3 -32
package/index.js
CHANGED
|
@@ -58,7 +58,8 @@ export default class OHLCV_INDICATORS {
|
|
|
58
58
|
for(let k in this.ohlcv)
|
|
59
59
|
{
|
|
60
60
|
const arr = this.ohlcv[k]
|
|
61
|
-
|
|
61
|
+
let value = arr[arr.length - 1]
|
|
62
|
+
output[k] = (BigNumber.isBigNumber(value)) ? value.toNumber() : value
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
return output
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ohlcv-indicators",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.2",
|
|
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",
|
|
@@ -33,7 +33,8 @@ export const getIchimokuCloud = (BigNumber, data, tenkan = 9, kijun = 26, senkou
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
const calculateAverage = (BigNumber, high, low, period) => {
|
|
36
|
-
|
|
36
|
+
|
|
37
|
+
return high.slice(0, high.length - period + 1).map((_, i) => {
|
|
37
38
|
const highSlice = high.slice(i, i + period)
|
|
38
39
|
const lowSlice = low.slice(i, i + period)
|
|
39
40
|
return BigNumber.maximum(...highSlice).plus(BigNumber.minimum(...lowSlice)).dividedBy(2)
|
|
@@ -55,9 +56,9 @@ const calculateSenkouSpanB = (BigNumber, high, low, period, slice) => {
|
|
|
55
56
|
return BigNumber.maximum(...highSlice).plus(BigNumber.minimum(...lowSlice)).dividedBy(2)
|
|
56
57
|
})
|
|
57
58
|
|
|
58
|
-
return spanB.slice(0, (spanB.length -slice)+
|
|
59
|
+
return spanB.slice(0, (spanB.length -slice)+2)
|
|
59
60
|
}
|
|
60
61
|
|
|
61
62
|
|
|
62
|
-
const calculateChikouSpan = (close, kijunSenPeriod) => close.slice(0, close.length - kijunSenPeriod)
|
|
63
|
+
const calculateChikouSpan = (close, kijunSenPeriod) => close.slice(0, close.length - kijunSenPeriod + 1)
|
|
63
64
|
|
package/test/fetchLiveData.js
CHANGED
|
@@ -35,6 +35,8 @@ export const getLatestOHLCV = async (symbol) => {
|
|
|
35
35
|
const {chart, lastSalePrice, volume} = data.data
|
|
36
36
|
const allValues = chart.map(o => convertCurrencyToFloat(o.z.value))
|
|
37
37
|
|
|
38
|
+
console.log(new Date(chart[chart.length -1].x).toDateString().slice(0, 10))
|
|
39
|
+
|
|
38
40
|
return [{
|
|
39
41
|
open: allValues[0],
|
|
40
42
|
high: Math.max(...allValues),
|
|
@@ -51,5 +53,6 @@ const getDateRange = limit => {
|
|
|
51
53
|
fromDate.setDate(fromDate.getDate() - limit)
|
|
52
54
|
const fromDateFormatted = fromDate.toISOString().slice(0, 10) // Get the date limit number of days ago in yyyy-mm-dd format
|
|
53
55
|
|
|
56
|
+
|
|
54
57
|
return { fromDate: fromDateFormatted, toDate }
|
|
55
58
|
}
|
package/test/test.js
CHANGED
|
@@ -2,11 +2,10 @@ import OHLCV_INDICATORS from '../index.js'
|
|
|
2
2
|
import { getOHLCV } from './fetchLiveData.js'
|
|
3
3
|
|
|
4
4
|
const indicators = new OHLCV_INDICATORS();
|
|
5
|
-
const {BigNumber, VolumeProfile} = indicators
|
|
6
5
|
|
|
7
6
|
const TEST = async () => {
|
|
8
7
|
|
|
9
|
-
const ohlcv = await getOHLCV('
|
|
8
|
+
const ohlcv = await getOHLCV('ADMA', 200)
|
|
10
9
|
|
|
11
10
|
indicators
|
|
12
11
|
.init(ohlcv)
|
|
@@ -16,41 +15,13 @@ const TEST = async () => {
|
|
|
16
15
|
//.SMA(100, 'sma_200')
|
|
17
16
|
//.MACD(12, 26, 9)
|
|
18
17
|
//.BollingerBands(20, 2)
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
.IchimokuCloud(9, 26, 52)
|
|
19
|
+
//.RSI(14)
|
|
21
20
|
//.MFI(14)
|
|
22
21
|
//.RelativeVolume(10)
|
|
23
22
|
//.RelativeVolume(20)
|
|
24
23
|
//.crossPairs([{fast: 'ema_9', slow: 'ema_21'}, {fast: 'close', slow: 'sma_200'}, {fast: 'rsi_14', slow: 30}])
|
|
25
24
|
|
|
26
|
-
const dataSet = indicators.getData()
|
|
27
|
-
const vp = VolumeProfile(BigNumber, dataSet, 5)
|
|
28
|
-
|
|
29
|
-
//console.log(vp)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
for(let k in dataSet)
|
|
33
|
-
{
|
|
34
|
-
let firstValidIndex = 0
|
|
35
|
-
const row = dataSet[k]
|
|
36
|
-
const firstValue = (BigNumber.isBigNumber(row[0])) ? row[0].toNumber() : row[0]
|
|
37
|
-
const lastValue = (BigNumber.isBigNumber(row[row.length -1])) ? row[row.length -1].toNumber() : row[row.length -1]
|
|
38
|
-
|
|
39
|
-
//get the first numeric index
|
|
40
|
-
row.forEach(v => {
|
|
41
|
-
if(isNaN(v))
|
|
42
|
-
{
|
|
43
|
-
firstValidIndex++
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
//console.log(`${k}: ${JSON.stringify({firstValue, firstValidIndex, lastValue})}`)
|
|
48
|
-
//console.log('---\n')
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
console.log('<<<<<<<<<< HEADERS >>>>>>>>>>')
|
|
52
|
-
console.log(indicators.getHeaders())
|
|
53
|
-
|
|
54
25
|
console.log(indicators.getLastValues())
|
|
55
26
|
}
|
|
56
27
|
|