Gekko Forum
Strategy does not return expected result - 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: Strategy does not return expected result (/thread-58005.html)



Strategy does not return expected result - lucascostner - 09-11-2019

Hey everyone- hope you can help me out with this. I've been revisiting an old strategy post from a year or so ago. So this doesn't generate any errors when I run it, but something is off because the IFRSI indicator never returns anything. When I console.log to print the result as it runs it always comes back with "false"- it should be returning 0.5 or -0.5. Anyone have any advice for me on this? The two required indicators and the strategy file are below.....


Here is the first indicator:



/indicators/IFTRSI.js   


Code:
var RSI = require('./RSI.js');
var WMA = require('./WMA.js');

var Indicator = function(config) {
 this.result = false;
 this.rsiInterval = config.interval;
 this.wmaLength = config.length;
 this.rsi = new RSI({interval: this.rsiInterval});
this.wma = new WMA({length: this.wmaLength});
}

Indicator.prototype.update = function (candle) {
 this.rsi.update(candle);
 if (this.rsi.result) {
   let v1 = 0.1 * (this.rsi.result - 50);
   this.wma.update(v1);

   if (this.wma.result) { 
       this.result = (Math.exp(2 * this.wma.result)-1) / (Math.exp(2 * this.wma.result)+1);
   }
 }
}

module.exports = Indicator;


Here is the second indicator-


 /indicators/WMA.js


Code:
var Indicator = function(settings) {
   this.input = 'price';
   this.windowLength = settings.length;
   this.prices = [];
   this.result = 0;
   this.age = 0;
   this.sum = 0;
}

Indicator.prototype.update = function(price) {
   var tail = this.prices[this.age] || 0;
   this.prices.push(price);


   var psum =0;
   var pdiv = 0;

   for (var j=0;j<this.prices.length;j++)
   {

       psum += j * this.prices[j];
       pdiv += j;

   }

   this.result = psum/pdiv;
   if (this.prices.length > this.windowLength)
   {
       this.prices.shift()

   }

   this.age = (this.age + 1) % this.windowLength
}

module.exports = Indicator;

And here is the strategy file--


/strategies/IFRSI.js

Code:
var method = {};
var traded = false;
var IFTRSI = require('./indicators/IFTRSI.js');
method.init = function() {
    var iftrsiParameters = {rsiInterval: 14, wmaLength: 8};
    this.addIndicator('iftrsi', 'IFTRSI', iftrsiParameters);
    
}
method.update = function(candle) {
    this.indicators.iftrsi.update(candle);
  
}
method.check = function(candle) {
    var iftResult = this.indicators.iftrsi.result;

    console.log(iftResult);

if ( traded == false && iftResult == -0.5 ){
    this.advice('long')
    traded = true;
    console.log(iftResult);
} else if(traded == true && iftResult == 0.5 ){
    this.advice('short')
    console.log(iftResult);
    traded = false;
}
}


module.exports = method;