ohlcv-indicators 1.1.0 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ohlcv-indicators",
3
- "version": "1.1.0",
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
- return high.slice(period).map((_, i) => {
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)+1)
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
 
@@ -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,60 +2,27 @@ 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('AAPL', 230)
8
+ const ohlcv = await getOHLCV('ADMA', 200)
10
9
 
11
10
  indicators
12
11
  .init(ohlcv)
13
- .EMA(21)
14
- .EMA(9, 'ema21')
15
- .SMA(200)
16
- .SMA(100, 'sma_200')
17
- .MACD(12, 26, 9)
18
- .BollingerBands(20, 2)
12
+ //.EMA(21)
13
+ //.EMA(9, 'ema21')
14
+ //.SMA(200)
15
+ //.SMA(100, 'sma_200')
16
+ //.MACD(12, 26, 9)
17
+ //.BollingerBands(20, 2)
19
18
  .IchimokuCloud(9, 26, 52)
20
- .RSI(14)
21
- .MFI(14)
22
- .RelativeVolume(10)
23
- .RelativeVolume(20)
24
- .crossPairs([{fast: 'ema_9', slow: 'ema_21'}, {fast: 'close', slow: 'sma_200'}, {fast: 'rsi_14', slow: 30}])
19
+ //.RSI(14)
20
+ //.MFI(14)
21
+ //.RelativeVolume(10)
22
+ //.RelativeVolume(20)
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
- console.log()
32
- const lastValue = Object.entries(indicators.getLastValues()).map(o => ([o[0], o[1], typeof o[1]]))
33
-
34
- console.log(lastValue)
35
-
36
- for(let k in dataSet)
37
- {
38
- let firstValidIndex = 0
39
- const row = dataSet[k]
40
- const firstValue = (BigNumber.isBigNumber(row[0])) ? row[0].toNumber() : row[0]
41
- const lastValue = (BigNumber.isBigNumber(row[row.length -1])) ? row[row.length -1].toNumber() : row[row.length -1]
42
-
43
- //get the first numeric index
44
- row.forEach(v => {
45
- if(isNaN(v))
46
- {
47
- firstValidIndex++
48
- }
49
- })
50
-
51
- //console.log(`${k}: ${JSON.stringify({firstValue, firstValidIndex, lastValue})}`)
52
- //console.log('---\n')
53
- }
54
-
55
- //console.log('<<<<<<<<<< HEADERS >>>>>>>>>>')
56
- //console.log(indicators.getHeaders())
57
-
58
- //console.log(indicators.getLastValues())
25
+ console.log(indicators.getLastValues())
59
26
  }
60
27
 
61
28
  TEST()