forked from Haehnchen/crypto-trading-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobv_pump_dump.js
76 lines (56 loc) · 1.82 KB
/
obv_pump_dump.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
const SignalResult = require('../dict/signal_result');
module.exports = class {
getName() {
return 'obv_pump_dump';
}
buildIndicator(indicatorBuilder, options) {
indicatorBuilder.add('obv', 'obv', '1m');
indicatorBuilder.add('ema', 'ema', '1m', {
length: 200
});
}
async period(indicatorPeriod, options) {
const triggerMultiplier = options.trigger_multiplier || 2;
const triggerTimeWindows = options.trigger_time_windows || 3;
const obv = indicatorPeriod.getIndicator('obv');
if (!obv || obv.length <= 20) {
return;
}
const price = indicatorPeriod.getPrice();
const ema = indicatorPeriod.getIndicator('ema').slice(-1)[0];
const debug = {
obv: obv.slice(-1)[0],
ema: ema
};
if (price > ema) {
// long
debug.trend = 'up';
const before = obv.slice(-20, triggerTimeWindows * -1);
const highest = before.sort((a, b) => b - a).slice(0, triggerTimeWindows);
const highestOverage = highest.reduce((a, b) => a + b, 0) / highest.length;
const current = obv.slice(triggerTimeWindows * -1);
const currentAverage = current.reduce((a, b) => a + b, 0) / current.length;
debug.highest_overage = highestOverage;
debug.current_average = currentAverage;
if (currentAverage < highestOverage) {
return SignalResult.createEmptySignal(debug);
}
const difference = Math.abs(currentAverage / highestOverage);
debug.difference = difference;
if (difference >= triggerMultiplier) {
return SignalResult.createSignal('long', debug);
}
} else {
// short
debug.trend = 'down';
}
return SignalResult.createEmptySignal(debug);
}
getOptions() {
return {
period: '15m',
trigger_multiplier: 2,
trigger_time_windows: 3
};
}
};