# Import necessary libraries from freqtrade.strategy import IStrategy from pandas import DataFrame import talib.abstract as ta class # Import necessary libraries from freqtrade.strategy import IStrategy from pandas import DataFrame import talib.abstract as ta class BollingerBandsStrategy(IStrategy): # Define minimal ROI (return on investment) and stoploss minimal_roi = { "0": 0.10 # 10% profit before we consider selling } stoploss = -0.10 # 10% stoploss # Define the time frame for the strategy (5 minutes) timeframe = '5m' # Custom settings for Bollinger Bands (period, deviation) bollinger_period = 20 bollinger_deviation = 2 def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: # Add Bollinger Bands to the dataframe # Upper and Lower Bands + Middle Band (SMA) bollinger = ta.BBANDS(dataframe, timeperiod=self.bollinger_period, nbdevup=self.bollinger_deviation, nbdevdn=self.bollinger_deviation, matype=0) dataframe['bb_upper'] = bollinger['upperband'] dataframe['bb_lower'] = bollinger['lowerband'] dataframe['bb_middle'] = bollinger['middleband'] return dataframe def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: # Buy condition: Close price is above the upper Bollinger Band dataframe.loc[ ( dataframe['close'] > dataframe['bb_upper'] ), 'buy'] = 1 return dataframe def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: # Sell condition: Close price is below the lower Bollinger Band dataframe.loc[ ( dataframe['close'] < dataframe['bb_lower'] ), 'sell'] = 1 return dataframe(IStrategy): # Define minimal ROI (return on investment) and stoploss minimal_roi = { "0": 0.10 # 10% profit before we consider selling } stoploss = -0.10 # 10% stoploss # Define the time frame for the strategy (5 minutes) timeframe = '5m' # Custom settings for Bollinger Bands (period, deviation) bollinger_period = 20 bollinger_deviation = 2 def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: # Add Bollinger Bands to the dataframe # Upper and Lower Bands + Middle Band (SMA) bollinger = ta.BBANDS(dataframe, timeperiod=self.bollinger_period, nbdevup=self.bollinger_deviation, nbdevdn=self.bollinger_deviation, matype=0) dataframe['bb_upper'] = bollinger['upperband'] dataframe['bb_lower'] = bollinger['lowerband'] dataframe['bb_middle'] = bollinger['middleband'] return dataframe def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: # Buy condition: Close price is above the upper Bollinger Band dataframe.loc[ ( dataframe['close'] > dataframe['bb_upper'] ), 'buy'] = 1 return dataframe def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: # Sell condition: Close price is below the lower Bollinger Band dataframe.loc[ ( dataframe['close'] < dataframe['bb_lower'] ), 'sell'] = 1 return dataframe