forked from askmike/gekko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom.js
62 lines (47 loc) · 1.4 KB
/
custom.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// 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.currentTrend = 'long';
this.requiredHistory = 0;
}
// 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() {
// Only continue if we have a new update.
if(!this.toUpdate)
return;
if(this.currentTrend === 'long') {
// If it was long, set it to short
this.currentTrend = 'short';
this.advice('short');
} else {
// If it was short, set it to long
this.currentTrend = 'long';
this.advice('long');
}
}
module.exports = strat;