-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathTWIG-strategy.js
More file actions
72 lines (58 loc) · 1.92 KB
/
Copy pathTWIG-strategy.js
File metadata and controls
72 lines (58 loc) · 1.92 KB
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
66
67
68
69
70
71
72
// helpers
var _ = require('lodash');
var log = require('../core/log.js');
// configuration
var config = require('../core/util.js').getConfig();
var settings = config.TWIG;
// let's create our own method
var method = {};
// prepare everything our method needs
method.init = function() {
this.name = 'TWIG';
this.currentTrend;
this.requiredHistory = config.tradingAdvisor.historySize;
// define the indicators we need
this.lastPrice=0;
this.addIndicator('twig', 'TWIG', settings);
}
// what happens on every new candle?
method.update = function(candle) {
// nothing!
}
// for debugging purposes: log the last calculated
// EMAs and diff.
method.log = function() {
//var twig = this.indicators.twig;
//
// log.debug('calculated TWIG properties for candle:');
// log.debug('\t', 'long ema:', twig.long.result.toFixed(8));
// log.debug('\t', 'short ema:', twig.short.result.toFixed(8));
// log.debug('\t diff:', twig.result.toFixed(5));
// log.debug('\t TWIG age:', twig.short.age, 'candles');
}
method.check = function() {
var twig = this.indicators.twig;
var diff = twig.result;
//var price = this.lastPrice;
console.log("diff = "+diff);
//var message = '@ ' + price.toFixed(8) + ' (' + diff.toFixed(5) + ')';
if(diff > settings.thresholds.up) {
//log.debug('we are currently in uptrend', message);
if(this.currentTrend !== 'up') {
this.currentTrend = 'up';
this.advice('long');
} else
this.advice();
} else if(diff < settings.thresholds.down) {
//log.debug('we are currently in a downtrend', message);
if(this.currentTrend !== 'down') {
this.currentTrend = 'down';
this.advice('short');
} else
this.advice();
} else {
//log.debug('we are currently not in an up or down trend', message);
this.advice();
}
}
module.exports = method;