-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathlambo_testing.py
338 lines (281 loc) · 11.2 KB
/
lambo_testing.py
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
import numpy as np # noqa
import pandas as pd # noqa
from pandas import DataFrame
from sqlalchemy.orm.base import RELATED_OBJECT_OK
from sqlalchemy.sql.elements import or_
import talib.abstract as ta
import pandas_ta as pta
import freqtrade.vendor.qtpylib.indicators as qtpylib
from freqtrade.exchange import timeframe_to_minutes
from technical import indicators
import logging
from freqtrade.strategy import (BooleanParameter, CategoricalParameter, DecimalParameter, RealParameter,
IStrategy, IntParameter, merge_informative_pair)
class lambotest(IStrategy):
# Add some logging
logger = logging.getLogger(__name__)
# Strategy interface version - allow new iterations of the strategy interface.
# Check the documentation or the Sample strategy to get the latest version.
INTERFACE_VERSION = 2
# Minimal ROI designed for the strategy.
# This attribute will be overridden if the config file contains "minimal_roi".
# ROI table:
minimal_roi = {
"0": 0.0625,
"28": 0.05,
"76": 0.04,
"125": 0.03,
"240": 0.02,
"360": 0
}
# Optimal stoploss designed for the strategy.
# This attribute will be overridden if the config file contains "stoploss".
# use_custom_stoploss = True
stoploss = -0.0625 #-0.10
# Trailing stop:
trailing_stop = False
trailing_stop_positive = 0.0069
trailing_stop_positive_offset = 0.038
trailing_only_offset_is_reached = False
process_only_new_candles = True
# Number of candles the strategy requires before producing valid signals
startup_candle_count: int = 20 #30
# Optimal timeframe for the strategy.
timeframe = '5m'
# These values can be overridden in the "ask_strategy" section in the config.
use_sell_signal = True
sell_profit_only = True
# sell_profit_offset = 0.019
ignore_roi_if_buy_signal = False
# hyperopt params
buy_williams_low = DecimalParameter(-100, -50, default=-58.201)
buy_williams_high = DecimalParameter(-100, -50, default=-92.098)
buy_rsi_low = DecimalParameter(0, 30, default=2.342)
buy_rsi_high = DecimalParameter(30, 60, default=51.22)
buy_volume = DecimalParameter(1000, 100000, default=5000)
sell_rsi = DecimalParameter(60, 100, default=60.631)
sell_williams = DecimalParameter(-40, -10, default=-19.308)
sell_volume = DecimalParameter(1000, 100000, default=1000)
# Optional order type mapping.
order_types = {
'buy': 'limit',
'sell': 'limit',
'stoploss': 'market',
'stoploss_on_exchange': False
}
# Optional order time in force.
order_time_in_force = {
'buy': 'gtc',
'sell': 'gtc'
}
@property
def plot_config(self):
return {
"main_plot": {
"bb.lower": {
"color": "#9c6edc",
"type": "line"
},
"bb.upper": {
"color": "#9c6edc",
"type": "line"
},
"vwma": {
"color": "#4f9f02",
"type": "line"
}
},
"subplots": {
"obv": {
"OBV": {
"color": "#1b61ab",
"type": "line"
},
"OBVSlope": {
"color": "#f18b7a",
"type": "line"
}
},
"vpci": {
"vpci": {
"color": "#d59a7a",
"type": "line"
}
},
"macd": {
"macd": {
"color": "#1c3d6a",
"type": "line"
},
"macdsignal": {
"color": "#873480",
"type": "line"
},
"macdhist": {
"color": "#478a87",
"type": "bar"
}
},
"wiliams": {
"williamspercent": {
"color": "#10f551",
"type": "line"
}
},
"stoch + rsi": {
"rsi": {
"color": "#d7affd",
"type": "line"
},
"slowd": {
"color": "#d7cc5c",
"type": "line"
},
"fastk": {
"color": "#186f86",
"type": "line"
}
},
"adx": {
"adx": {
"color": "#c392cd",
"type": "line"
},
"plus.di": {
"color": "#bcd6c5",
"type": "line"
},
"minus.di": {
"color": "#eb044c",
"type": "line"
}
}
}
}
def informative_pairs(self):
"""
Define additional, informative pair/interval combinations to be cached from the exchange.
These pair/interval combinations are non-tradeable, unless they are part
of the whitelist as well.
For more information, please consult the documentation
:return: List of tuples in the format (pair, interval)
Sample: return [("ETH/USDT", "5m"),
("BTC/USDT", "15m"),
]
"""
pairs = self.dp.current_whitelist()
informative_pairs = [(pair, self.timeframe) for pair in pairs]
return informative_pairs
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
# Retrieve best bid and best ask from the orderbook
# ------------------------------------
# first check if dataprovider is available
if self.dp:
if self.dp.runmode.value in ('live', 'dry_run'):
ob = self.dp.orderbook(metadata['pair'], 1)
dataframe['best_bid'] = ob['bids'][0][0]
dataframe['best_ask'] = ob['asks'][0][0]
# Bollinger!
bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2)
dataframe['bb.lower'] = bollinger['lower']
dataframe['bb.middle'] = bollinger['mid']
dataframe['bb.upper'] = bollinger['upper']
# Added PCB Style OBV
dataframe['OBV'] = ta.OBV(dataframe)
dataframe['OBVSlope'] = pta.momentum.slope(dataframe['OBV'])
# VWMA
# vwma_period = 13
# dataframe['vwma'] = ((dataframe["close"] * dataframe["volume"]).rolling(vwma_period).sum() /
# dataframe['volume'].rolling(vwma_period).sum())
# VWAP
# vwap_period = 20
# dataframe['vwap'] = qtpylib.rolling_vwap(dataframe, window=vwap_period)
# VPCI
dataframe['vpci'] = indicators.vpci(dataframe, period_long=14)
#williamsR
dataframe['williamspercent'] = indicators.williams_percent(dataframe)
# ADX
dataframe['adx'] = ta.ADX(dataframe)
dataframe['plus.di'] = ta.PLUS_DI(dataframe)
dataframe['minus.di'] = ta.MINUS_DI(dataframe)
# RSI
dataframe['rsi'] = ta.RSI(dataframe)
# MACD
macd = ta.MACD(dataframe)
dataframe['macd'] = macd['macd']
dataframe['macdsignal'] = macd['macdsignal']
dataframe['macdhist'] = macd['macdhist']
# Stochastic Fast
stoch_fast = ta.STOCHF(dataframe)
dataframe['fastd'] = stoch_fast['fastd']
dataframe['fastk'] = stoch_fast['fastk']
# Stochastic Slow
stoch_slow = ta.STOCH(dataframe)
dataframe['slowd'] = stoch_slow['slowd']
dataframe['slowk'] = stoch_slow['slowd']
return dataframe
def do_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
# Bollinger!
bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2)
dataframe['bb.lower'] = bollinger['lower']
dataframe['bb.middle'] = bollinger['mid']
dataframe['bb.upper'] = bollinger['upper']
# Added PCB Style OBV
dataframe['OBV'] = ta.OBV(dataframe)
dataframe['OBVSlope'] = pta.momentum.slope(dataframe['OBV'])
# VWMA
# vwma_period = 13
# dataframe['vwma'] = ((dataframe["close"] * dataframe["volume"]).rolling(vwma_period).sum() /
# dataframe['volume'].rolling(vwma_period).sum())
# VPCI
dataframe['vpci'] = indicators.vpci(dataframe, period_long=14)
#williamsR
dataframe['williamspercent'] = indicators.williams_percent(dataframe)
# ADX
dataframe['adx'] = ta.ADX(dataframe)
dataframe['plus.di'] = ta.PLUS_DI(dataframe)
dataframe['minus.di'] = ta.MINUS_DI(dataframe)
# RSI
dataframe['rsi'] = ta.RSI(dataframe)
# MACD
macd = ta.MACD(dataframe)
dataframe['macd'] = macd['macd']
dataframe['macdsignal'] = macd['macdsignal']
dataframe['macdhist'] = macd['macdhist']
# Stochastic Fast
stoch_fast = ta.STOCHF(dataframe)
dataframe['fastd'] = stoch_fast['fastd']
dataframe['fastk'] = stoch_fast['fastk']
# Stochastic Slow
stoch_slow = ta.STOCH(dataframe)
dataframe['slowd'] = stoch_slow['slowd']
dataframe['slowk'] = stoch_slow['slowd']
return dataframe
def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
dataframe.loc[
(
(dataframe['volume'] > self.buy_volume.value) &
(dataframe['OBVSlope'] > 0) &
(dataframe['williamspercent'] <= self.buy_williams_low.value) &
(dataframe['williamspercent'] > self.buy_williams_high.value) &
(dataframe['rsi'] > self.buy_rsi_low.value) &
(dataframe['rsi'] <= self.buy_rsi_high.value) &
(qtpylib.crossed_above(dataframe['fastk'], dataframe['slowd'])) &
(dataframe['close'] < dataframe['bb.middle'])
),'buy'] = 1
return dataframe
def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
dataframe.loc[
(
(dataframe['volume'] > self.sell_volume.value) &
(dataframe['williamspercent'] > self.sell_williams.value) &
(dataframe['rsi'] > self.sell_rsi.value) |
(qtpylib.crossed_below(dataframe['plus.di'], dataframe['minus.di'])) |
(qtpylib.crossed_below(dataframe['macd'], dataframe['macdsignal'])) |
(qtpylib.crossed_below(dataframe['fastk'], dataframe['slowd'])) &
(dataframe['close'] > dataframe['bb.upper']) |
(dataframe['vpci'] >= dataframe['bb.upper'])
),
'sell'] = 1
return dataframe
# "All watched over by machines with loving grace..."