防止追高

This commit is contained in:
zhangkun9038@dingtalk.com 2026-01-31 10:41:24 +08:00
parent d9a2267e43
commit e9f287c3d6

View File

@ -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
# 检查3ML 审核官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}")
# 检查4ML 审核官FreqAI 过滤低质量入场)+ 入场诊断统计
# 逻辑:用 entry_signal 概率来判断——若"容易上涨概率"低,则拒绝入场
if allow_trade:
try: