# Auto-generated by Strategy Lab — Auto-Quant Factory # Entry logic is controlled by the CategoricalParameter `entry_logic`. # Optimise it with: freqtrade hyperopt --strategy IntradayBasic_v1 --spaces buy from freqtrade.strategy import CategoricalParameter, IStrategy from pandas import DataFrame import talib.abstract as ta import freqtrade.vendor.qtpylib.indicators as qtpylib class IntradayBasic_v1(IStrategy): INTERFACE_VERSION: int = 3 # --- ROI / stoploss / timeframe defaults ---------------------------- minimal_roi = { "0": 0.10, "30": 0.05, "60": 0.02, "120": 0, } stoploss = -0.05 timeframe = "5m" trailing_stop = False # --- Categorical entry-logic selector -------------------------------- # Hyperopt will search this space when --spaces buy is used. entry_logic = CategoricalParameter( ["macd_cross", "rsi_oversold", "bb_breakout"], default="macd_cross", space="buy", optimize=True, ) # --- Indicator computation ------------------------------------------- def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: # MACD (fast=12, slow=26, signal=9) macd = ta.MACD(dataframe, fastperiod=12, slowperiod=26, signalperiod=9) dataframe["macd"] = macd["macd"] dataframe["macdsignal"] = macd["macdsignal"] dataframe["macdhist"] = macd["macdhist"] # RSI (period=14) dataframe["rsi"] = ta.RSI(dataframe, timeperiod=14) # Bollinger Bands (period=20, stddev=2) 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"] return dataframe # --- Entry logic router ---------------------------------------------- def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: logic = self.entry_logic.value if logic == "macd_cross": dataframe.loc[ ( qtpylib.crossed_above(dataframe["macd"], dataframe["macdsignal"]) & (dataframe["volume"] > 0) ), "enter_long", ] = 1 elif logic == "rsi_oversold": dataframe.loc[ ( (dataframe["rsi"] < 30) & (dataframe["volume"] > 0) ), "enter_long", ] = 1 elif logic == "bb_breakout": dataframe.loc[ ( (dataframe["close"] < dataframe["bb_lowerband"]) & (dataframe["volume"] > 0) ), "enter_long", ] = 1 return dataframe # --- Exit logic stub (relies on ROI / stoploss) ---------------------- def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: return dataframe