-
Notifications
You must be signed in to change notification settings - Fork 1
/
fd_pull_back.js
83 lines (67 loc) · 2.83 KB
/
fd_pull_back.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
var _ = require('lodash');
var log = require('../core/log.js');
var strat = {};
strat.init = function() {
this.name = "pull back with or without trend";
this.stopLoss = 0;
this.highClose = 0;
this.lowClose = 0;
this.advised = 0; // 1 => long advised; -1 => short advised
this.requiredHistory = this.settings.ltLongPeriod;
this.addTalibIndicator('stShort', 'ema', { optInTimePeriod: this.settings.stShortPeriod });
this.addTalibIndicator('stLong', 'ema', { optInTimePeriod: this.settings.stLongPeriod });
this.addTalibIndicator('ltShort', 'ema', { optInTimePeriod: this.settings.ltShortPeriod });
this.addTalibIndicator('ltLong', 'ema', { optInTimePeriod: this.settings.ltLongPeriod });
this.addTalibIndicator('tsAtr', 'atr', { optInTimePeriod: this.settings.tsAtrPeriod });
}
strat.update = function(candle) {
}
strat.log = function() {
}
strat.check = function(candle) {
const stShort = this.talibIndicators.stShort.result.outReal;
const stLong = this.talibIndicators.stLong.result.outReal;
const ltShort = this.talibIndicators.stShort.result.outReal;
const ltLong = this.talibIndicators.ltLong.result.outReal;
const tsAtr = this.talibIndicators.tsAtr.result.outReal;
const ltUptrend = ltShort > ltLong;
const ltDowntrend = ! ltUptrend;
const stUptrend = stShort > stLong;
const stDowntrend = ! stUptrend;
///////ENTRIES////////
if ( ltUptrend && stDowntrend) {
this.advice('long');
this.advised = 1;
this.highClose = candle.close;
} else if ( ltDowntrend && stUptrend) {
this.advice('short');
this.advised = -1;
this.lowClose = candle.close;
}
////END OF ENTRIES////
////////EXITS////////
if ( this.advised == 1 ) {
if ( candle.close > this.highClose ) {
this.highClose = candle.close;
}
this.stopLoss = this.highClose - this.settings.nbAtrStop * tsAtr;
if (candle.close <= this.stopLoss) {
this.advice('short');
this.advised = 0;
this.stopLoss = 0;
}
} else if (this.advised == -1) {
if ( candle.close < this.lowClose ) {
this.lowClose = candle.close;
}
this.stopLoss = this.lowClose + this.settings.nbAtrStop * tsAtr;
if (candle.close >= this.stopLoss) {
this.advice('long');
this.advised = 0;
this.stopLoss = 0;
}
}
}
strat.end = function() {
}
module.exports = strat;