Gekko Forum
Help with Trailing SL - 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: Help with Trailing SL (/thread-57343.html)

Pages: 1 2


Help with Trailing SL - Kris191 - 07-12-2018

Hi all,

I want to add a trailing stoploss into a strat i have the code for both but no idea how to being them together, any tips?

Thanks


RE: Help with Trailing SL - Kris191 - 07-16-2018

Anyone able to help?


RE: Help with Trailing SL - askmike - 07-17-2018

There are some guides on the forum regarding stop losses, but if you are not that comfortable it is probably better to wait until we get native stop losses added, see here: https://forum.gekko.wizb.it/thread-57314.html


RE: Help with Trailing SL - Kris191 - 07-17-2018

(07-17-2018, 03:06 AM)askmike Wrote: There are some guides on the forum regarding stop losses, but if you are not that comfortable it is probably better to wait until we get native stop losses added, see here: https://forum.gekko.wizb.it/thread-57314.html

Well i tried to put the trailing stop loss into the strat and if im honest it looks good to me but the computer says no!! Anyone albe to tell me whats wrong with this??

Code:
// Source: https://raw.githubusercontent.com/vrfurl/gekko/stable/strategies/DEMACrossover.js
// Downloaded from: https://github.com/xFFFFF/Gekko-Strategies
// helpers
var _ = require('lodash');
var log = require('../core/log.js');
var helper = require('../helper.js');

// let's create our own method
var method = {};

// prepare everything our method needs
method.init = function() {
 this.name = 'DEMACrossover';

 this.currentTrend;
 this.requiredHistory = 0;

 // define the indicators we need
 //this.addIndicator('dema', 'DEMA', this.settings);

 //Determine if we first want to buy or sell
 if(this.settings.firstTrade === 'buy') {
   this.currentTrend = 'down';
 }
 else if(this.settings.firstTrade === 'sell'){
   this.currentTrend = 'up';
 }

 log.debug("Short DEMA size: "+this.settings.shortSize);
 log.debug("Long DEMA size: "+this.settings.longSize);

 this.addTalibIndicator('shortDEMA', 'dema', {optInTimePeriod : this.settings.shortSize});
 this.addTalibIndicator('longDEMA', 'dema', {optInTimePeriod : this.settings.longSize});

 log.debug(this.name+' Strategy initialized');

}
strat.init = function() {
   this.stopLoss = helper.trailingStopLoss();
   this.stopLoss.percentage = this.settings.trailingStop.percentage;
    }

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

// for debugging purposes: log the last calculated
// EMAs and diff.
method.log = function() {
 var shortDEMA = this.talibIndicators.shortDEMA;
 var longDEMA = this.talibIndicators.longDEMA;


 log.debug('Required history is: '+this.requiredHistory);

 log.debug('calculated DEMA properties for candle:');

 log.debug('\t shortDEMA :', shortDEMA.result);

 log.debug('\t', 'longDEMA:', longDEMA.result);
}


method.check = function(candle) {

 var shortResult = this.talibIndicators.shortDEMA.result.outReal;
 var longResult = this.talibIndicators.longDEMA.result.outReal;
 var price = candle.close;

 var message = '@ ' + price.toFixed(8);

if(this.stopLoss.isTriggered(currentPrice)) {
       this.advice('short');
       this.stopLoss.destroy();

 //DEMA Golden Cross
 if(shortResult >  longResult) {
   log.debug('we are currently in uptrend', message);

   if(this.currentTrend !== 'up') {
     this.currentTrend = 'up';
     this.advice('long');
     log.debug("Going to buy");
   } else {
     log.debug("Nothing to buy");
     this.advice();
   }

 } else if(longResult > shortResult) {
   log.debug('we are currently in a downtrend', message);

   if(this.currentTrend !== 'down') {
     this.currentTrend = 'down';
     this.advice('short');
     log.debug("Going to sell");
   } else
     log.debug("Nothing to sell");
     this.advice();

 }  else if(shortConditions) {
       this.advice('short');
       this.stopLoss.destroy();

   } else {
       this.stopLoss.update(currentPrice);
       this.advice();
    }else {
   log.debug('we are currently not in an up or down trend', message);
   this.advice();
 }

}

module.exports = method;



RE: Help with Trailing SL - crypto49er - 07-18-2018

@Kris191,

Are you getting an error message or is the trailing stop loss not working at all?


RE: Help with Trailing SL - mark.sch - 07-18-2018

@crypto49er Keep on publishing your Gekko videos on youtube, I like, great work :-D What is left on your crypto gameplan?


RE: Help with Trailing SL - Kris191 - 07-18-2018

(07-18-2018, 07:09 PM)crypto49er Wrote: @Kris191,

Are you getting an error message or is the trailing stop loss not working at all?

Just not working, I've found a TEMA strat i'm going to try and re config, so watch this space.


RE: Help with Trailing SL - Kris191 - 07-19-2018

So can someone advise on this please.

I want the follwoing to happen:

Buy when medium crosses above the long
Sell when medium crosses below the long
Sell when the short crosses below the medium but medium is still above the long
Buy when the short crosses above the medium but the medium is still above the long

code currently is:
Code:
if((short > medium) && (medium > long)) {
   this.advice('long')
 } else if((short < medium) && (medium > long)) {
   this.advice('short')
 } else if(((short > medium) && (medium < long))) {
   this.advice('short')
 } else {
   this.advice();

I think its almost there but can some one help me??

Also how do i add console notifications in this saying buy and sell.
thanks


RE: Help with Trailing SL - crypto49er - 07-20-2018

@mark.sch,

Thanks! Appreciate it. I got the basics of Zappra's communicate with Gekko via Telegram working. Will try to have a video out today. Other than that, still looking into ways to have Gekko trade with a specific starting amount and have that amount go up/down based on the sell so I can run multiple gekko off the same API key for an exchange. I know AskMike has implemented the base for this in 0.6 but it isn't working yet.

@Kris191,

I will drop the "else" and just use a bunch of if statements. It just makes things more confusing. You can also use "switch" instead of if statements since you have two conditions that will trigger a sell for cleaner code. Just add log.info('message') within the if brackets to get the console notifications. Then just find time frames in backtest data that will trigger each of these if statements to confirm if they are working as you need it.


RE: Help with Trailing SL - Kris191 - 07-22-2018

(07-20-2018, 05:32 PM)crypto49er Wrote: @mark.sch,

Thanks! Appreciate it. I got the basics of Zappra's communicate with Gekko via Telegram working. Will try to have a video out today. Other than that, still looking into ways to have Gekko trade with a specific starting amount and have that amount go up/down based on the sell so I can run multiple gekko off the same API key for an exchange. I know AskMike has implemented the base for this in 0.6 but it isn't working yet.

@Kris191,

I will  drop the "else" and just use a bunch of if statements. It just makes things more confusing. You can also use "switch" instead of if statements since you have two conditions that will trigger a sell for cleaner code. Just add log.info('message') within the if brackets to get the console notifications. Then just find time frames in backtest data that will trigger each of these if statements to confirm if they are working as you need it.

wow thats just confused me more lol i need to learn some code as i back tested the strat and it didnt trigger a sell or buy