# pragma pylint: disable=missing-docstring, invalid-name, too-few-public-methods """ IchimokuHyper — version paramétrable d'IchimokuStrategy pour hyperopt (futures, long/short). Paramètres optimisables : - buy_adx_min : force de tendance minimale - buy_cloud_min_pct : largeur minimale du nuage (anti-chop) en % du prix - require_tk_cross : exiger le croisement Tenkan/Kijun (sinon simple position vs nuage) + espaces ROI / stoploss / trailing. Anti-lookahead : Senkou décalés de +26 ; confirmation via close vs close[-26]. """ from __future__ import annotations import talib.abstract as ta from pandas import DataFrame from freqtrade.strategy import ( IStrategy, IntParameter, DecimalParameter, BooleanParameter, ) class IchimokuHyper(IStrategy): INTERFACE_VERSION = 3 timeframe = "1h" can_short = True minimal_roi = {"0": 0.06, "240": 0.03, "720": 0.01, "1440": 0} stoploss = -0.08 trailing_stop = True trailing_stop_positive = 0.025 trailing_stop_positive_offset = 0.04 trailing_only_offset_is_reached = True startup_candle_count: int = 120 process_only_new_candles = True use_exit_signal = True # --- Paramètres optimisables (espace "buy", appliqués long ET short) --- buy_adx_min = IntParameter(15, 40, default=20, space="buy", optimize=True) buy_cloud_min_pct = DecimalParameter( 0.0, 2.0, default=0.0, decimals=2, space="buy", optimize=True ) require_tk_cross = BooleanParameter(default=True, space="buy", optimize=True) def leverage(self, pair, current_time, current_rate, proposed_leverage, max_leverage, entry_tag, side, **kwargs) -> float: return 1.0 def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: high, low, close = dataframe["high"], dataframe["low"], dataframe["close"] tenkan = (high.rolling(9).max() + low.rolling(9).min()) / 2 kijun = (high.rolling(26).max() + low.rolling(26).min()) / 2 dataframe["tenkan"] = tenkan dataframe["kijun"] = kijun dataframe["senkou_a"] = ((tenkan + kijun) / 2).shift(26) dataframe["senkou_b"] = ( (high.rolling(52).max() + low.rolling(52).min()) / 2 ).shift(26) dataframe["cloud_top"] = dataframe[["senkou_a", "senkou_b"]].max(axis=1) dataframe["cloud_bot"] = dataframe[["senkou_a", "senkou_b"]].min(axis=1) # Largeur du nuage en % du prix (filtre anti-chop) dataframe["cloud_width_pct"] = ( (dataframe["cloud_top"] - dataframe["cloud_bot"]) / close * 100 ) dataframe["close_prev26"] = close.shift(26) dataframe["adx"] = ta.ADX(dataframe, timeperiod=14) return dataframe def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: adx_min = self.buy_adx_min.value cloud_min = self.buy_cloud_min_pct.value long_cond = ( (dataframe["close"] > dataframe["cloud_top"]) & (dataframe["tenkan"] > dataframe["kijun"]) & (dataframe["close"] > dataframe["close_prev26"]) & (dataframe["adx"] > adx_min) & (dataframe["cloud_width_pct"] > cloud_min) & (dataframe["volume"] > 0) ) short_cond = ( (dataframe["close"] < dataframe["cloud_bot"]) & (dataframe["tenkan"] < dataframe["kijun"]) & (dataframe["close"] < dataframe["close_prev26"]) & (dataframe["adx"] > adx_min) & (dataframe["cloud_width_pct"] > cloud_min) & (dataframe["volume"] > 0) ) if self.require_tk_cross.value: long_cond &= dataframe["tenkan"].shift(1) <= dataframe["kijun"].shift(1) short_cond &= dataframe["tenkan"].shift(1) >= dataframe["kijun"].shift(1) dataframe.loc[long_cond, "enter_long"] = 1 dataframe.loc[short_cond, "enter_short"] = 1 return dataframe def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: dataframe.loc[ ( ((dataframe["tenkan"] < dataframe["kijun"]) | (dataframe["close"] < dataframe["cloud_bot"])) & (dataframe["volume"] > 0) ), "exit_long", ] = 1 dataframe.loc[ ( ((dataframe["tenkan"] > dataframe["kijun"]) | (dataframe["close"] > dataframe["cloud_top"])) & (dataframe["volume"] > 0) ), "exit_short", ] = 1 return dataframe