forked from Haehnchen/crypto-trading-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trader.js
128 lines (110 loc) · 2.86 KB
/
trader.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
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
const { SD } = require('technicalindicators');
const { SMA } = require('technicalindicators');
const { Lowest } = require('technicalindicators');
const { isTrendingUp } = require('technicalindicators');
const { isTrendingDown } = require('technicalindicators');
const SignalResult = require('../dict/signal_result');
const TA = require('../../../utils/technical_analysis');
const TechnicalPattern = require('../../../utils/technical_pattern');
const resample = require('../../../utils/resample');
const TechnicalAnalysis = require('../../../utils/technical_analysis');
module.exports = class {
getName() {
return 'trader';
}
buildIndicator(indicatorBuilder, options) {
indicatorBuilder.add('candles_1m', 'candles', '1m');
indicatorBuilder.add('bb', 'bb', '15m', {
length: 40
});
}
async period(indicatorPeriod, options) {
const currentValues = indicatorPeriod.getLatestIndicators();
const result = SignalResult.createEmptySignal(currentValues);
const candles1m = indicatorPeriod.getIndicator('candles_1m');
if (!candles1m) {
return result;
}
const candles3m = resample.resampleMinutes(candles1m.slice().reverse(), '3');
const foo = TechnicalAnalysis.getPivotPoints(
candles1m.slice(-10).map(c => c.close),
3,
3
);
const bb = indicatorPeriod.getLatestIndicator('bb');
const lastCandle = candles1m.slice(-1)[0];
result.addDebug('price2', lastCandle.close);
if (bb && lastCandle && lastCandle.close > bb.upper) {
result.addDebug('v', 'success');
const bb = indicatorPeriod.getIndicator('bb');
const values = bb
.slice(-10)
.reverse()
.map(b => b.width);
const value = Math.min(...values);
if (currentValues.bb.width < 0.05) {
result.addDebug('x', currentValues.bb.width);
result.setSignal('long');
}
}
result.addDebug('pivot', foo);
result.mergeDebug(TechnicalPattern.volumePump(candles3m.slice().reverse() || []));
return result;
}
getBacktestColumns() {
return [
{
label: 'price2',
value: 'price2'
},
{
label: 'RSI',
value: 'rsi'
},
{
label: 'roc',
value: 'roc_1m'
},
{
label: 'roc_ma',
value: 'roc_ma',
type: 'icon'
},
{
label: 'Vol',
value: 'candles_1m.volume'
},
{
label: 'VolSd',
value: 'volume_sd'
},
{
label: 'VolV',
value: 'volume_v'
},
{
label: 'hint',
value: 'hint',
type: 'icon'
},
{
label: 'v',
value: 'v',
type: 'icon'
},
{
label: 'x',
value: 'x'
},
{
label: 'pivot',
value: 'pivot'
}
];
}
getOptions() {
return {
period: '15m'
};
}
};