-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathTABBSLINREG.js
More file actions
110 lines (87 loc) · 2.68 KB
/
Copy pathTABBSLINREG.js
File metadata and controls
110 lines (87 loc) · 2.68 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
var BB = require('technicalindicators').BollingerBands;
var tools = require('../tradingFunctions');
var Indicator = function (settings) {
console.log(settings);
this.input = 'candle';
this.interval = settings.count;
this.standarddeviation = settings.standarddeviation;
this.bb_linreg_upperdeviation = settings.bblinregupperdeviation;
this.bb_linreg_lowerdeviation = settings.bblinreglowerdeviation;
this.bbout = [];
this.result = [];
this.historyopen =[];
this.historyhigh =[];
this.historyclose =[];
this.historylow =[];
this.bbupperhistory =[];
this.bbmiddlehistory =[];
this.bblowerhistory =[];
this.bbpbhistory =[];
this.age = 0;
this.vwphistory = [];
}
Indicator.prototype.update = function(candle) {
this.result.upper = 0;
this.result.middle = 0;
this.result.lower = 0;
this.result.pb = 0;
this.result.pb_linreg_pearsonsR = 0;
this.result.pb_linreg_pearsonsR = 0;
this.result.pb_linreg_upperdeviation= 0;
this.result.pb_linreg_lowerdeviation= 0;
this.result.pb_linreg_Yintercept= 0;
// 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){
this.historyopen.shift();
this.historyhigh.shift();
this.historyclose.shift();
this.historylow.shift();
this.calculate(candle);
//setup bb and get linreg for values
//console.log(this.tfbb.indicators.tabbs.result.pb);
let bbupper = this.bbout.upper;
let bbmiddle = this.bbout.middle;
let bblower = this.bbout.lower;
let bbpb = this.bbout.pb;
let bbpb_linreg = 0;
this.bbupperhistory.push(bbupper);
this.bbmiddlehistory.push(bbmiddle);
this.bblowerhistory.push(bblower);
this.bbpbhistory.push(bbpb);
if(this.bbupperhistory.length > this.interval){
this.bbupperhistory.shift();
this.bbmiddlehistory.shift();
this.bblowerhistory.shift();
this.bbpbhistory.shift();
bbpb_linreg = tools.linReg(this.bbpbhistory, this.bb_linreg_upperdeviation, this.bb_linreg_lowerdeviation);
this.result = {
middle: bbmiddle,
upper: bbupper,
lower: bblower,
pb: bbpb,
pb_linreg_pearsonsR: bbpb_linreg.pearsonsR,
pb_linreg_upperdeviation: bbpb_linreg.upperdeviation,
pb_linreg_lowerdeviation: bbpb_linreg.lowerdeviation,
pb_linreg_Yintercept: bbpb_linreg.Yintercept,
}
}
}
return;
}
/*
* Handle calculations
*/
Indicator.prototype.calculate = function(candle) {
var input = {
period: this.interval,
values: this.historyclose,
stdDev: this.standarddeviation
}
var bb = new BB(input);
this.bbout = bb.getResult()[0];
}
module.exports = Indicator;