stochrsi strategy doesn't buy or sell
#1
I am trying to make a strategy based on stochrsi and I cannot get it to either buy or sell. So I backtracked and made it as basic as can be to see where the problem is and it still never buys or sells in the backtest. It also doesn't matter if I define the stochrsi or use the talib library. 
Here is the basic code I have with stochrsi defined:

// let's create our own method
var strat = {};

var _ = require('lodash');
var log = require('../core/log.js');

var RSI = require('./indicators/RSI.js');

// prepare everything our method needs
strat.init = function() {
 this.interval = this.settings.interval;

 this.trend = {
   direction: 'none',
   duration: 0,
   persisted: false,
   adviced: false
 };

 this.requiredHistory = this.tradingAdvisor.historySize;

 // define the indicators we need
 this.addIndicator('rsi', 'RSI', { interval: this.interval });

this.RSIhistory = [];
}

// what happens on every new candle?
strat.update = function(candle) {
this.rsi = this.indicators.rsi.result;

this.RSIhistory.push(this.rsi);

if(_.size(this.RSIhistory) > this.interval)
// remove oldest RSI value
this.RSIhistory.shift();

this.lowestRSI = _.min(this.RSIhistory);
this.highestRSI = _.max(this.RSIhistory);
this.stochRSI = ((this.rsi - this.lowestRSI) / (this.highestRSI - this.lowestRSI)) * 100;
}

strat.log = function() {
 
}

strat.check = function() {
   if(this.stockRSI < 25){
       this.advice('long');
       console.log("buy");
   }
   else if(this.stockRSI > 50) {
       this.advice('short');
       console.log("sell");
   }
}
module.exports = strat;


I am not sure if this is the right forum to post in, so if not please move my thread. 
Thank you very much
  Reply


Messages In This Thread
stochrsi strategy doesn't buy or sell - by damnnnnn - 09-28-2018, 07:13 AM

Forum Jump:


Users browsing this thread: