调整入场逻辑

This commit is contained in:
Ubuntu 2025-08-31 19:30:50 +08:00
parent 0806774f38
commit 54effd23c1

View File

@ -401,14 +401,23 @@ class FreqaiPrimer(IStrategy):
# 条件4: MACD 上升趋势
macd_condition_1h = dataframe['macd_1h'] > dataframe['macd_signal_1h']
# 条件5: 成交量显著放大
volume_spike = dataframe['volume'] > dataframe['volume_ma'] * 1.5
# 条件6: 布林带宽度过滤(避免窄幅震荡)
bb_width = (dataframe['bb_upper_1h'] - dataframe['bb_lower_1h']) / dataframe['close']
bb_width_condition = bb_width > 0.02 # 布林带宽度大于2%
# 辅助条件: 3m 和 15m 趋势确认
trend_confirmation = (dataframe['trend_3m'] == 1) & (dataframe['trend_15m'] == 1)
# 合并所有条件(放宽逻辑组合)
# 合并所有条件(增加成交量和布林带宽度过滤
final_condition = (
close_to_bb_lower_1h &
(rsi_condition_1h | stochrsi_condition_1h) & # 允许 RSI 或 StochRSI 满足其一
macd_condition_1h &
volume_spike & # 成交量显著放大
bb_width_condition & # 布林带宽度过滤
trend_confirmation
)
@ -595,8 +604,20 @@ class FreqaiPrimer(IStrategy):
if current_state == 'strong_bull' and current_profit > -0.01:
return -1.5 * atr / current_rate
# 动态调整止损范围
if current_profit > 0.05: # 利润超过5%时
return -2.5 * atr / current_rate # 大幅扩大止损范围,让利润奔跑
elif current_profit > 0.03: # 利润超过3%时
return -2.0 * atr / current_rate # 中等扩大止损范围
elif current_profit > 0.01: # 利润超过1%时
return -1.5 * atr / current_rate # 轻微扩大止损范围
# 在强劲牛市中,即使小亏损也可以容忍更大回调
if current_state == 'strong_bull' and current_profit > -0.01:
return -1.8 * atr / current_rate
if atr > 0:
return -1.0 * atr / current_rate # 基础1倍ATR止损
return -1.2 * atr / current_rate # 基础1.2倍ATR止损
return self.stoploss
def custom_exit(self, pair: str, trade: 'Trade', current_time, current_rate: float,
@ -619,6 +640,10 @@ class FreqaiPrimer(IStrategy):
# 默认使用中性市场的止盈设置
levels = profit_levels.get(current_state, profit_levels['neutral'])
# 在强劲牛市中,进一步放宽止盈目标
if current_state == 'strong_bull':
levels = [(p + 0.01, r) for p, r in levels] # 将止盈触发利润提高1%
# 确定当前应该止盈的比例
exit_ratio = 0.0
for profit_target, ratio in levels: