Created
November 15, 2017 22:39
-
-
Save Gab0/5bf2621bc0abfd88bca821f20e7c627a to your computer and use it in GitHub Desktop.
some Strategies for Gekko Trading Bot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// helpers | |
var _ = require('lodash'); | |
var log = require('../core/log.js'); | |
// let's create our own method | |
var method = {}; | |
method.init = function() { | |
this.age = 0; | |
this.currentTrend; | |
this.requiredHistory = 6; | |
this.addIndicator('macd', 'MACD', this.settings); | |
this.addIndicator('rsi', 'RSI', this.settings); | |
this.addIndicator('bb', 'BB', this.settings.bbands); | |
this.lastSignal = -1; | |
this.macdCross=0; | |
} | |
// what happens on every new candle? | |
method.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();*/ | |
} | |
method.log = function() { | |
// for debugging purposes;;; | |
var BB = this.indicators.bb; | |
log.debug(this.indicators.macd.signal.result); | |
log.debug(BB.lower, BB.middle, BB.upper); | |
} | |
method.isPositive = function(numb) //useful to calculate if macd has crossed; | |
{ | |
return numb >=0; | |
} | |
method.check = function(candle) { | |
var signal = this.indicators.macd.signal.result; | |
var price = candle.close; | |
var BB = this.indicators.bb; | |
var rsiVal = this.indicators.rsi.result; | |
var macdVal = this.indicators.macd.result; | |
var macdDiff = this.indicators.macd.diff; | |
var macdSignal = this.indicators.macd.signal; | |
if (this.isPositive(macdSignal) != this.isPositive(this.lastSignal)) | |
{// Cross happens!; | |
this.macdCross = this.settings.crosspersistence; | |
} | |
else | |
{ | |
this.macdCross--; | |
if (this.macdCross <0) | |
this.macdCross=0; | |
} | |
var validation = function(ConditionList) | |
{ | |
var validNB = ConditionList.filter(function(s) { return s; }).length; | |
return validNB/ ConditionList.length; | |
} | |
this.age++; | |
var message = '@ ' + price.toFixed(8) + ' (' + signal.toFixed(5) + ')'; | |
var BuyConditions = [ signal < BB.lower, | |
rsiVal < this.settings.rsilow, | |
macdDiff > this.settings.macdhigh, | |
this.macdCross > 0 && macdDiff > 0 ]; | |
var SellConditions = [ signal > BB.upper, | |
macdDiff < this.settings.macdlow, | |
this.macdCross > 0 && macdDiff < 0, | |
rsiVal > this.settings.rsihigh ]; | |
if (validation(BuyConditions) > 0.6) | |
{ | |
log.debug('we are currently in uptrend', message); | |
if(this.currentTrend !== 'up') { | |
this.currentTrend = 'up'; | |
this.advice('long'); | |
} else | |
this.advice(); | |
} | |
else if (validation(SellConditions) > 0.6) | |
{ | |
log.debug('we are currently in a downtrend', message); | |
if (this.currentTrend !== 'down') { | |
this.currentTrend = 'down'; | |
this.advice('short'); | |
} else | |
this.advice(); | |
} else { | |
log.debug('we are currently not in an up or down trend', message); | |
this.advice(); | |
} | |
this.macdSignal = macdSignal; | |
} | |
module.exports = method; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment