RSI = 0 first view candles
#1
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;


Attached Files
.png   Knipsel.PNG (Size: 56.62 KB / Downloads: 5)
  Reply
#2
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
  Reply
#3
(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.
  Reply
#4
put something like (and RsiValue!=0) into your code! Smile
  Reply
#5
Something like this! :

if (RSIsaysBUY && RSI!=0)
{
this.advice('long')
}
  Reply
#6
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.
  Reply


Forum Jump:


Users browsing this thread: