From ffd06e237fecdd13706bd91c89917c07ac9e83dd Mon Sep 17 00:00:00 2001 From: generalectric Date: Sun, 10 Dec 2017 22:05:56 -0600 Subject: [PATCH] ppo output to this.result for api exposure (#1443) * fix ppo result for api exposure * fix tests * fix tests --- strategies/PPO.js | 24 ++++++++++++------------ strategies/indicators/PPO.js | 26 ++++++++++++++++---------- test/indicators/macd.js | 8 ++++---- test/indicators/ppo.js | 8 ++++---- 4 files changed, 36 insertions(+), 30 deletions(-) diff --git a/strategies/PPO.js b/strategies/PPO.js index 6f39b7768..8c0f21488 100644 --- a/strategies/PPO.js +++ b/strategies/PPO.js @@ -40,12 +40,12 @@ method.update = function(candle) { method.log = function() { var digits = 8; var ppo = this.indicators.ppo; - var short = ppo.short.result; - var long = ppo.long.result; - var macd = ppo.macd; - var result = ppo.ppo; - var macdSignal = ppo.MACDsignal.result; - var ppoSignal = ppo.PPOsignal.result; + var long = ppo.result.longEMA; + var short = ppo.result.shortEMA; + var macd = ppo.result.macd; + var result = ppo.result.ppo; + var macdSignal = ppo.result.MACDsignal; + var ppoSignal = ppo.result.PPOsignal; log.debug('calculated MACD properties for candle:'); log.debug('\t', 'short:', short.toFixed(digits)); @@ -62,12 +62,12 @@ method.check = function(candle) { var price = candle.close; var ppo = this.indicators.ppo; - var long = ppo.long.result; - var short = ppo.short.result; - var macd = ppo.macd; - var result = ppo.ppo; - var macdSignal = ppo.MACDsignal.result; - var ppoSignal = ppo.PPOsignal.result; + var long = ppo.result.longEMA; + var short = ppo.result.shortEMA; + var macd = ppo.result.macd; + var result = ppo.result.ppo; + var macdSignal = ppo.result.MACDsignal; + var ppoSignal = ppo.result.PPOsignal; // TODO: is this part of the indicator or not? // if it is it should move there diff --git a/strategies/indicators/PPO.js b/strategies/indicators/PPO.js index eea3d827a..b49e592c7 100644 --- a/strategies/indicators/PPO.js +++ b/strategies/indicators/PPO.js @@ -2,9 +2,10 @@ var EMA = require('./EMA.js'); var Indicator = function(config) { + this.result = {}; this.input = 'price'; - this.macd = false; - this.ppo = false; + this.macd = 0; + this.ppo = 0; this.short = new EMA(config.short); this.long = new EMA(config.long); this.MACDsignal = new EMA(config.signal); @@ -15,17 +16,22 @@ Indicator.prototype.update = function(price) { this.short.update(price); this.long.update(price); this.calculatePPO(); - this.MACDsignal.update(this.macd); - this.MACDhist = this.macd - this.MACDsignal.result; - this.PPOsignal.update(this.ppo); - this.PPOhist = this.ppo - this.PPOsignal.result; + this.MACDsignal.update(this.result.macd); + this.MACDhist = this.result.macd - this.MACDsignal.result; + this.PPOsignal.update(this.result.ppo); + this.PPOhist = this.result.ppo - this.PPOsignal.result; + + this.result.MACDsignal = this.MACDsignal.result; + this.result.MACDhist = this.MACDhist; + this.result.PPOsignal = this.PPOsignal.result; + this.result.PPOhist = this.PPOhist; } Indicator.prototype.calculatePPO = function() { - var shortEMA = this.short.result; - var longEMA = this.long.result; - this.macd = shortEMA - longEMA; - this.ppo = 100 * (this.macd / longEMA); + this.result.shortEMA = this.short.result; + this.result.longEMA = this.long.result; + this.result.macd = this.result.shortEMA - this.result.longEMA; + this.result.ppo = 100 * (this.result.macd / this.result.longEMA); } module.exports = Indicator; diff --git a/test/indicators/macd.js b/test/indicators/macd.js index f19529ea1..7f5d97bc8 100644 --- a/test/indicators/macd.js +++ b/test/indicators/macd.js @@ -66,7 +66,7 @@ describe('indicators/PPO', function() { var ppo = new PPO({short: 12, long: 26, signal: 9}); _.each(prices, function(p, i) { ppo.update(p); - expect(ppo.ppo).to.equal(verified_ppo12v26v9[i]); + expect(ppo.result.ppo).to.equal(verified_ppo12v26v9[i]); }); }); @@ -74,7 +74,7 @@ describe('indicators/PPO', function() { var ppo = new PPO({short: 12, long: 26, signal: 9}); _.each(prices, function(p, i) { ppo.update(p); - expect(ppo.PPOsignal.result).to.equal(verified_ppo12v26v9signal[i]); + expect(ppo.result.PPOsignal).to.equal(verified_ppo12v26v9signal[i]); }); }); @@ -83,7 +83,7 @@ describe('indicators/PPO', function() { var ppo = new PPO({short: 12, long: 26, signal: 9}); _.each(prices, function(p, i) { ppo.update(p); - expect(ppo.PPOhist).to.equal(verified_ppo12v26v9hist[i]); + expect(ppo.result.PPOhist).to.equal(verified_ppo12v26v9hist[i]); }); }); }); @@ -97,4 +97,4 @@ xdescribe('indicators/DEMA', function() { }); -}); \ No newline at end of file +}); diff --git a/test/indicators/ppo.js b/test/indicators/ppo.js index 7518f33a4..0f2a7e684 100644 --- a/test/indicators/ppo.js +++ b/test/indicators/ppo.js @@ -32,7 +32,7 @@ describe('indicators/PPO', function() { var ppo = new PPO({short: 12, long: 26, signal: 9}); _.each(prices, function(p, i) { ppo.update(p); - expect(ppo.ppo).to.equal(verified_ppo12v26v9[i]); + expect(ppo.result.ppo).to.equal(verified_ppo12v26v9[i]); }); }); @@ -40,7 +40,7 @@ describe('indicators/PPO', function() { var ppo = new PPO({short: 12, long: 26, signal: 9}); _.each(prices, function(p, i) { ppo.update(p); - expect(ppo.PPOsignal.result).to.equal(verified_ppo12v26v9signal[i]); + expect(ppo.result.PPOsignal).to.equal(verified_ppo12v26v9signal[i]); }); }); @@ -49,7 +49,7 @@ describe('indicators/PPO', function() { var ppo = new PPO({short: 12, long: 26, signal: 9}); _.each(prices, function(p, i) { ppo.update(p); - expect(ppo.PPOhist).to.equal(verified_ppo12v26v9hist[i]); + expect(ppo.result.PPOhist).to.equal(verified_ppo12v26v9hist[i]); }); }); -}); \ No newline at end of file +});