This repository has been archived by the owner on Feb 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue #1812
- Loading branch information
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |