diff --git a/freqtrade/templates/freqaiprimer.py b/freqtrade/templates/freqaiprimer.py index ec7beb6a..bd743c68 100644 --- a/freqtrade/templates/freqaiprimer.py +++ b/freqtrade/templates/freqaiprimer.py @@ -743,69 +743,6 @@ class FreqaiPrimer(IStrategy): # 设置入场信号 dataframe.loc[final_condition, 'enter_long'] = 1 - # ========== 新增:入场诊断统计(回测可用) ========== - # 对每个入场信号输出详细诊断信息 - entry_signals = dataframe[dataframe['enter_long'] == 1] - if len(entry_signals) > 0: - for idx in entry_signals.index[-5:]: # 只输出最近 5 个信号,避免日志过多 - row = dataframe.loc[idx] - current_close = float(row['close']) - - # 1. 价格与短期高点的关系 - recent_high_5 = float(dataframe.loc[max(0, idx-4):idx+1, 'high'].max()) if idx >= 4 else current_close - price_vs_recent_high = (current_close - recent_high_5) / recent_high_5 if recent_high_5 > 0 else 0 - - # 2. 价格与 EMA5 的关系 - ema5_1h = float(row.get('ema_5_1h', current_close)) - price_vs_ema5 = (current_close - ema5_1h) / ema5_1h if ema5_1h > 0 else 0 - - # 3. 价格与布林带的位置 - bb_upper = float(row.get('bb_upper_1h', current_close)) - bb_lower = float(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 - - # 4. RSI 状态 - rsi_1h = float(row.get('rsi_1h', 50)) - - # 5. MACD 状态 - macd_1h = float(row.get('macd_1h', 0)) - macd_signal_1h = float(row.get('macd_signal_1h', 0)) - macd_cross = 'up' if macd_1h > macd_signal_1h else 'down' - - # 6. 市场状态 - market_state = str(row.get('market_state', 'unknown')) - - # 7. ML 入场概率(如果有) - entry_prob = None - if '&s-entry_signal' in dataframe.columns: - val = row.get('&s-entry_signal', 0) - if val is not None and str(val).strip(): # 检查非空且非空白 - try: - entry_prob = float(val) - except (ValueError, TypeError): - pass - elif '&-entry_signal' in dataframe.columns: - val = row.get('&-entry_signal', 0) - if val is not None and str(val).strip(): - try: - entry_prob = float(val) - except (ValueError, TypeError): - pass - - # 输出诊断日志 - ml_prob_str = f"{entry_prob:.2f}" if entry_prob is not None else "N/A" - self.strategy_log( - f"[入场诊断] {metadata['pair']} | " - f"价格: {current_close:.6f} | " - f"vs 5K高点: {price_vs_recent_high:+.2%} | " - f"vs EMA5: {price_vs_ema5:+.2%} | " - f"布林位置: {bb_position:.2f} | " - f"RSI: {rsi_1h:.1f} | " - f"MACD: {macd_cross} | " - f"市场: {market_state} | " - f"ML概率: {ml_prob_str}" - ) - # ========== 诊断统计结束 ========== # 设置入场价格:下调1.67%(使用乘法避免除零风险) final_condition_updated = dataframe['enter_long'] == 1 @@ -1016,7 +953,7 @@ class FreqaiPrimer(IStrategy): # 基本信息 basic_info = ( - f"[入场诊断] {pair} | " + f"[入场诊断1] {pair} | " f"价格: {current_close:.6f} | " f"vs 5K高点: {price_vs_recent_high:+.2%} | " f"vs EMA5: {price_vs_ema5:+.2%}" @@ -1035,7 +972,6 @@ class FreqaiPrimer(IStrategy): f"ML入场概率: {ml_prob_str}" ) - self.strategy_log(basic_info + " | " + tech_info + " | " + env_info) # ========== 诊断统计结束 ========== if entry_prob is not None: @@ -1062,6 +998,7 @@ class FreqaiPrimer(IStrategy): allow_trade = False else: self.strategy_log(f"[{pair}] ML 审核官允许入场: entry_signal 概率 {entry_prob:.2f} >= 阈值 {entry_threshold:.2f}(市场: {market_state})") + self.strategy_log(basic_info + " | " + tech_info + " | " + env_info) except Exception as e: logger.warning(f"[{pair}] ML 审核官检查失败,忽略 ML 过滤: {e}") return allow_trade