-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUO.js
45 lines (36 loc) · 1.42 KB
/
UO.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
// required indicators
var SMA = require('./SMA.js');
var Indicator = function(settings) {
this.input = 'candle';
this.lastClose = 0;
this.uo = 0;
this.firstWeight = settings.first.weight;
this.secondWeight = settings.second.weight;
this.thirdWeight = settings.third.weight;
this.firstLow = new SMA(settings.first.period);
this.firstHigh = new SMA(settings.first.period);
this.secondLow = new SMA(settings.second.period);
this.secondHigh = new SMA(settings.second.period);
this.thirdLow = new SMA(settings.third.period);
this.thirdHigh = new SMA(settings.third.period);
}
Indicator.prototype.update = function(candle) {
var close = candle.close;
var prevClose = this.lastClose;
var low = candle.low;
var high = candle.high;
var bp = close - Math.min(low, prevClose);
var tr = Math.max(high, prevClose) - Math.min(low, prevClose);
this.firstLow.update(tr);
this.secondLow.update(tr);
this.thirdLow.update(tr);
this.firstHigh.update(bp);
this.secondHigh.update(bp);
this.thirdHigh.update(bp);
var first = this.firstHigh.result / this.firstLow.result;
var second = this.secondHigh.result / this.secondLow.result;
var third = this.thirdHigh.result / this.thirdLow.result;
this.uo = 100 * (this.firstWeight * first + this.secondWeight * second + this.thirdWeight * third) / (this.firstWeight + this.secondWeight + this.thirdWeight);
this.lastClose = close;
}
module.exports = Indicator;