Created
August 11, 2018 07:48
-
-
Save askmike/ce4120ade30c7da02910c882f6312c99 to your computer and use it in GitHub Desktop.
ema test
This file contains hidden or 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
// This is a basic example strategy for Gekko. | |
// For more information on everything please refer | |
// to this document: | |
// | |
// https://gekko.wizb.it/docs/strategies/creating_a_strategy.html | |
// | |
// The example below is pretty bad investment advice: on every new candle there is | |
// a 10% chance it will recommend to change your position (to either | |
// long or short). | |
var log = require('../core/log'); | |
// Let's create our own strat | |
var strat = {}; | |
// Prepare everything our method needs | |
strat.init = function() { | |
this.input = 'candle'; | |
this.currentTrend = 'long'; | |
this.requiredHistory = 0; | |
var weight = 10; | |
// add the indicator to the strategy | |
this.addIndicator('myema', 'EMA', weight); | |
} | |
// What happens on every new candle? | |
strat.update = function(candle) { | |
// Get a random number between 0 and 1. | |
this.randomNumber = Math.random(); | |
// There is a 10% chance it is smaller than 0.1 | |
this.toUpdate = this.randomNumber < 0.1; | |
} | |
// For debugging purposes. | |
strat.log = function() { | |
// log.debug('calculated random number:'); | |
// log.debug('\t', this.randomNumber.toFixed(3)); | |
} | |
// Based on the newly calculated | |
// information, check if we should | |
// update or not. | |
strat.check = function() { | |
// use indicator results | |
const ema = this.indicators.myema.result; | |
console.log('EMA: ' + ema); | |
} | |
module.exports = strat; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment