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

Fix varPPO strategy and TSI indicator #1799

Merged
merged 6 commits into from
Jan 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion exchanges/bitfinex.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var retryForever = {
};

// Probably we need to update these string
var recoverableErrors = new RegExp(/(SOCKETTIMEDOUT|TIMEDOUT|CONNRESET|CONNREFUSED|NOTFOUND|StatusCodeError: 429|StatusCodeError: 5)/)
var recoverableErrors = new RegExp(/(SOCKETTIMEDOUT|TIMEDOUT|CONNRESET|CONNREFUSED|NOTFOUND|429|443|5\d\d)/g);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be part of this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m sorry, this will update the Bitfinex string. Maybe I’ll submit another PR.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it needs to be updated, did you add this specifically because it caught errors better?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this string caught erros better.It can be committed.


Trader.prototype.processError = function(funcName, error) {
if (!error) return undefined;
Expand Down
2 changes: 1 addition & 1 deletion strategies/TSI.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ method.log = function(candle) {
var digits = 8;
var tsi = this.indicators.tsi;

log.debug('calculated Ultimate Oscillator properties for candle:');
log.debug('calculated TSI properties for candle:');
log.debug('\t', 'tsi:', tsi.tsi.toFixed(digits));
log.debug('\t', 'price:', candle.close.toFixed(digits));
}
Expand Down
10 changes: 9 additions & 1 deletion strategies/indicators/TSI.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var EMA = require('./EMA.js');

var Indicator = function(settings) {
this.input = 'candle';
this.lastClose = 0;
this.lastClose = null;
this.tsi = 0;
this.inner = new EMA(settings.long);
this.outer = new EMA(settings.short);
Expand All @@ -14,6 +14,14 @@ var Indicator = function(settings) {
Indicator.prototype.update = function(candle) {
var close = candle.close;
var prevClose = this.lastClose;

if (prevClose === null) {
// Set initial price to prevent invalid change calculation
this.lastClose = close;
// Do not calculate TSI on first close
return;
}

var momentum = close - prevClose;

this.inner.update(momentum);
Expand Down
12 changes: 5 additions & 7 deletions strategies/varPPO.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ method.update = function(candle) {
// calculated parameters.
method.log = function(candle) {
var digits = 8;
var ppo = this.indicators.ppo;
var ppo = this.indicators.ppo.result;
var result = ppo.ppo;
var signal = ppo.PPOsignal.result;
var hist = result - signal;
var signal = ppo.PPOsignal;
var hist = ppo.PPOhist;
var momentumResult = this.indicators[momentumName][momentumName];

log.debug('\t', 'PPO:', result.toFixed(digits));
Expand All @@ -51,10 +51,8 @@ method.log = function(candle) {
}

method.check = function() {
var ppo = this.indicators.ppo;
var result = ppo.ppo;
var signal = ppo.PPOsignal.result;
var hist = result - signal;
var ppo = this.indicators.ppo.result;
var hist = ppo.PPOhist;

var value = this.indicators[momentumName][momentumName];

Expand Down