--- original_strategy.py +++ modified_strategy.py @@ -28,8 +28,8 @@ class FreqaiPrimer(IStrategy): TRAILING_STOP_DISTANCE = DecimalParameter(0.005, 0.02, default=0.01, space='sell', optimize=True) - BUY_THRESHOLD_MIN = DecimalParameter(-0.1, -0.01, default=-0.05, space='buy', optimize=True) - BUY_THRESHOLD_MAX = DecimalParameter(-0.02, -0.001, default=-0.005, space='buy', optimize=True) + BUY_THRESHOLD_MIN = DecimalParameter(-0.15, -0.03, default=-0.07, space='buy', optimize=True) + BUY_THRESHOLD_MAX = DecimalParameter(-0.04, -0.005, default=-0.01, space='buy', optimize=True) SELL_THRESHOLD_MIN = DecimalParameter(0.001, 0.02, default=0.005, space='sell', optimize=True) SELL_THRESHOLD_MAX = DecimalParameter(0.02, 0.1, default=0.05, space='sell', optimize=True) @@ -356,10 +356,10 @@ class FreqaiPrimer(IStrategy): volume_z_score_min = 0.5 volume_z_score_max = 1.5 volume_z_score_threshold = self.linear_map(trend_score, 0, 100, volume_z_score_max, volume_z_score_min) - rsi_min = 40 - rsi_max = 60 + rsi_min = 35 + rsi_max = 55 rsi_threshold = self.linear_map(trend_score, 0, 100, rsi_max, rsi_min) - stochrsi_min = 30 - stochrsi_max = 50 + stochrsi_min = 25 + stochrsi_max = 45 stochrsi_threshold = self.linear_map(trend_score, 0, 100, stochrsi_max, stochrsi_min) if "&-price_value_divergence" in dataframe.columns: # 计算 STOCHRSI stochrsi = ta.STOCHRSI(dataframe, timeperiod=14, fastk_period=3, fastd_period=3) dataframe["stochrsi_k"] = stochrsi["fastk"] + # 添加 15m 时间框架的 EMA200 + dataframe_15m = self.dp.get_pair_dataframe(pair=pair, timeframe="15m") + dataframe_15m["ema200_15m"] = ta.EMA(dataframe_15m, timeperiod=200) + dataframe["ema200_15m"] = dataframe_15m["ema200_15m"].reindex(dataframe.index, method="ffill") cond1 = (dataframe["&-price_value_divergence"] < self.buy_threshold) cond2 = (dataframe["volume_z_score"] > volume_z_score_threshold) cond3 = (dataframe["rsi"] < rsi_threshold) cond4 = (dataframe["close"] <= dataframe["bb_lowerband"]) - cond5 = (dataframe["stochrsi_k"] < stochrsi_threshold) - buy_condition = cond1 & cond2 & cond3 & cond4 & cond5 + cond5 = (dataframe["stochrsi_k"] < stochrsi_threshold) + cond6 = (dataframe["close"] < dataframe["ema200_15m"]) # 价格低于 15m EMA200 + buy_condition = cond1 & cond2 & cond3 & cond4 & cond5 & cond6 conditions.append(buy_condition) @@ -534,7 +534,7 @@ class FreqaiPrimer(IStrategy): def get_market_trend(self, dataframe: DataFrame = None, metadata: dict = None) -> int: try: timeframes = ["3m", "15m", "1h"] - weights = {"3m": 0.5, "15m": 0.3, "1h": 0.2} + weights = {"3m": 0.3, "15m": 0.35, "1h": 0.35} trend_scores = {} pair = metadata.get('pair', 'Unknown') if metadata else 'Unknown' @@ -565,7 +565,7 @@ class FreqaiPrimer(IStrategy): pair_df["ema_short_slope"] = (pair_df["ema_short"] - pair_df["ema_short"].shift(10)) / pair_df["ema_short"].shift(10) # 动态调整权重 - if trend_scores.get("1h", 50) - trend_scores.get("3m", 50) > 20: - weights = {"3m": 0.3, "15m": 0.3, "1h": 0.4} + if trend_scores.get("1h", 50) - trend_scores.get("3m", 50) > 20 or trend_scores.get("15m", 50) - trend_scores.get("3m", 50) > 20: + weights = {"3m": 0.2, "15m": 0.35, "1h": 0.45} logger.debug(f"[{pair}] 1h 趋势得分({trend_scores.get('1h', 50)})显著高于 3m({trend_scores.get('3m', 50)}),调整权重为 {weights}")