first commit

This commit is contained in:
Francois Klieber committed 2021-06-06 20:25:14 +02:00
commit aa7869eb33
386 files changed
+69375

No files matched your search

+21
View File
@@ -0,0 +1,21 @@
// required indicators
// Simple Moving Average - O(1) implementation
var Indicator = function(windowLength) {
this.input = 'price';
this.windowLength = windowLength;
this.prices = [];
this.result = 0;
this.age = 0;
this.sum = 0;
}
Indicator.prototype.update = function(price) {
var tail = this.prices[this.age] || 0; // oldest price in window
this.prices[this.age] = price;
this.sum += price - tail;
this.result = this.sum / this.prices.length;
this.age = (this.age + 1) % this.windowLength
}
module.exports = Indicator;