ohlcv-indicators 1.0.1 → 1.0.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 +15 -4
- package/package.json +1 -1
- package/src/moving-averages/bollingerBands.js +22 -6
- package/test/fetchLiveData.js +1 -1
- package/test/test.js +13 -8
package/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { IchimokuCloud } from './src/moving-averages/ichimokuCloud.js'
|
|
|
7
7
|
import { RSI} from './src/oscillators/rsi.js'
|
|
8
8
|
import { MFI} from './src/oscillators/mfi.js'
|
|
9
9
|
import { RelativeVolume} from './src/moving-averages/relativeVolume.js'
|
|
10
|
-
import {
|
|
10
|
+
import {findCrosses} from './src/utilities.js'
|
|
11
11
|
|
|
12
12
|
export default class OHLCV_INDICATORS {
|
|
13
13
|
constructor() {
|
|
@@ -83,6 +83,7 @@ export default class OHLCV_INDICATORS {
|
|
|
83
83
|
|
|
84
84
|
//crossing single column pairs
|
|
85
85
|
const ohlcv = this.getData()
|
|
86
|
+
let slowNumArr = []
|
|
86
87
|
|
|
87
88
|
//each parameter [{fast, slow}, {fast, slow}]
|
|
88
89
|
|
|
@@ -97,8 +98,8 @@ export default class OHLCV_INDICATORS {
|
|
|
97
98
|
|
|
98
99
|
//if the column does not exist, will try to create a new one
|
|
99
100
|
//this code can only add single column output indicators such as SMA and EMA
|
|
100
|
-
[fast, slow].forEach(v => {
|
|
101
|
-
if (!ohlcv.hasOwnProperty(v)) {
|
|
101
|
+
[fast, slow].forEach((v, i) => {
|
|
102
|
+
if (!ohlcv.hasOwnProperty(v) && typeof v === 'string') {
|
|
102
103
|
const arr = v.split('_')
|
|
103
104
|
if (arr.length > 0) {
|
|
104
105
|
const funcName = arr[0].toUpperCase()
|
|
@@ -109,13 +110,23 @@ export default class OHLCV_INDICATORS {
|
|
|
109
110
|
}
|
|
110
111
|
}
|
|
111
112
|
}
|
|
113
|
+
else if(typeof v === 'number' && i === 1)
|
|
114
|
+
{
|
|
115
|
+
slowNumArr = ohlcv.close.map(o => 30)
|
|
116
|
+
}
|
|
112
117
|
})
|
|
113
118
|
|
|
114
119
|
//finds the cross and adds is to the columns
|
|
115
120
|
if (ohlcv.hasOwnProperty(fast) && ohlcv.hasOwnProperty(slow)) {
|
|
116
121
|
const cross = findCrosses(this.BigNumber, ohlcv[fast], ohlcv[slow])
|
|
117
122
|
this.addColumn(`${fast}_x_${slow}`, cross)
|
|
118
|
-
}
|
|
123
|
+
}
|
|
124
|
+
else if(ohlcv.hasOwnProperty(fast) && slowNumArr.length > 0)
|
|
125
|
+
{
|
|
126
|
+
const cross = findCrosses(this.BigNumber, ohlcv[fast], slowNumArr)
|
|
127
|
+
this.addColumn(`${fast}_x_${slow}`, cross)
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
119
130
|
console.error(`Missing ohlcv properties for ${fast} or ${slow}`)
|
|
120
131
|
}
|
|
121
132
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ohlcv-indicators",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.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",
|
|
@@ -7,9 +7,12 @@ export const BollingerBands = (main, size, times) => {
|
|
|
7
7
|
const data = ohlcv['close'];
|
|
8
8
|
const bb = getBollingerBands(main.BigNumber, data, size, times)
|
|
9
9
|
const {upper, mid, lower} = bb
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
for(let k in bb)
|
|
13
|
+
{
|
|
14
|
+
main.addColumn(`bollinger_bands_${k}`, bb[k])
|
|
15
|
+
}
|
|
13
16
|
}
|
|
14
17
|
|
|
15
18
|
|
|
@@ -28,8 +31,11 @@ export const getBollingerBands = (BigNumber, data, size = 20, times = 2) => {
|
|
|
28
31
|
let upper = avg.map((o, i) => o.plus(timesSd[i]))
|
|
29
32
|
let mid = avg
|
|
30
33
|
let lower = avg.map((o, i) => o.minus(timesSd[i]))
|
|
34
|
+
let range = bollingerBandsRange(data, {upper, lower})
|
|
35
|
+
|
|
36
|
+
console.log({range})
|
|
31
37
|
|
|
32
|
-
return { upper, mid, lower }
|
|
38
|
+
return { upper, mid, lower, range }
|
|
33
39
|
};
|
|
34
40
|
|
|
35
41
|
const deviation = (BigNumber, data, size) => {
|
|
@@ -49,5 +55,15 @@ export const getBollingerBands = (BigNumber, data, size = 20, times = 2) => {
|
|
|
49
55
|
}
|
|
50
56
|
|
|
51
57
|
return ret
|
|
52
|
-
}
|
|
53
|
-
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
const bollingerBandsRange = (data, bollingerBands) => {
|
|
62
|
+
let {upper, lower} = bollingerBands;
|
|
63
|
+
|
|
64
|
+
const range = upper.map((v, i) => v.minus(lower[i]))
|
|
65
|
+
|
|
66
|
+
const output = data.map((v, i) => (v.minus(lower[i]).dividedBy(range[i])).times(100))
|
|
67
|
+
|
|
68
|
+
return output
|
|
69
|
+
}
|
package/test/fetchLiveData.js
CHANGED
|
@@ -61,7 +61,7 @@ export const fetchHistoricalOHLCV = async ({symbol, days}) => {
|
|
|
61
61
|
|
|
62
62
|
//this function removes the lates "today result from output"
|
|
63
63
|
|
|
64
|
-
const response = await fetch(`https://charting.nasdaq.com/data/charting/intraday?symbol=${symbol}&mostRecent=${days}&includeLatestIntradayData=
|
|
64
|
+
const response = await fetch(`https://charting.nasdaq.com/data/charting/intraday?symbol=${symbol}&mostRecent=${days}&includeLatestIntradayData=0&`, {
|
|
65
65
|
referrer: "https://charting.nasdaq.com/dynamic/chart.html"
|
|
66
66
|
})
|
|
67
67
|
|
package/test/test.js
CHANGED
|
@@ -10,6 +10,11 @@ const TEST = async () => {
|
|
|
10
10
|
|
|
11
11
|
//console.log(await getLatestOHLCV('NVDA'))
|
|
12
12
|
|
|
13
|
+
|
|
14
|
+
//const historical = await fetchHistoricalOHLCV({symbol: 'NVDA', days: 30})
|
|
15
|
+
|
|
16
|
+
//console.log(historical[0])
|
|
17
|
+
|
|
13
18
|
//const historical = convertToOHLCV(await fetchHistoricalOHLCV({symbol: 'NVDA', days: 15}), 5)
|
|
14
19
|
//console.log(historical.length)
|
|
15
20
|
//console.log(historical[0])
|
|
@@ -21,17 +26,17 @@ const TEST = async () => {
|
|
|
21
26
|
|
|
22
27
|
indicators
|
|
23
28
|
.init(ohlcv)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
//.EMA(21)
|
|
30
|
+
//.EMA(9, 'ema21')
|
|
31
|
+
//.SMA(200)
|
|
32
|
+
//.SMA(100, 'sma_200')
|
|
33
|
+
//.MACD(12, 26, 9)
|
|
29
34
|
.BollingerBands(20, 2)
|
|
30
|
-
|
|
35
|
+
//.IchimokuCloud(9, 26, 52)
|
|
31
36
|
.RSI(14, 14)
|
|
32
37
|
.MFI(14)
|
|
33
|
-
|
|
34
|
-
.crossPairs([{fast: 'ema_9', slow: 'ema_21'}, {fast: 'close', slow: 'sma_200'}])
|
|
38
|
+
//.RelativeVolume(10)
|
|
39
|
+
.crossPairs([{fast: 'ema_9', slow: 'ema_21'}, {fast: 'close', slow: 'sma_200'}, {fast: 'rsi_14_14', slow: 30}])
|
|
35
40
|
|
|
36
41
|
const dataSet = indicators.getData()
|
|
37
42
|
|