Elffuss BraidHub

kikocis/freqtrade public

develop · 5.2 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.interface import IStrategy
8
9
10class DefaultStrategy(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 timeframe 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 def informative_pairs(self):
52 """
53 Define additional, informative pair/interval combinations to be cached from the exchange.
54 These pair/interval combinations are non-tradeable, unless they are part
55 of the whitelist as well.
56 For more information, please consult the documentation
57 :return: List of tuples in the format (pair, interval)
58 Sample: return [("ETH/USDT", "5m"),
59 ("BTC/USDT", "15m"),
60 ]
61 """
62 return []
63
64 def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
65 """
66 Adds several different TA indicators to the given DataFrame
67
68 Performance Note: For the best performance be frugal on the number of indicators
69 you are using. Let uncomment only the indicator you are using in your strategies
70 or your hyperopt configuration, otherwise you will waste your memory and CPU usage.
71 :param dataframe: Dataframe with data from the exchange
72 :param metadata: Additional information, like the currently traded pair
73 :return: a Dataframe with all mandatory indicators for the strategies
74 """
75
76 # Momentum Indicator
77 # ------------------------------------
78
79 # ADX
80 dataframe['adx'] = ta.ADX(dataframe)
81
82 # MACD
83 macd = ta.MACD(dataframe)
84 dataframe['macd'] = macd['macd']
85 dataframe['macdsignal'] = macd['macdsignal']
86 dataframe['macdhist'] = macd['macdhist']
87
88 # Minus Directional Indicator / Movement
89 dataframe['minus_di'] = ta.MINUS_DI(dataframe)
90
91 # Plus Directional Indicator / Movement
92 dataframe['plus_di'] = ta.PLUS_DI(dataframe)
93
94 # RSI
95 dataframe['rsi'] = ta.RSI(dataframe)
96
97 # Stoch fast
98 stoch_fast = ta.STOCHF(dataframe)
99 dataframe['fastd'] = stoch_fast['fastd']
100 dataframe['fastk'] = stoch_fast['fastk']
101
102 # Bollinger bands
103 bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2)
104 dataframe['bb_lowerband'] = bollinger['lower']
105 dataframe['bb_middleband'] = bollinger['mid']
106 dataframe['bb_upperband'] = bollinger['upper']
107
108 # EMA - Exponential Moving Average
109 dataframe['ema10'] = ta.EMA(dataframe, timeperiod=10)
110
111 return dataframe
112
113 def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
114 """
115 Based on TA indicators, populates the buy signal for the given dataframe
116 :param dataframe: DataFrame
117 :param metadata: Additional information, like the currently traded pair
118 :return: DataFrame with buy column
119 """
120 dataframe.loc[
121 (
122 (dataframe['rsi'] < 35) &
123 (dataframe['fastd'] < 35) &
124 (dataframe['adx'] > 30) &
125 (dataframe['plus_di'] > 0.5)
126 ) |
127 (
128 (dataframe['adx'] > 65) &
129 (dataframe['plus_di'] > 0.5)
130 ),
131 'buy'] = 1
132
133 return dataframe
134
135 def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
136 """
137 Based on TA indicators, populates the sell signal for the given dataframe
138 :param dataframe: DataFrame
139 :param metadata: Additional information, like the currently traded pair
140 :return: DataFrame with buy column
141 """
142 dataframe.loc[
143 (
144 (
145 (qtpylib.crossed_above(dataframe['rsi'], 70)) |
146 (qtpylib.crossed_above(dataframe['fastd'], 70))
147 ) &
148 (dataframe['adx'] > 10) &
149 (dataframe['minus_di'] > 0)
150 ) |
151 (
152 (dataframe['adx'] > 70) &
153 (dataframe['minus_di'] > 0.5)
154 ),
155 'sell'] = 1
156 return dataframe