Gekko Forum
stochrsi strategy doesn't buy or sell - Printable Version

+- Gekko Forum (https://forum.gekko.wizb.it)
+-- Forum: Gekko (https://forum.gekko.wizb.it/forum-13.html)
+--- Forum: Strategy Development (https://forum.gekko.wizb.it/forum-12.html)
+--- Thread: stochrsi strategy doesn't buy or sell (/thread-57690.html)

Pages: 1 2


stochrsi strategy doesn't buy or sell - damnnnnn - 09-28-2018

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


RE: stochrsi strategy doesn't buy or sell - askmike - 09-28-2018

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.


RE: stochrsi strategy doesn't buy or sell - damnnnnn - 10-03-2018

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


RE: stochrsi strategy doesn't buy or sell - Nigry - 10-09-2018

Hello,

you wrote stockRSI instead of stochRSI in the check function.

Bye


RE: stochrsi strategy doesn't buy or sell - damnnnnn - 10-22-2018

(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.


RE: stochrsi strategy doesn't buy or sell - Nigry - 10-22-2018

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


RE: stochrsi strategy doesn't buy or sell - GraceJordan - 09-13-2020

(10-22-2018, 11:41 AM)Nigry Wrote:  I was looking for free samples of academic papers cause writing is not my strongest suit. What luck, I’ve found a lot of templates on this website. I paid nothing to read them.



RE: stochrsi strategy doesn't buy or sell - ivanpuvko - 09-24-2020

Informations utiles, merci.


RE: stochrsi strategy doesn't buy or sell - jenniferjulie - 11-19-2020

We all know how to make a style which is everlasting and that is with Mens Flight Jacket. Jacket which makes you go crazy and will definitely be your piece which you want to wear daily. Great quality and precise material work is truly a blessing from the store.


RE: stochrsi strategy doesn't buy or sell - Aisha Lakhani - 01-08-2021

Wow, What a Excellent post. I really found this to much informatics. It is what i was searching for. Sehat Kahani I would like to suggest you that please keep sharing such type of info.