From e9f287c3d602199afd50d04918afb066e3bd4dd9 Mon Sep 17 00:00:00 2001 From: "zhangkun9038@dingtalk.com" Date: Sat, 31 Jan 2026 10:41:24 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=B2=E6=AD=A2=E8=BF=BD=E9=AB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- freqtrade/templates/freqaiprimer.py | 39 +++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/freqtrade/templates/freqaiprimer.py b/freqtrade/templates/freqaiprimer.py index a359e6d3..0297e0e0 100644 --- a/freqtrade/templates/freqaiprimer.py +++ b/freqtrade/templates/freqaiprimer.py @@ -957,10 +957,45 @@ class FreqaiPrimer(IStrategy): if allow_trade: is_unstable_region = self.detect_h1_rapid_rise(pair) if is_unstable_region: - #self.strategy_log(f"[{pair}] 由于检测到剧烈拉升,取消入场交易") + self.strategy_log(f"[{pair}] 🚫 拉升后不稳固区域,取消入场") allow_trade = False - # 检查3:ML 审核官(FreqAI 过滤低质量入场)+ 入场诊断统计 + # 检查3:防止追高 - 价格接近短期高点 + if allow_trade: + try: + df, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe) + if len(df) >= 20: + last_row = df.iloc[-1] + current_close = float(last_row['close']) + + # 短期高点(最近10根1h K线,即10小时) + recent_10h_high = float(df['high'].iloc[-10:].max()) + price_vs_high = (current_close - recent_10h_high) / recent_10h_high + + # 如果价格在短期高点的 -2% 以内,认为是追高 + if price_vs_high > -0.02: + self.strategy_log( + f"[{pair}] 🚫 追高过滤: 当前价 {current_close:.6f} 接近10h高点 {recent_10h_high:.6f} " + f"({price_vs_high:+.2%}),取消入场" + ) + allow_trade = False + + # 额外检查:价格在布林带上半部(> 0.7)且 RSI > 60 = 高位震荡 + bb_upper = float(last_row.get('bb_upper_1h', current_close)) + bb_lower = float(last_row.get('bb_lower_1h', current_close)) + bb_position = (current_close - bb_lower) / (bb_upper - bb_lower) if (bb_upper - bb_lower) > 0 else 0.5 + rsi_1h = float(last_row.get('rsi_1h', 50)) + + if bb_position > 0.7 and rsi_1h > 60: + self.strategy_log( + f"[{pair}] 🚫 高位震荡过滤: BB位置 {bb_position:.2f}, RSI {rsi_1h:.1f},取消入场" + ) + allow_trade = False + + except Exception as e: + logger.warning(f"[{pair}] 追高检查失败: {e}") + + # 检查4:ML 审核官(FreqAI 过滤低质量入场)+ 入场诊断统计 # 逻辑:用 entry_signal 概率来判断——若"容易上涨概率"低,则拒绝入场 if allow_trade: try: