forked from AImeta-pro/crypto-trading-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnoop.js
More file actions
167 lines (145 loc) · 4.23 KB
/
noop.js
File metadata and controls
167 lines (145 loc) · 4.23 KB
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
const { SD } = require('technicalindicators');
const TA = require('../../../utils/technical_analysis');
const SignalResult = require('../dict/signal_result');
module.exports = class {
getName() {
return 'noop';
}
buildIndicator(indicatorBuilder, options) {
indicatorBuilder.add('bb', 'bb', '15m');
indicatorBuilder.add('rsi', 'rsi', '15m');
indicatorBuilder.add('mfi', 'mfi', '15m');
indicatorBuilder.add('volume_profile', 'volume_profile', '15m');
indicatorBuilder.add('zigzag', 'zigzag', '15m');
indicatorBuilder.add('pivot_points_high_low', 'pivot_points_high_low', '15m', {
left: 14,
right: 14
});
indicatorBuilder.add('sma200', 'sma', '15m', {
length: 200
});
indicatorBuilder.add('sma50', 'sma', '15m', {
length: 50
});
indicatorBuilder.add('foreign_candle', 'candles', options.foreign_pair_period || '15m', {
exchange: options.foreign_pair_exchange || 'binance',
symbol: options.foreign_pair_symbol || 'BTCUSDT'
});
}
async period(indicatorPeriod, options) {
const currentValues = indicatorPeriod.getLatestIndicators();
const bollinger = indicatorPeriod.getIndicator('bb');
if (bollinger && currentValues.bb) {
const standardDeviation = SD.calculate({
period: 150,
values: bollinger.slice(-200).map(b => b.width)
});
currentValues.bb.sd = standardDeviation.slice(-1)[0];
}
const currentBB = indicatorPeriod.getLatestIndicator('bb');
if (currentBB && currentValues.bb) {
currentValues.bb.percent = TA.getBollingerBandPercent(
indicatorPeriod.getPrice(),
currentBB.upper,
currentBB.lower
);
}
const intl = new Intl.NumberFormat('en-US', { minimumSignificantDigits: 3, maximumSignificantDigits: 4 });
currentValues.ranges = (indicatorPeriod.getIndicator('volume_profile') || [])
.sort((a, b) => b.totalVolume - a.totalVolume)
.slice(0, 3)
.map(v => `${intl.format(v.rangeStart)}-${intl.format(v.rangeEnd)}`)
.join(', ');
const emptySignal = SignalResult.createEmptySignal(currentValues);
// entry or exit
if (!indicatorPeriod.getLastSignal()) {
const dice = parseFloat(options.dice || 6);
const diceSize = parseFloat(options.dice_size || 12);
const number = Math.floor(Math.random() * diceSize) + 1;
emptySignal.addDebug('message', `${number}`);
if (number === dice) {
const longOrShort = Math.random() > 0.5 ? 'long' : 'short';
emptySignal.setSignal(longOrShort);
}
}
// close on profit or lose
if (indicatorPeriod.getLastSignal()) {
if (indicatorPeriod.getProfit() > 2) {
// take profit
emptySignal.addDebug('message', 'TP');
emptySignal.setSignal('close');
} else if (indicatorPeriod.getProfit() < -2) {
// stop loss
emptySignal.addDebug('message', 'SL');
emptySignal.setSignal('close');
}
}
return emptySignal;
}
getBacktestColumns() {
return [
{
label: 'BollDev',
value: 'bb.width',
type: 'cross',
cross: 'bb.sd'
},
{
label: 'BollPct',
value: 'bb.percent',
type: 'oscillator',
range: [1, 0]
},
{
label: 'rsi',
value: 'rsi',
type: 'oscillator'
},
{
label: 'mfi',
value: 'mfi',
type: 'oscillator'
},
{
label: 'SMA 50/200',
value: 'sma50',
type: 'cross',
cross: 'sma200'
},
{
label: 'Pivot Points',
value: 'pivot_points_high_low'
},
{
label: 'Foreign',
value: 'foreign_candle.close'
},
{
label: 'Top Volume Ranges',
value: 'ranges'
},
{
label: 'dice',
value: 'message'
},
{
label: 'zigzag',
value: row => (row.zigzag && row.zigzag.turningPoint === true ? 'warning' : undefined),
type: 'icon'
}
];
}
getOptions() {
return {
period: '15m',
dice: 6,
dice_size: 12,
foreign_pair_exchange: 'binance',
foreign_pair_symbol: 'BTCUSDT',
foreign_pair_period: '15m'
};
}
getTickPeriod() {
return '1m';
}
};