forked from DeviaVir/zenbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ta_ultosc.js
52 lines (43 loc) · 1.41 KB
/
ta_ultosc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
var talib = require('talib')
module.exports = function ultosc(s, min_periods, timeperiod1, timeperiod2, timeperiod3) {
return new Promise(function(resolve, reject) {
// create object for talib. only close is used for now but rest might come in handy
if (!s.marketData) {
s.marketData = { open: [], close: [], high: [], low: [], volume: [] }
}
if (s.lookback.length > s.marketData.close.length) {
for (var i = (s.lookback.length - s.marketData.close.length) - 1; i >= 0; i--) {
s.marketData.high.push(s.lookback[i].high)
s.marketData.low.push(s.lookback[i].low)
s.marketData.close.push(s.lookback[i].close)
}
}
if (s.marketData.close.length < min_periods) {
resolve()
return
}
let tmpHigh = s.marketData.high.slice()
tmpHigh.push(s.period.high)
let tmpLow = s.marketData.low.slice()
tmpLow.push(s.period.low)
let tmpClose = s.marketData.close.slice()
tmpClose.push(s.period.close)
talib.execute({
name: 'ULTOSC',
startIdx: 0,
endIdx: tmpHigh.length -1,
high: tmpHigh,
low: tmpLow,
close: tmpClose,
optInTimePeriod1: timeperiod1,
optInTimePeriod2: timeperiod2,
optInTimePeriod3: timeperiod3,
}, function (err, result) {
if (err) {
reject(err, result)
return
}
resolve(result.result.outReal[(result.nbElement - 1)])
})
})
}