-
Notifications
You must be signed in to change notification settings - Fork 21
/
StepGains.js
65 lines (54 loc) · 1.47 KB
/
StepGains.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
64
65
/*
StepGains - Crypto49er 2018-04-21
*/
// helpers
var _ = require('lodash');
var log = require('../core/log.js');
var watchPrice = 0.0;
var lowestPrice = 0.0;
var sellPrice = 0.0;
var advised = false;
// Let's create our own buy and sell strategy
var strat = {};
// Prepare everything our strat needs
strat.init = function() {
// how many candles do we need as a base
// before we can start giving advice?
this.requiredHistory = this.tradingAdvisor.historySize;
}
// What happens on every new candle?
strat.update = function(candle) {
// Display close price in terminal
log.debug('candle time', candle.start);
log.debug('candle close price:', candle.close);
}
// For debugging purposes.
strat.log = function() {
}
// Based on the newly calculated
// information, check if we should
// update or not.
strat.check = function(candle) {
if(watchPrice == 0){
watchPrice = candle.close * 0.98;
}
if(candle.close <= watchPrice){
lowestPrice = candle.close;
}
if(candle.close > lowestPrice && !advised){
this.advice("long");
log.debug('Buying at', candle.close);
sellPrice = candle.close * 1.03;
advised = true;
}
if(candle.close > sellPrice && watchPrice != 0 && lowestPrice != 0){
this.advice("short");
log.debug('Selling at', candle.close);
watchPrice = 0;
lowestPrice = 0;
buyPrice = 0;
sellPrice = 0;
advised = false;
}
}
module.exports = strat;