-
Notifications
You must be signed in to change notification settings - Fork 21
/
Fibonacci Trendlines.js
86 lines (63 loc) · 2.42 KB
/
Fibonacci Trendlines.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
Fibonacci Trendlines - Crypto49er 2018-04-24
This strategy uses the golden cross of the Fibonacci Trendlines (8 EMA and 21 EMA cross
over the 55 EMA) and as a buy signal. It will sell if the 21 cross below the 55 EMA.
*/
// helpers
var _ = require('lodash');
var log = require('../core/log.js');
var buyPrice = 0.0;
var advised = false;
// let's create our own method
var method = {};
// prepare everything our method needs
method.init = function() {
this.name = 'Fibonacci Trendlines';
this.currentTrend;
this.requiredHistory = this.settings.longSize;
log.debug("Short EMA size: "+this.settings.shortSize);
log.debug("Long EMA size: "+this.settings.longSize);
this.addTalibIndicator('shortEMA', 'ema', {optInTimePeriod : this.settings.shortSize});
this.addTalibIndicator('mediumEMA', 'ema', {optInTimePeriod : this.settings.mediumSize});
this.addTalibIndicator('longEMA', 'ema', {optInTimePeriod : this.settings.longSize});
log.debug(this.name+' Strategy initialized');
}
// what happens on every new candle?
method.update = function(candle) {
// nothing!
}
// for debugging purposes: log the last calculated
// EMAs and diff.
method.log = function() {
}
method.check = function(candle) {
var shortResult = this.talibIndicators.shortEMA.result.outReal;
var mediumResult = this.talibIndicators.mediumEMA.result.outReal;
var longResult = this.talibIndicators.longEMA.result.outReal;
var currentPrice = candle.close;
if(shortResult > mediumResult && mediumResult > longResult && !advised){
// Display close price in terminal
log.debug('____________________________________');
log.debug('candle time', candle.start);
log.debug('candle close price:', candle.close);
log.debug("Buying in at", currentPrice);
log.debug('shortEMA:', shortResult);
log.debug('longEMA:', longResult);
buyPrice = candle.close;
advised = true;
this.advice('long');
}
if(advised && mediumResult < longResult){
// Display close price in terminal
log.debug('____________________________________');
log.debug('candle time', candle.start);
log.debug('candle close price:', candle.close);
log.debug("Selling at", currentPrice);
log.debug('shortEMA:', shortResult);
log.debug('longEMA:', longResult);
advised = false;
buyPrice = 0;
this.advice('short');
}
}
module.exports = method;