Skip to content

Commit

Permalink
ppo output to this.result for api exposure (askmike#1443)
Browse files Browse the repository at this point in the history
* fix ppo result for api exposure

* fix tests

* fix tests
  • Loading branch information
generalectric authored and askmike committed Dec 11, 2017
1 parent 6a35513 commit ffd06e2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 30 deletions.
24 changes: 12 additions & 12 deletions strategies/PPO.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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
Expand Down
26 changes: 16 additions & 10 deletions strategies/indicators/PPO.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
8 changes: 4 additions & 4 deletions test/indicators/macd.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ 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]);
});
});

it('should correctly calculate PPO signals with 12/26/9', 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]);
});
});

Expand All @@ -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]);
});
});
});
Expand All @@ -97,4 +97,4 @@ xdescribe('indicators/DEMA', function() {
});


});
});
8 changes: 4 additions & 4 deletions test/indicators/ppo.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ 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]);
});
});

it('should correctly calculate PPO signals with 12/26/9', 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]);
});
});

Expand All @@ -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]);
});
});
});
});

0 comments on commit ffd06e2

Please sign in to comment.