This repository has been archived on 2025-10-29. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
gekko/strategies/indicators/SMMA.js
T
2021-06-06 20:25:14 +02:00

29 lines
624 B
JavaScript

// required indicators
var SMA = require('./SMA');
var Indicator = function (weight) {
this.input = 'price';
this.sma = new SMA(weight);
this.weight = weight;
this.prices = [];
this.result = 0;
this.age = 0;
}
Indicator.prototype.update = function (price) {
this.prices[this.age] = price;
if(this.prices.length < this.weight) {
this.sma.update(price);
} else if(this.prices.length === this.weight) {
this.sma.update(price);
this.result = this.sma.result;
} else {
this.result = (this.result * (this.weight - 1) + price) / this.weight;
}
this.age++;
}
module.exports = Indicator;