-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathBBRSIv2.py
More file actions
165 lines (124 loc) · 5.4 KB
/
BBRSIv2.py
File metadata and controls
165 lines (124 loc) · 5.4 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
# --- Do not remove these libs ---
from freqtrade.strategy.interface import IStrategy
from pandas import DataFrame
import talib.abstract as ta
import freqtrade.vendor.qtpylib.indicators as qtpylib
# --------------------------------
from freqtrade.persistence import Trade
from datetime import datetime, timedelta
from functools import reduce
#
class BBRSIv2(IStrategy):
"""
author@: Gert Wohlgemuth
converted from:
https://github.com/sthewissen/Mynt/blob/master/src/Mynt.Core/Strategies/BbandRsi.cs
Customized by StrongManBR
"""
# Minimal ROI designed for the strategy.
# adjust based on market conditions. We would recommend to keep it low for quick turn arounds
# This attribute will be overridden if the config file contains "minimal_roi"
minimal_roi = {
"0": 0.3
}
# Optimal stoploss designed for the strategy
stoploss = -0.99
process_only_new_candles = True
use_sell_signal = True
sell_profit_only = True
sell_profit_offset= 0.01
ignore_roi_if_buy_signal = False
use_custom_stoploss = True
startup_candle_count: int = 144
# Optimal timeframe for the strategy
timeframe = '15m'
plot_config = {
'main_plot': {
'bb_lowerband': {},
'bb_middleband': {},
'bb_upperband': {},
'tema': {}
},
'subplots': {
"RSI": {
'rsi': {'color': 'blue'}
},
"MARKET": {
'close_max': {'color': 'green', 'type': 'bar'},
'close_min': {'color': 'red','type': 'bar'},
'dropped_by_percent': {'color': 'blue','type': 'bar'},
'pumped_by_percent': {'color': 'orange','type': 'bar'}
}
}
}
def custom_stoploss(self, pair: str, trade: 'Trade', current_time: datetime,
current_rate: float, current_profit: float, **kwargs) -> float:
sl_new = 1
if self.config['runmode'].value in ('live', 'dry_run'):
sl_new = 0.001
if (current_profit > 0.2):
sl_new = 0.05
elif (current_profit > 0.1):
sl_new = 0.03
elif (current_profit > 0.06):
sl_new = 0.02
elif (current_profit > 0.03):
sl_new = 0.01
return sl_new
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)
# Bollinger bands
bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2)
dataframe['bb_lowerband'] = bollinger['lower']
dataframe['bb_middleband'] = bollinger['mid']
dataframe['bb_upperband'] = bollinger['upper']
# Custom
# TEMA - Triple Exponential Moving Average
dataframe["tema"] = ta.TEMA(dataframe, timeperiod=9, price="close")
dataframe['close_max'] = dataframe['close'].rolling(window=60).max() #5h
dataframe['dropped_by_percent'] = (1 - (dataframe['close'] / dataframe['close_max']))
dataframe['close_min'] = dataframe['close'].rolling(window=60).min() #5h
dataframe['pumped_by_percent'] = (dataframe['high'] - dataframe['close_min'])/ dataframe['high']
return dataframe
def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
dataframe.loc[:, 'buy_tag'] = ''
conditions = []
# dont_buy_conditions = []
RB1 = (
(qtpylib.crossed_above(dataframe['rsi'], 35)) & # Signal: RSI crosses above 35
(dataframe['close'] < dataframe['bb_lowerband'])
)
dataframe.loc[RB1, 'buy_tag'] += 'RB1:BB_LOWER '
conditions.append(RB1)
RB2 = (
(dataframe['rsi'] < 23) &
(dataframe["tema"] < dataframe["bb_lowerband"]) &
(dataframe["tema"] > dataframe["tema"].shift(1)) &
(dataframe["volume"] > 0) # Make sure Volume is not 0
)
dataframe.loc[RB2, 'buy_tag'] += 'RB2:RSI<23_ '
conditions.append(RB2)
if conditions:
dataframe.loc[
#is_bull &
#is_additional_check &
#can_buy &
#is_live_data &
reduce(lambda x, y: x | y, conditions),'buy'] = 1
return dataframe
def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
conditions = []
dataframe.loc[:, 'exit_tag'] = ''
#sell_now = []
RS1 = ( dataframe['rsi'] >70 )
dataframe.loc[RS1, 'exit_tag'] += 'RS1:RSI>70 '
conditions.append(RS1)
RS2 = ( dataframe["high"] > dataframe["close_max"])
dataframe.loc[RS2, 'exit_tag'] += 'RS2:>CLOSE_MAX '
conditions.append(RS2)
if conditions:
dataframe.loc[
#can_sell &
#is_live_data &
reduce(lambda x, y: x | y, conditions),'sell'] = 1
return dataframe