Gekko Forum
[BOUNTY COMPLETD] fix DEMA example strategy - Printable Version

+- Gekko Forum (https://forum.gekko.wizb.it)
+-- Forum: Gekko (https://forum.gekko.wizb.it/forum-13.html)
+--- Forum: Feature Requests (https://forum.gekko.wizb.it/forum-15.html)
+--- Thread: [BOUNTY COMPLETD] fix DEMA example strategy (/thread-93.html)

Pages: 1 2


[BOUNTY COMPLETD] fix DEMA example strategy - askmike - 01-29-2018

Gekko comes with an indicator called DEMA, it is supposed to implement the Double EMA indicator properly. However @ pointed out the current implementation is not correct, see #1812 for more details.

Who ever can get a PR merged that:

- fixes the indicator to implement the described algorithm ["DEMA = ( 2 * EMA(n)) - (EMA(EMA(n)) ), where n= period"]
- fixes the current DEMA test.
- updates the DEMA strategy to only use a single period n.
- updates the sample-config and the toml config file to use a single period n.

Can claim a bounty of 0.003 BTC (currently worth ~$33.15), the bounty comes from me Smile


RE: [BOUNTY] fix DEMA example strategy - askmike - 01-31-2018

A PR is currently proposed that fixes the DEMA: https://github.com/askmike/gekko/pull/1822

if everything checks out this bounty is to be claimed by Paulovms ( https://github.com/Paulovms )


RE: [BOUNTY] fix DEMA example strategy - tommiehansen - 01-31-2018

No, but you can have my basic TEMA-strategy (tulip) that would hardly be impossible to convert to using DEMA instead:

js
Code:
/*
    TEMA
    Triple EMA strategy with 'safety net'
    ---
    Uses two TEMA's to go long/short and a long SMA
    in order to completely stay out of market if the
    long trend is really terrible.
    ---
    The general idea is to lower the risk.
*/

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

// conf
var config = require ('../core/util.js').getConfig();
var async = require ('async');

// create method
var method = {};


// init
method.init = function()
{

   this.name = 'Triple TEMA';

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

   // yes
   this.requiredHistory = config.tradingAdvisor.historySize;
    
    // add params    
    this.addTulipIndicator('maSlow', 'tema', { optInTimePeriod: this.settings.TEMA_long });
    this.addTulipIndicator('maFast', 'tema', { optInTimePeriod: this.settings.TEMA_short });
    
    if( this.settings.SMA_long > 0 )
    {
        this.useSafety = true;
        this.addTulipIndicator('maSlowest', 'sma', { optInTimePeriod: this.settings.SMA_long });
    }
 
}

// what happens on every new candle?
method.update = function(candle) {} // nothing
method.log = function() {} // nothing

method.check = function (candle)
{
   if (candle.close.length < this.requiredHistory) { return; } // still needed?
    
    // fetch indicators
    let ti = this.tulipIndicators;
    let maFast = ti.maFast.result.result,
        maSlow = ti.maSlow.result.result,
        maSlowest = false,
        useSafety = this.useSafety;
        
    if( useSafety ) maSlowest = ti.maSlowest.result.result;
        
    
    // rules
    let goLong, goShort;
    
    goLong = maFast > maSlow ? true : false;
    goShort = maFast < maSlow ? true : false;
    
    // safety
    if( useSafety ) {
        goLong = maFast > maSlow && maSlow > maSlowest; // slow must be over the really slow trend
    }
    
    
    // LONG
    if( goLong )
    {
        // new trend? (only act on new trends)
        if (this.trend.direction !== 'up')
        {
            log.debug ('In positive trend since', this.trend.duration, 'candle (s)');
            
            // reset the state for the new trend
            this.trend = {
                duration: 0,
                persisted: false,
                direction: 'up',
                adviced: false
            };

            this.trend.duration ++;
            
            if( !this.trend.adviced )
            {
                this.trend.adviced = true;
                this.advice('long');
            }
            else
            {
                this.advice();
            }
        } // !== 'up'    
    }
    
    // SHORT
    else if( goShort )
    {
        // new trend?
        if( this.trend.direction !== 'down' ){
            
            log.debug ('In downtrend since', this.trend.duration, 'candle (s)');
            
            // reset state
            this.trend = {
                duration: 0,
                persisted: false,
                direction: 'down',
                adviced: false
            };

            this.trend.duration ++;

            if( !this.trend.adviced )
            {
                this.trend.adviced = true;
                this.advice ('short');
            }
            else
            {
                this.advice();
            }
        
        }
    }
    else
    {
        log.debug('In no trend');
        this.advice();
    }
   
} // method.check()

module.exports = method;

toml
Code:
# Triple EMA's
TEMA_short = 30
TEMA_long = 80

# Long SMA (safety net)
SMA_long = 200

# Set SMA_long to 0 (zero) to disable it

Btw -- any reason why you wouldn't just use a library for the TA's? It seems quite unessecary to reinvent the wheel?


RE: [BOUNTY] fix DEMA example strategy - susitronix - 01-31-2018

Noobee:
Hi thanks. This code looks very clean.
I can learn alot on how to use the candle data.

I am trying to create a universal Stoploss addition that uses the last averaged Buyprice (per unit), found in the portofolioManager.
this new Var could be used in every Strategie.

/plugins/trader/portofolioManager 332
price = ........ //averaging
LastTradePrice = price
LastTradeState = //Buy/Sell Flag

Just need to learn about the coding first.


RE: [BOUNTY] fix DEMA example strategy - askmike - 02-03-2018

> Btw -- any reason why you wouldn't just use a library for the TA's? It seems quite unessecary to reinvent the wheel?

Good point. The main reason being that TAlib is quite hard to install for some of our users (mainly windows users).

This bounty will go to Paulovms, it's not merged yet but will be asap.


RE: [BOUNTY] fix DEMA example strategy - paulovms - 02-03-2018

(02-03-2018, 04:18 AM)askmike Wrote: > Btw -- any reason why you wouldn't just use a library for the TA's? It seems quite unessecary to reinvent the wheel?

Good point. The main reason being that TAlib is quite hard to install for some of our users (mainly windows users).

This bounty will go to Paulovms, it's not merged yet but will be asap.
Thank you askmike!
The address is 38YTsUrcxPxwxf8UnQewjF87pBDDnjxoEx
https://gist.github.com/Paulovms/aaa277d249ba2a147e23b359404c9df4


RE: [BOUNTY] fix DEMA example strategy - briancrypto - 02-03-2018

For us newbies.. how do we add the fixes to Gekko?


RE: [BOUNTY] fix DEMA example strategy - tommiehansen - 02-03-2018

(02-03-2018, 04:18 AM)askmike Wrote: > Btw -- any reason why you wouldn't just use a library for the TA's? It seems quite unessecary to reinvent the wheel?

Good point. The main reason being that TAlib is quite hard to install for some of our users (mainly windows users).

This bounty will go to Paulovms, it's not merged yet but will be asap.

Yeah, but the tulip indicators works fine and first and foremost are fast and tested.
As said -- no need to reinvent the wheel especially since creating/testing/fixing all indicators does take some time that could be better spent doing other things.


RE: [BOUNTY] fix DEMA example strategy - briancrypto - 02-03-2018

(02-03-2018, 03:52 PM)briancrypto Wrote: For us newbies.. how do we add the fixes to Gekko?

I figured it out.. 
For all other newbies like me.. lol. here you go..

I followed the comment "A PR is currently proposed that fixes the DEMA: https://github.com/askmike/gekko/pull/1822"

I viewed the files changed.. https://github.com/askmike/gekko/pull/1822/files

Then I found those updated files by going back to the code.. https://github.com/askmike/gekko

I downloaded the updated files and replaced the old ones.


RE: [BOUNTY COMPLETD] fix DEMA example strategy - askmike - 02-04-2018

@briancrypto an easier way is to download the develop branch.

How Gekko development works is that you can download the latest development (nightly) build that include all these kind of completed bounties directly here: https://github.com/askmike/gekko (click on the green "clone or download" button). Note that the this build might have issues and bugs, we aim for the latest release to be super stable (but we only release new stable releases every once in a while, meaning this bounty is not included in a new stable release just yet).