-
Notifications
You must be signed in to change notification settings - Fork 1
/
2xRsi.txt
187 lines (141 loc) · 4.16 KB
/
2xRsi.txt
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
RSI - cykedev 14/02/2014
(updated a couple of times since, check git history)
*/
// helpers
var _ = require('lodash');
var log = require('../core/log.js');
var RSI = require('./indicators/RSI.js');
// let's create our own method
var method = {};
var fatherOnLowPoint = false;
// prepare everything our method needs
method.init = function ()
{
this.name = 'RSI';
this.trend = {
direction: 'none',
duration: 0,
persisted: false,
adviced: false
};
this.trendFather = {
direction: 'none',
duration: 0,
persisted: false,
adviced: false
};
this.requiredHistory = this.tradingAdvisor.historySize;
// define the indicators we need
this.addIndicator('rsi', 'RSI', this.settings);
this.addIndicator('rsiFather', 'RSI', { interval: this.settings.interval + 5 , low: this.settings.low + 3, high: this.settings.high-5 });
}
// for debugging purposes log the last
// calculated parameters.
method.log = function (candle)
{
var digits = 8;
var rsi = this.indicators.rsi;
log.debug('calculated RSI properties for candle:');
log.debug('\t', 'rsi:', rsi.result.toFixed(digits));
log.debug('\t', 'price:', candle.close.toFixed(digits));
}
method.check = function ()
{
var rsi = this.indicators.rsi;
var rsiFather = this.indicators.rsiFather;
var rsiVal = rsi.result;
var rsiValFather = rsiFather.result;
//RSI FATHER MAIN ----------------
if (rsiValFather > this.settings.thresholds.high)
{
// new trend detected
if (this.trendFather.direction !== 'high')
this.trendFather = {
duration: 0,
persisted: false,
direction: 'high',
adviced: false
};
this.trendFather.duration++;
log.debug('FATHER ...> high since', this.trendFather.duration, 'candle(s)');
if (this.trendFather.duration >= this.settings.thresholds.persistence)
this.trendFather.persisted = true;
if (this.trendFather.persisted && !this.trendFather.adviced)
{
this.trendFather.adviced = true;
this.fatherOnLowPoint = true;
}
} else if (rsiValFather < this.settings.thresholds.low)
{
// new trend detected
if (this.trendFather.direction !== 'low')
this.trendFather = {
duration: 0,
persisted: false,
direction: 'low',
adviced: false
};
this.trendFather.duration++;
log.debug('FATHER ---> IN low since', this.trendFather.duration, 'candle(s)');
if (this.trendFather.duration >= this.settings.thresholds.persistence)
this.trendFather.persisted = true;
if (this.trendFather.persisted && !this.trendFather.adviced)
{
this.trendFather.adviced = true;
this.fatherOnLowPoint = false;
}
} else
{
log.debug('In no trend');
}
//RSI MAIN ----------------
if (rsiVal > this.settings.thresholds.high)
{
// new trend detected
if (this.trend.direction !== 'high')
this.trend = {
duration: 0,
persisted: false,
direction: 'high',
adviced: false
};
this.trend.duration++;
log.debug('In high since', this.trend.duration, 'candle(s)');
if (this.trend.duration >= this.settings.thresholds.persistence)
this.trend.persisted = true;
if (this.trend.persisted && !this.trend.adviced && this.trendFather.direction === 'high' )
{
this.trend.adviced = true;
this.advice('short');
log.debug('SELL AT ---------->');
} else
this.advice();
} else if (rsiVal < this.settings.thresholds.low)
{
// new trend detected
if (this.trend.direction !== 'low')
this.trend = {
duration: 0,
persisted: false,
direction: 'low',
adviced: false
};
this.trend.duration++;
log.debug('In low since', this.trend.duration, 'candle(s)');
if (this.trend.duration >= this.settings.thresholds.persistence)
this.trend.persisted = true;
if (this.trend.persisted && !this.trend.adviced && this.trendFather.direction === 'low' )
{
this.trend.adviced = true;
this.advice('long');
log.debug('BUY AT ---------->');
} else
this.advice();
} else
{
log.debug('In no trend');
this.advice();
}
}
module.exports = method;