diff --git a/methods/ZERO.js b/methods/ZERO.js index 9fa34f4bc..85e2de922 100644 --- a/methods/ZERO.js +++ b/methods/ZERO.js @@ -39,6 +39,7 @@ method.log = function() { var windowstats = zero.windowstats; // historical stats for the sanity checking window: + log.debug('\t', 'VWAP:', windowstats.vwap.toFixed(digits)); log.debug('(percentiles) window stats:'); log.debug('\t', '5th:', windowstats.p5th.toFixed(digits)); log.debug('\t', '10th:', windowstats.p10th.toFixed(digits)); @@ -62,6 +63,7 @@ method.log = function() { method.check = function() { var zero = this.indicators.zero; + var windowstats = zero.windowstats; var macd = zero.diff; var signal = zero.signal.result; var macdiff = zero.result; @@ -71,7 +73,7 @@ method.check = function() { var divination = macd + crystalball; var filtered = Math.min(macdiff, divination); - if ((filtered >= minup) && (macd <= crystalball) && (signal < 0)) { + if ((filtered >= minup) && (macd <= crystalball) && (signal < 0) && (windowstats.vwap <= windowstats.p25th)) { // new trend detected if(this.trend.direction !== 'up') { diff --git a/methods/indicators/windowstats.js b/methods/indicators/windowstats.js index 61c7acd2b..37cd63aee 100644 --- a/methods/indicators/windowstats.js +++ b/methods/indicators/windowstats.js @@ -30,6 +30,7 @@ var Indicator = function(period) { this.p75ndx = Math.floor(this.period * (75 / 100)); this.p90ndx = Math.floor(this.period * (90 / 100)); this.p95ndx = Math.floor(this.period * (95 / 100)); + this.vwap = 0; }; Indicator.prototype.update = function(price) { @@ -41,6 +42,7 @@ Indicator.prototype.update = function(price) { SanitizedPrice *= 100000000; SanitizedPrice = Math.round(SanitizedPrice); SanitizedPrice /= 100000000; + this.vwap = SanitizedPrice; if (this.age >= this.period) { this.enough = true;