09-23-2018, 04:23 PM
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 ?
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;