Elffuss BraidHub

kikocis/freqtrade public

develop · 5.9 KiBRawPermalink
1# pragma pylint: disable=missing-docstring, invalid-name, pointless-string-statement
2
3import talib.abstract as ta
4from pandas import DataFrame
5
6import freqtrade.vendor.qtpylib.indicators as qtpylib
7from freqtrade.strategy import DecimalParameter, IntParameter, IStrategy, RealParameter
8
9
10class HyperoptableStrategy(IStrategy):
11 """
12 Default Strategy provided by freqtrade bot.
13 Please do not modify this strategy, it's intended for internal use only.
14 Please look at the SampleStrategy in the user_data/strategy directory
15 or strategy repository https://github.com/freqtrade/freqtrade-strategies
16 for samples and inspiration.
17 """
18 INTERFACE_VERSION = 2
19
20 # Minimal ROI designed for the strategy
21 minimal_roi = {
22 "40": 0.0,
23 "30": 0.01,
24 "20": 0.02,
25 "0": 0.04
26 }
27
28 # Optimal stoploss designed for the strategy
29 stoploss = -0.10
30
31 # Optimal ticker interval for the strategy
32 timeframe = '5m'
33
34 # Optional order type mapping
35 order_types = {
36 'buy': 'limit',
37 'sell': 'limit',
38 'stoploss': 'limit',
39 'stoploss_on_exchange': False
40 }
41
42 # Number of candles the strategy requires before producing valid signals
43 startup_candle_count: int = 20
44
45 # Optional time in force for orders
46 order_time_in_force = {
47 'buy': 'gtc',
48 'sell': 'gtc',
49 }
50
51 buy_params = {
52 'buy_rsi': 35,
53 # Intentionally not specified, so "default" is tested
54 # 'buy_plusdi': 0.4
55 }
56
57 sell_params = {
58 'sell_rsi': 74,
59 'sell_minusdi': 0.4
60 }
61
62 buy_rsi = IntParameter([0, 50], default=30, space='buy')
63 buy_plusdi = RealParameter(low=0, high=1, default=0.5, space='buy')
64 sell_rsi = IntParameter(low=50, high=100, default=70, space='sell')
65 sell_minusdi = DecimalParameter(low=0, high=1, default=0.5001, decimals=3, space='sell',
66 load=False)
67
68 def informative_pairs(self):
69 """
70 Define additional, informative pair/interval combinations to be cached from the exchange.
71 These pair/interval combinations are non-tradeable, unless they are part
72 of the whitelist as well.
73 For more information, please consult the documentation
74 :return: List of tuples in the format (pair, interval)
75 Sample: return [("ETH/USDT", "5m"),
76 ("BTC/USDT", "15m"),
77 ]
78 """
79 return []
80
81 def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
82 """
83 Adds several different TA indicators to the given DataFrame
84
85 Performance Note: For the best performance be frugal on the number of indicators
86 you are using. Let uncomment only the indicator you are using in your strategies
87 or your hyperopt configuration, otherwise you will waste your memory and CPU usage.
88 :param dataframe: Dataframe with data from the exchange
89 :param metadata: Additional information, like the currently traded pair
90 :return: a Dataframe with all mandatory indicators for the strategies
91 """
92
93 # Momentum Indicator
94 # ------------------------------------
95
96 # ADX
97 dataframe['adx'] = ta.ADX(dataframe)
98
99 # MACD
100 macd = ta.MACD(dataframe)
101 dataframe['macd'] = macd['macd']
102 dataframe['macdsignal'] = macd['macdsignal']
103 dataframe['macdhist'] = macd['macdhist']
104
105 # Minus Directional Indicator / Movement
106 dataframe['minus_di'] = ta.MINUS_DI(dataframe)
107
108 # Plus Directional Indicator / Movement
109 dataframe['plus_di'] = ta.PLUS_DI(dataframe)
110
111 # RSI
112 dataframe['rsi'] = ta.RSI(dataframe)
113
114 # Stoch fast
115 stoch_fast = ta.STOCHF(dataframe)
116 dataframe['fastd'] = stoch_fast['fastd']
117 dataframe['fastk'] = stoch_fast['fastk']
118
119 # Bollinger bands
120 bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2)
121 dataframe['bb_lowerband'] = bollinger['lower']
122 dataframe['bb_middleband'] = bollinger['mid']
123 dataframe['bb_upperband'] = bollinger['upper']
124
125 # EMA - Exponential Moving Average
126 dataframe['ema10'] = ta.EMA(dataframe, timeperiod=10)
127
128 return dataframe
129
130 def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
131 """
132 Based on TA indicators, populates the buy signal for the given dataframe
133 :param dataframe: DataFrame
134 :param metadata: Additional information, like the currently traded pair
135 :return: DataFrame with buy column
136 """
137 dataframe.loc[
138 (
139 (dataframe['rsi'] < self.buy_rsi.value) &
140 (dataframe['fastd'] < 35) &
141 (dataframe['adx'] > 30) &
142 (dataframe['plus_di'] > self.buy_plusdi.value)
143 ) |
144 (
145 (dataframe['adx'] > 65) &
146 (dataframe['plus_di'] > self.buy_plusdi.value)
147 ),
148 'buy'] = 1
149
150 return dataframe
151
152 def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
153 """
154 Based on TA indicators, populates the sell signal for the given dataframe
155 :param dataframe: DataFrame
156 :param metadata: Additional information, like the currently traded pair
157 :return: DataFrame with buy column
158 """
159 dataframe.loc[
160 (
161 (
162 (qtpylib.crossed_above(dataframe['rsi'], self.sell_rsi.value)) |
163 (qtpylib.crossed_above(dataframe['fastd'], 70))
164 ) &
165 (dataframe['adx'] > 10) &
166 (dataframe['minus_di'] > 0)
167 ) |
168 (
169 (dataframe['adx'] > 70) &
170 (dataframe['minus_di'] > self.sell_minusdi.value)
171 ),
172 'sell'] = 1
173 return dataframe