forked from askmike/gekko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom.js
63 lines (48 loc) · 1.48 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
63
// If you want to use your own trading methods you can
// write them here. For more information on everything you
// can use please refer to this document:
//
// https://github.com/askmike/gekko/blob/stable/docs/trading_methods.md
//
// The example below is pretty stupid: on every new candle there is
// a 10% chance it will recommand to change your position (to either
// long or short).
var config = require('../core/util.js').getConfig();
var settings = config.custom;
// Let's create our own method
var method = {};
// Prepare everything our method needs
method.init = function() {
this.currentTrend = 'long';
this.requiredHistory = 0;
}
// What happens on every new candle?
method.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 = randomNumber < 0.1;
}
// For debugging purposes.
method.log = function() {
console.log('calculated random number:');
console.log('\t', this.randomNumber.toFixed(3));
}
// Based on the newly calculated
// information, check if we should
// update or not.
method.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 = method;