Changing EMA to DEMA in a native strat (help please)
#1
Hi all,

I want to change the below strat from using EMA to using DEMA but if i change
 'this.addIndicator('short', 'EMA', this.settings.short)' to   this.addIndicator('short', 'DEMA', this.settings.short). 

Then i get the error in fig 2, the only thing that changes is the addition of the letter D. Even if

This is the working code, when i change 'EMA' to 'DEMA' i get the error in fig 2


Code:
var log = require('../core/log.js');

var method = {};

method.init = function() {
 this.name = 'Triple Moving Average';
 this.requiredHistory = this.settings.long;

 this.addIndicator('short', 'EMA', this.settings.short)
 this.addIndicator('medium', 'EMA', this.settings.medium)
 this.addIndicator('long', 'EMA', this.settings.long)
}

method.update = function(candle) {
 this.indicators.short.update(candle.close)
 this.indicators.medium.update(candle.close)
 this.indicators.long.update(candle.close)

 if((this.indicators.short.result > this.indicators.medium.result) && (this.indicators.medium.result > this.indicators.long.result)) {
 log.info('We are in an UP trend: Price =', this.indicators.short.result.toFixed(8))
} else if(this.indicators.medium.result < this.indicators.long.result) {
   log.info('We are in a DOWN trend: Price =', this.indicators.short.result.toFixed(8))
 }
}

method.check = function() {
 const short = this.indicators.short.result;
 const medium = this.indicators.medium.result;
 const long = this.indicators.long.result;

 if((short > medium) && (medium > long)) {
   this.advice('long')
   log.info('Were going long')
 } else if((short < medium) && (medium > long)) {
   this.advice('short')
   log.info('Were getting outta this')
 } else if((short > medium) && (medium < long)) {
   this.advice('short')
   log.info('Were getting outta this')
 } else {
   this.advice();
 }
}

module.exports = method;

fig 2

Code:
/root/gekko/strategies/TMA2.js:7
 this.requiredHistory = this.settings.long;
                                      ^

TypeError: Cannot read property 'long' of undefined
   at Base.method.init (/root/gekko/strategies/TMA2.js:7:40)
   at Base.bound [as init] (/root/gekko/node_modules/lodash/dist/lodash.js:729:21)
   at new Base (/root/gekko/plugins/tradingAdvisor/baseTradingMethod.js:70:8)
   at Actor.setupTradingMethod (/root/gekko/plugins/tradingAdvisor/tradingAdvisor.js:60:17)
   at Actor.bound [as setupTradingMethod] (/root/gekko/node_modules/lodash/dist/lodash.js:729:21)
   at new Actor (/root/gekko/plugins/tradingAdvisor/tradingAdvisor.js:23:8)
   at load (/root/gekko/core/pluginUtil.js:98:22)
   at /root/gekko/node_modules/async/dist/async.js:1156:9
   at replenish (/root/gekko/node_modules/async/dist/async.js:1030:17)
   at iterateeCallback (/root/gekko/node_modules/async/dist/async.js:1015:17)
root@vps520385:~/gekko# node gekko --config test.js --backtest
Help please, i'm guessing EMA and DEMA read code different but the DEMA indicator uses the EMA indicator??/

Thanks

EDIT: @askmike i hope this makes it clearer as to where my issue is.
  Reply
#2
Could you next time make the title of the thread a bit more descriptive (and also edit this one)? Thanks!

Your settings are defined in your config, Gekko will pass anything in your config with the same name as your strategy (in your case "TMA2"). So basically Gekko complains that your config doens't have something like this:

Code:
config.TMA2 = { long: 10 }

Read this: https://gekko.wizb.it/docs/strategies/cr...figurables
  Reply
#3
I made the DEMA changes in the normal TMA config and it hangs on backtest then fails with no output in the console, I have no idea what (surprise surprise), any ideas that i can try, if i change EMA to SMA it works but not going from EMA to DEMA.

If you need more info please let me know and i will happily provide it.

EDIT: also works if i change it to WMA
  Reply


Forum Jump:


Users browsing this thread: