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
#2
Quote:I am not sure if this is the right forum to post in, so if not please move my thread.

This is fine! Though can you next time put code in a codeblock? This is a bit hard to read.

----

This start never buys or sells because it's checking something called "this.stockRSI" which is never defined. Probably needs to be "stochRSI" instead.
  Reply
#3
When I remove "this." the backtest doesn't even run. There is not even a chart anymore.

With the code posted in this thread the backtest does run, it just never buys or sells even though the parameters have had to have been fulfilled in the time-frame.





Code:
// 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 repasted it in codeblock here
  Reply
#4
Hello,

you wrote stockRSI instead of stochRSI in the check function.

Bye
  Reply
#5
(10-09-2018, 11:07 PM)Nigry Wrote: Hello,

you wrote stockRSI instead of stochRSI in the check function.

Bye

Wow, I feel stupid for not catching that. Thanks for spotting that!
Unfortunately after fixing this it still doesn't work.
  Reply
#6
replace:
this.interval = this.settings.interval;

with:
this.interval = 7;

it works. So I conclude that you do not have any .toml files in the Config / strategies folder, or it is written incorrectly.

bye
  Reply


Forum Jump:


Users browsing this thread: