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
2021-06-06 20:25:14 +02:00

28 lines
653 B
JavaScript

// required indicators
var EMA = require('./EMA.js');
var Indicator = function(config) {
this.input = 'price';
this.diff = false;
this.short = new EMA(config.short);
this.long = new EMA(config.long);
this.signal = new EMA(config.signal);
}
Indicator.prototype.update = function(price) {
this.short.update(price);
this.long.update(price);
this.calculateEMAdiff();
this.signal.update(this.diff);
this.result = this.diff - this.signal.result;
}
Indicator.prototype.calculateEMAdiff = function() {
var shortEMA = this.short.result;
var longEMA = this.long.result;
this.diff = shortEMA - longEMA;
}
module.exports = Indicator;