Gekko Forum
RSI = 0 first view candles - Printable Version

+- Gekko Forum (https://forum.gekko.wizb.it)
+-- Forum: Gekko (https://forum.gekko.wizb.it/forum-13.html)
+--- Forum: Technical Discussion (https://forum.gekko.wizb.it/forum-23.html)
+--- Thread: RSI = 0 first view candles (/thread-57676.html)



RSI = 0 first view candles - PrimalFury - 09-23-2018

I have a simple rsi script which buys at rsi below 30 en buy at rsi above 70


Every candle which it checks it also prints out the RSI value

See the attachment. why are the first rsi value 0 ?

Code:
// Let's create our own strategy
var strat = {};

var RSIinterval = 14;
var RSIlow = 30;
var RSIhigh = 70;


strat.init = function() {

this.addIndicator('rsi', 'RSI', { interval: RSIinterval });    

}

// What happens on every new candle?
strat.update = function(candle) {
 // your code!
}

// For debugging purposes.
strat.log = function() {
 // your code!
}

// Based on the newly calculated
// information, check if we should
// update or not.
strat.check = function(candle) {

var RSI = this.indicators.rsi.result;
var RSIsaysSELL = RSI > RSIhigh;
var RSIsaysBUY = RSI < RSIlow;  
   console.log(RSI)    
   
   
   if (RSIsaysBUY)
   {
       this.advice('long')
   }    
   

if (RSIsaysSELL)
   {
     
    this.advice('short')
   
   }    
}

strat.end = function() {
 // your code!
}

module.exports = strat;



RE: RSI = 0 first view candles - cubit - 09-23-2018

Just a guess but there are 14 zeros so I would say that relates to your RSIinterval of 14... it probably requires this many iterations to warm up! Smile


RE: RSI = 0 first view candles - PrimalFury - 09-23-2018

(09-23-2018, 07:55 PM)cubit Wrote: Just a guess but there are 14 zeros so I would say that relates to your RSIinterval of 14... it probably requires this many iterations to warm up! Smile

could be. But how do I prevent the strategy to buy in the first 14 candles ?

it is 0, so the strategy says buy.


RE: RSI = 0 first view candles - cubit - 09-23-2018

put something like (and RsiValue!=0) into your code! Smile


RE: RSI = 0 first view candles - cubit - 09-23-2018

Something like this! :

if (RSIsaysBUY && RSI!=0)
{
this.advice('long')
}


RE: RSI = 0 first view candles - mark.sch - 09-24-2018

Add a history size to your tradingAdvisor config, like this:

config.tradingAdvisor = {
enabled: true,
method: 'myStrat',
candleSize: 60,
historySize: 14
}

This will force Gekko to call your strategy update function 14 times until it calls the check function for the first time, so all your indicator candle arrays are prepared and will give you valid results. At least this will work in the CLI version, not sure if it is already in the UI version - in the past it was not.