| 1 | |
| 2 | # --- Do not remove these libs --- |
| 3 | # Add your lib to import here |
| 4 | import talib.abstract as ta |
| 5 | from pandas import DataFrame |
| 6 | |
| 7 | from freqtrade.strategy.interface import IStrategy |
| 8 | |
| 9 | |
| 10 | # -------------------------------- |
| 11 | |
| 12 | # This class is a sample. Feel free to customize it. |
| 13 | class TestStrategyLegacy(IStrategy): |
| 14 | """ |
| 15 | This is a test strategy using the legacy function headers, which will be |
| 16 | removed in a future update. |
| 17 | Please do not use this as a template, but refer to user_data/strategy/sample_strategy.py |
| 18 | for a uptodate version of this template. |
| 19 | """ |
| 20 | |
| 21 | # Minimal ROI designed for the strategy. |
| 22 | # This attribute will be overridden if the config file contains "minimal_roi" |
| 23 | minimal_roi = { |
| 24 | "40": 0.0, |
| 25 | "30": 0.01, |
| 26 | "20": 0.02, |
| 27 | "0": 0.04 |
| 28 | } |
| 29 | |
| 30 | # Optimal stoploss designed for the strategy |
| 31 | # This attribute will be overridden if the config file contains "stoploss" |
| 32 | stoploss = -0.10 |
| 33 | |
| 34 | # Optimal timeframe for the strategy |
| 35 | # Keep the legacy value here to test compatibility |
| 36 | ticker_interval = '5m' |
| 37 | |
| 38 | def populate_indicators(self, dataframe: DataFrame) -> DataFrame: |
| 39 | """ |
| 40 | Adds several different TA indicators to the given DataFrame |
| 41 | |
| 42 | Performance Note: For the best performance be frugal on the number of indicators |
| 43 | you are using. Let uncomment only the indicator you are using in your strategies |
| 44 | or your hyperopt configuration, otherwise you will waste your memory and CPU usage. |
| 45 | """ |
| 46 | |
| 47 | # Momentum Indicator |
| 48 | # ------------------------------------ |
| 49 | |
| 50 | # ADX |
| 51 | dataframe['adx'] = ta.ADX(dataframe) |
| 52 | |
| 53 | # TEMA - Triple Exponential Moving Average |
| 54 | dataframe['tema'] = ta.TEMA(dataframe, timeperiod=9) |
| 55 | |
| 56 | return dataframe |
| 57 | |
| 58 | def populate_buy_trend(self, dataframe: DataFrame) -> DataFrame: |
| 59 | """ |
| 60 | Based on TA indicators, populates the buy signal for the given dataframe |
| 61 | :param dataframe: DataFrame |
| 62 | :return: DataFrame with buy column |
| 63 | """ |
| 64 | dataframe.loc[ |
| 65 | ( |
| 66 | (dataframe['adx'] > 30) & |
| 67 | (dataframe['tema'] > dataframe['tema'].shift(1)) & |
| 68 | (dataframe['volume'] > 0) |
| 69 | ), |
| 70 | 'buy'] = 1 |
| 71 | |
| 72 | return dataframe |
| 73 | |
| 74 | def populate_sell_trend(self, dataframe: DataFrame) -> DataFrame: |
| 75 | """ |
| 76 | Based on TA indicators, populates the sell signal for the given dataframe |
| 77 | :param dataframe: DataFrame |
| 78 | :return: DataFrame with buy column |
| 79 | """ |
| 80 | dataframe.loc[ |
| 81 | ( |
| 82 | (dataframe['adx'] > 70) & |
| 83 | (dataframe['tema'] < dataframe['tema'].shift(1)) & |
| 84 | (dataframe['volume'] > 0) |
| 85 | ), |
| 86 | 'sell'] = 1 |
| 87 | return dataframe |