Stochastics over Heiken Ashi candles
#1
Hi,

I already implemented Heiken Ashi candles in my strategy, but now I want to have a stochastics indicator running on those heiken ashi candles. How can I do that? The input candle/price is hard coded inside the indicators. I can't send my own (Heiken Ashi) HOCL data to the indicator do I?
  Reply
#2
(04-17-2018, 10:00 AM)niquedegraaff Wrote: Hi,

I already implemented Heiken Ashi candles in my strategy, but now I want to have a stochastics indicator running on those heiken ashi candles. How can I do that? The input candle/price is hard coded inside the indicators. I can't send my own (Heiken Ashi) HOCL data to the indicator do I?

No one that can help me in the right direction here?

How do I run my own custom heiken candle data through a Indicator?
  Reply
#3
Add the indicator as a require:
Code:
var myInd = require(./indicators/myInd.js);

Then add it as:   
Code:
this.myIndicator = new myInd(myParameters);


Gekko won't automatically update this, so in the update block you need to call update, with your HA candle instead of the normal candle: 
Code:
this.myIndicator.update(myHACandle);
  Reply
#4
Thanks, but I still encounter some problems with this. The SMA indicator (i want smoothed K and D over stochRSI) is returning NaN results. I don't see where the problem is. The input is good (Input Price) but the SMA Indicator seems to have problems calculating it.

Code:
// Prepare everything our method needs
strat.init = function () {
 this.name = 'Heiken';
 this.requiredHistory = 14;
 this.interval = 14;

 this.rsi = new RSI({interval: this.interval});
 this.RSIhistory = [];

 this.addIndicator('stochK', 'SMA', 3);
 this.addIndicator('stochD', 'SMA', 3);
}

// What happens on every new candle?
strat.update = function (candle) {
 this.heikenCandle = this.heikenAshi(candle);
 
 this.rsi.update(this.heikenCandle);

 this.RSIhistory.push(this.rsi.result);

 if(_.size(this.RSIhistory) > this.interval)
   this.RSIhistory.shift();

 this.lowestRSI = _.min(this.RSIhistory);
 this.highestRSI = _.max(this.RSIhistory);

 var price = ((this.rsi.result - this.lowestRSI) / (this.highestRSI - this.lowestRSI)) * 100;
 log.debug('Input price:', price);
 this.indicators.stochK.update(price);
 log.debug(this.indicators.stochK);

 this.previousHeikenCandle = this.heikenCandle;
}


Result (limited to 2 results for readability):
Code:
2018-04-21 09:36:45 (DEBUG):    Input price: 100
2018-04-21 09:36:45 (DEBUG):    Indicator {
 input: 'price',
 windowLength: 3,
 prices: [ 494.7, 100, 100 ],
 result: NaN,
 age: 2,
 sum: NaN }
2018-04-21 09:36:45 (DEBUG):    calculated properties for candle 2018-04-13 01:45:00:
2018-04-21 09:36:45 (DEBUG):             Candle:        open[495] close[494.7]
2018-04-21 09:36:45 (DEBUG):             Heiken:        open[494.24] close[495.07]
2018-04-21 09:36:45 (DEBUG):             StochRSI:      k[NaN]


2018-04-21 09:36:45 (DEBUG):    Input price: 84.86116310138854
2018-04-21 09:36:45 (DEBUG):    Indicator {
 input: 'price',
 windowLength: 3,
 prices: [ 84.86116310138854, 100, 494 ],
 result: NaN,
 age: 1,
 sum: NaN }
2018-04-21 09:36:45 (DEBUG):    calculated properties for candle 2018-04-13 01:50:00:
2018-04-21 09:36:45 (DEBUG):             Candle:        open[494.71] close[494]
2018-04-21 09:36:45 (DEBUG):             Heiken:        open[494.65] close[494.68]
2018-04-21 09:36:45 (DEBUG):             StochRSI:      k[NaN]
  Reply


Forum Jump:


Users browsing this thread: