Skip to content
This repository has been archived by the owner on Feb 16, 2020. It is now read-only.

Commit

Permalink
Create a new DEMA indicator
Browse files Browse the repository at this point in the history
Fix issue #1812
  • Loading branch information
rkingy committed Feb 2, 2018
1 parent f5ba234 commit fab67a5
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions strategies/indicators/doubleEMA.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Richard King, 2 Feb
// Built as a fix to the DEMA.js indicator that wasn't accurate.

// required indicators
var EMA = require('./EMA.js');

var Indicator = function(period) {
this.input = 'price'
this.result = false;
this.ema = new EMA(period);
this.doubleEMA = new EMA(period);
}

// add a price and calculate the EMAs and
// the diff for that price
Indicator.prototype.update = function(price) {
this.ema.update(price);
var EMA = this.ema.result;
this.doubleEMA.update(EMA);
this.calculateDoubleEMA();
}

// Formula https://www.investopedia.com/ask/answers/121814/what-double-exponential-moving-average-dema-formula-and-how-it-calculated.asp
Indicator.prototype.calculateDoubleEMA = function() {

var EMA = this.ema.result;
var doubleEMA = this.doubleEMA.result;

this.result = (2 * EMA) - doubleEMA;

}

module.exports = Indicator;

0 comments on commit fab67a5

Please sign in to comment.