-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathTABBS.js
More file actions
55 lines (45 loc) · 1.19 KB
/
Copy pathTABBS.js
File metadata and controls
55 lines (45 loc) · 1.19 KB
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
52
53
54
55
var BB = require('technicalindicators').BollingerBands;
var Indicator = function (settings) {
this.input = 'candle';
this.interval = settings.period;
this.standarddeviation = settings.standarddeviation;
this.result = [];
this.age = 0;
this.historyopen =[];
this.historyhigh =[];
this.historyclose =[];
this.historylow =[];
}
Indicator.prototype.update = function(candle) {
// We need sufficient history to get the right result.
this.historyopen.push(candle.open);
this.historyhigh.push(candle.high);
this.historyclose.push(candle.close);
this.historylow.push(candle.low);
if(this.historyopen.length > this.interval){
// remove oldest RSI value
this.historyopen.shift();
this.historyhigh.shift();
this.historyclose.shift();
this.historylow.shift();
}
if(this.age>30){
this.calculate(candle);
}
this.age++;
return;
}
/*
* Handle calculations
*/
Indicator.prototype.calculate = function(candle) {
var input = {
period: this.interval,
values: this.historyclose,
stdDev: this.standarddeviation
}
var bb = new BB(input);
//console.log("bullish = "+ bullish(input));
this.result = bb.getResult()[0];
}
module.exports = Indicator;