Skip to content

Commit

Permalink
ZERO method sanity check using stats window
Browse files Browse the repository at this point in the history
current "proof of concept" to make sure the price
is in the 25th percentile (cheap) before buying

config with .window parameter under ZERO section:

example: set window to 1440 minutes to use 1 day's data
  • Loading branch information
Sarah White committed Jul 14, 2014
1 parent eefcf1d commit b554b26
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion methods/ZERO.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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;
Expand All @@ -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') {
Expand Down
2 changes: 2 additions & 0 deletions methods/indicators/windowstats.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down

0 comments on commit b554b26

Please sign in to comment.