Last active
November 14, 2018 19:04
-
-
Save mnofresno/bd4d6a501e62eec649c77a61a10cf429 to your computer and use it in GitHub Desktop.
Gekko strategy for learning purposes with 10% quarterly profit
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
// Let's create our own strategy | |
var strat = {}; | |
// Prepare everything our strat needs | |
strat.init = function() { | |
// your code! | |
this.count = 0; | |
var weight = 10; | |
// add the indicator to the strategy | |
this.addIndicator('myema', 'EMA', weight); | |
} | |
/* | |
{ id: 33384, | |
start: | |
{ [Number: 1535788680000] | |
_i: 1535788680000, | |
_f: undefined, | |
_l: undefined, | |
_strict: undefined, | |
_isUTC: false, | |
_pf: | |
{ empty: false, | |
unusedTokens: [], | |
unusedInput: [], | |
overflow: -2, | |
charsLeftOver: 0, | |
nullInput: false, | |
invalidMonth: null, | |
invalidFormat: false, | |
userInvalidated: false, | |
iso: false }, | |
_d: 2018-09-01T07:58:00.000Z }, | |
open: 7047.8, | |
high: 7053.89463206, | |
low: 7047.8, | |
close: 7053.89463206, | |
vwp: 7050.688903599112, | |
volume: 14.509290799999999, | |
trades: 23 } | |
*/ | |
// Based on the newly calculated | |
// information, check if we should | |
// update or not. | |
var porcentaje = 1; | |
strat.check = function(candle) { | |
console.log('candle: ', candle); | |
//throw 'e'; | |
this.count++; | |
var ema = this.indicators.myema.result; | |
if(candle.high < ema*(1-porcentaje/100)) { | |
this.advice('long'); | |
} else if( candle.low > ema*(1+porcentaje/100)){ | |
this.advice('short'); | |
} | |
} | |
strat.end = function() { | |
console.log('count: ', this.count); | |
}; | |
module.exports = strat; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment