-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathFIBO.js
More file actions
133 lines (108 loc) · 3.23 KB
/
Copy pathFIBO.js
File metadata and controls
133 lines (108 loc) · 3.23 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
class MinMaxQueue {
constructor(len) {
this.max_queue = [];
this.min_queue = [];
this.length = len;
this.i=0;
}
enqueue(element) {
/* Deal with max queue */
while(this.max_queue.length!==0 && this.max_queue[0][1] < this.i - this.length + 1) {
this.max_queue.shift();
}
while(this.max_queue.length!==0 && this.max_queue[this.max_queue.length-1][0] < element) {
this.max_queue.pop();
}
this.max_queue.push([element, this.i]);
/* Deal with min queue */
/* */
while(this.min_queue.length!==0 && this.min_queue[0][1] < this.i - this.length + 1) {
this.min_queue.shift();
}
while(this.min_queue.length!==0 && this.min_queue[this.min_queue.length-1][0] >= element) {
this.min_queue.pop();
}
this.min_queue.push([element, this.i]);
this.i++;
}
get_max() {
return this.max_queue[0][0];
}
get_min() {
return this.min_queue[0][0];
}
}
// Naive, slower version
// class MinMaxQueue {
// constructor(len) {
// this.max_queue = [];
// this.min_queue = [];
// this.length = len;
// this.i=0;
// }
//
// enqueue(element) {
// this.max_queue.push(element);
// this.min_queue.push(element);
//
// if(this.max_queue.length>this.length) {
// this.max_queue.shift();
// }
//
// if(this.min_queue.length>this.length) {
// this.min_queue.shift();
// }
// }
//
// get_max() {
// return Math.max(...this.max_queue);
// }
//
// get_min() {
// return Math.min(...this.min_queue);
// }
// }
var Indicator = function(config) {
this.windowMin = Number.MAX_VALUE;
this.windowMax = Number.MIN_VALUE;
this.queue = new MinMaxQueue(config.histSize);
this.thresholds = [0, 0.236, 0.382, 0.5, 0.618, 1];
this.thres_vals = [];
this.line0 = 0;
this.line23_6 = 0;
this.line38_2 = 0;
this.line50_0 = 0;
this.line61_8 = 0;
this.line100 = 0;
/* Number of current candle */
this.numCandle = 0;
/* Size of the window we are gonna watch */
this.histSize = config.histSize;
/* How close is close to line, this.eps needs to be between 0 - 100*/
this.eps_config = config.eps/100.0;
this.eps = 0;
};
Indicator.prototype.update = function(candle) {
// enqueue
// max()
// min()
// config:window length
this.queue.enqueue(candle.close);
this.windowMin = this.queue.get_min();
this.windowMax = this.queue.get_max();
let diff = this.windowMax - this.windowMin;
this.eps = diff*this.eps_config;
this.thres_vals = [];
for(let ind in this.thresholds) {
this.thres_vals.push(this.thresholds[ind]*diff + this.windowMin);
}
//this.line0 = this.windowMin;
//this.line23_6 = this.line0 + 0.236 * diff;
//this.line38_2 = this.line0 + 0.382 * diff;
//this.line50_0 = this.line0 + 0.5 * diff;
//this.line61_8 = this.line0 + 0.618 * diff;
//this.line100 = this.windowMax;
}
Indicator.prototype.calculate = function(candle) {
}
module.exports = Indicator;