From dc5a38873116be5810c4eb5fefe21f39f09cb62c Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sun, 31 Aug 2025 19:38:30 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=85=A5=E5=9C=BA=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- freqtrade/templates/freqaiprimer.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/freqtrade/templates/freqaiprimer.py b/freqtrade/templates/freqaiprimer.py index dc1f5c7c..063542e3 100644 --- a/freqtrade/templates/freqaiprimer.py +++ b/freqtrade/templates/freqaiprimer.py @@ -192,8 +192,8 @@ class FreqaiPrimer(IStrategy): df_1h['stochrsi_k_1h'] = stochrsi_1h['STOCHRSIk_14_14_3_3'] df_1h['stochrsi_d_1h'] = stochrsi_1h['STOCHRSId_14_14_3_3'] - # 将 1h 数据重新索引到主时间框架 (3m) - df_1h = df_1h.set_index('date').reindex(dataframe['date']).reset_index() + # 将 1h 数据重新索引到主时间框架 (3m),并填充缺失值 + df_1h = df_1h.set_index('date').reindex(dataframe['date']).ffill().bfill().reset_index() df_1h = df_1h.rename(columns={'index': 'date'}) # Include macd_1h and macd_signal_1h in the column selection df_1h = df_1h[['date', 'rsi_1h', 'trend_1h', 'ema_50_1h', 'ema_200_1h', 'bb_lower_1h', 'bb_upper_1h', 'stochrsi_k_1h', 'stochrsi_d_1h', 'macd_1h', 'macd_signal_1h']].ffill() @@ -393,10 +393,10 @@ class FreqaiPrimer(IStrategy): close_to_bb_lower_1h = (dataframe['close'] <= dataframe['bb_lower_1h'] * 1.02) # 条件2: RSI 不高于阈值(更严格) - rsi_condition_1h = dataframe['rsi_1h'] < 45 # 更严格的 RSI 阈值 + rsi_condition_1h = dataframe['rsi_1h'] < 40 # 进一步收紧 RSI 阈值 # 条件3: StochRSI 处于超卖区域(更严格) - stochrsi_condition_1h = (dataframe['stochrsi_k_1h'] < 25) & (dataframe['stochrsi_d_1h'] < 25) # 更严格的 StochRSI 阈值 + stochrsi_condition_1h = (dataframe['stochrsi_k_1h'] < 20) & (dataframe['stochrsi_d_1h'] < 20) # 进一步收紧 StochRSI 阈值 # 条件4: MACD 上升趋势 macd_condition_1h = dataframe['macd_1h'] > dataframe['macd_signal_1h'] @@ -411,6 +411,9 @@ class FreqaiPrimer(IStrategy): # 辅助条件: 3m 和 15m 趋势确认 trend_confirmation = (dataframe['trend_3m'] == 1) & (dataframe['trend_15m'] == 1) + # 增加布林带宽度过滤器,避免窄幅震荡市场 + bb_width_condition = (dataframe['bb_upper_1h'] - dataframe['bb_lower_1h']) / dataframe['close'] > 0.03 # 布林带宽度大于3% + # 合并所有条件(增加成交量和布林带宽度过滤) final_condition = ( close_to_bb_lower_1h & @@ -594,12 +597,12 @@ class FreqaiPrimer(IStrategy): current_state = dataframe['market_state'].iloc[-1] if 'market_state' in dataframe.columns else 'unknown' # 更激进的渐进式止损策略 - if current_profit > 0.04: # 利润超过4%时 - return -2.0 * atr / current_rate # 大幅扩大止损范围,让利润奔跑 - elif current_profit > 0.025: # 利润超过2.5%时 - return -1.7 * atr / current_rate # 中等扩大止损范围 + if current_profit > 0.05: # 利润超过5%时 + return -3.0 * atr / current_rate # 更大幅扩大止损范围,让利润奔跑 + elif current_profit > 0.03: # 利润超过3%时 + return -2.5 * atr / current_rate # 更中等扩大止损范围 elif current_profit > 0.01: # 利润超过1%时 - return -1.3 * atr / current_rate # 轻微扩大止损范围 + return -2.0 * atr / current_rate # 更轻微扩大止损范围 # 在强劲牛市中,即使小亏损也可以容忍更大回调 if current_state == 'strong_bull' and current_profit > -0.01: @@ -632,10 +635,10 @@ class FreqaiPrimer(IStrategy): # 定义更激进的渐进式止盈水平,提高收益上限 profit_levels = { # 状态: [(止盈触发利润, 止盈比例)] - 'strong_bull': [(0.03, 0.2), (0.06, 0.35), (0.09, 0.5), (0.12, 0.65), (0.15, 0.8)], # 强劲牛市的渐进止盈,提高目标 - 'weak_bull': [(0.02, 0.25), (0.04, 0.45), (0.07, 0.7), (0.10, 0.9)], # 弱牛市的渐进止盈 - 'neutral': [(0.015, 0.35), (0.03, 0.6), (0.05, 0.85)], # 中性市场的渐进止盈 - 'bear': [(0.01, 0.6), (0.02, 0.9), (0.03, 1.0)] # 熊市的渐进止盈(更保守) + 'strong_bull': [(0.04, 0.2), (0.08, 0.4), (0.12, 0.6), (0.16, 0.8), (0.20, 1.0)], # 强劲牛市的渐进止盈,提高目标 + 'weak_bull': [(0.03, 0.3), (0.06, 0.5), (0.09, 0.7), (0.12, 0.9)], # 弱牛市的渐进止盈 + 'neutral': [(0.02, 0.4), (0.04, 0.6), (0.06, 0.8), (0.08, 1.0)], # 中性市场的渐进止盈 + 'bear': [(0.01, 0.6), (0.02, 0.8), (0.03, 1.0)] # 熊市的渐进止盈(更保守) } # 默认使用中性市场的止盈设置