From 70b6b03325bc77dd253f9132846ec7507732add6 Mon Sep 17 00:00:00 2001 From: bgh91 <32361514+bgh91@users.noreply.github.com> Date: Thu, 12 Jul 2018 16:02:44 +1000 Subject: [PATCH 1/3] Update STOCH.js Getting the same values as Tradingview. Make sure the time zone is correct on tradingview to compare. When the exchange data fails Tradingview cut out the data that is missing but gekko just freezes and all the numbers go to the same for close, high and low candle. Then causes the K and D numbers to NaN, stopped this with - if (candle.high !== candle.low). Added Smooth K, set to 1 to disable Takes 5-6 candles for K % D calculations to catch up initially ?? not sure how to correct this Test with: var method = {}; method.init = function() { this.name = "Tradingview-tester"; this.addIndicator('ind', 'STOCH', {KPeriods: 5, DPeriods: 3, smoothKPeriods :2}); }; method.check = function() {}; method.update= function(candle) { console.log("Time: " + candle.start.format()) console.log("High : " + candle.high); console.log("Low : " + candle.low); console.log("Close : " + candle.close); console.log("LL : " + this.indicators.ind.getLowest()); console.log("HH : " + this.indicators.ind.getHighest()); console.log("%K: " + this.indicators.ind.K); console.log("%D: " + this.indicators.ind.D); console.log(); }; method.log = function() {}; module.exports = method; --- indicators/STOCH.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/indicators/STOCH.js b/indicators/STOCH.js index 4ca7e0c..341035f 100644 --- a/indicators/STOCH.js +++ b/indicators/STOCH.js @@ -1,7 +1,9 @@ // Stochastic Oscillator Slow - STOCH // Ported by Gab0 march-2018 // ref http://www.tadoc.org/indicator/STOCH.htm -// state: badly coded, uncertain results; +// Added Smooth K, set to 1 to disable +// Takes 5-6 candles for K % D calculations to catch up initially?? +// Added - if (candle.high !== candle.low), to stop NaN values in K&D when no exchange data var SMA = require('./SMA'); var _ = require('lodash'); @@ -18,6 +20,8 @@ var Indicator = function(settings) { this.KPeriods = settings.KPeriods; this.KMA = new SMA(settings.DPeriods); + this.smoothK = new SMA(settings.smoothKPeriods); + } Indicator.prototype.getLowest = function() @@ -55,6 +59,9 @@ Indicator.prototype.getHighest = function() Indicator.prototype.update = function(candle) { + if (candle.high !== candle.low) + { + this.candles.push(candle); if (this.candles.length > this.KPeriods) this.candles.shift(); @@ -63,14 +70,20 @@ Indicator.prototype.update = function(candle) { var LL = this.getLowest(); var HH = this.getHighest() + + var K = candle.close - LL; K = K / (HH - LL) * 100; - this.KMA.update(K); + this.smoothK.update(K) - this.K = K; + var smoothD = this.smoothK.result + this.KMA.update(smoothD); + + this.K = this.smoothK.result; this.D = this.KMA.result; + } } module.exports = Indicator; From 0ae434ffbd499204da26ce5bd694d69fc3031d08 Mon Sep 17 00:00:00 2001 From: bgh91 <32361514+bgh91@users.noreply.github.com> Date: Thu, 12 Jul 2018 16:08:14 +1000 Subject: [PATCH 2/3] Update STOCH.js --- indicators/STOCH.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/indicators/STOCH.js b/indicators/STOCH.js index 341035f..60f3851 100644 --- a/indicators/STOCH.js +++ b/indicators/STOCH.js @@ -70,8 +70,7 @@ Indicator.prototype.update = function(candle) { var LL = this.getLowest(); var HH = this.getHighest() - - + var K = candle.close - LL; K = K / (HH - LL) * 100; From 66de315d783bae34d6584f1129e5054384208c17 Mon Sep 17 00:00:00 2001 From: bgh91 <32361514+bgh91@users.noreply.github.com> Date: Thu, 12 Jul 2018 16:09:08 +1000 Subject: [PATCH 3/3] Update STOCH.js --- indicators/STOCH.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indicators/STOCH.js b/indicators/STOCH.js index 60f3851..8c51cfa 100644 --- a/indicators/STOCH.js +++ b/indicators/STOCH.js @@ -70,7 +70,7 @@ Indicator.prototype.update = function(candle) { var LL = this.getLowest(); var HH = this.getHighest() - + var K = candle.close - LL; K = K / (HH - LL) * 100;