加仓逻辑修复

This commit is contained in:
zhangkun9038@dingtalk.com 2025-08-22 16:19:01 +08:00
parent 0207db2da5
commit 5f7b8295b0

View File

@ -1264,9 +1264,29 @@ class FreqaiPrimer(IStrategy):
# 计算当前加仓阈值config中的ADD_POSITION_THRESHOLD × (递进系数^加仓次数) # 计算当前加仓阈值config中的ADD_POSITION_THRESHOLD × (递进系数^加仓次数)
current_add_threshold = self.ADD_POSITION_THRESHOLD * (self.ADD_PROGRESSION_FACTOR ** add_count) current_add_threshold = self.ADD_POSITION_THRESHOLD * (self.ADD_PROGRESSION_FACTOR ** add_count)
# 统一加仓逻辑(移除所有趋势判断) # 计算从上一次加仓以来的跌幅(使用正确的基准)
if add_count > 0:
# 有加仓记录,使用最后一次加仓价作为基准
last_entry_price = trade.orders[-1].safe_price if trade.orders else trade.open_rate
drop_since_last_entry = (current_rate - last_entry_price) / last_entry_price
drop_baseline = drop_since_last_entry
logger.info(f"{pair}{add_count}次加仓后跌幅: {drop_since_last_entry*100:.2f}% (基于上次加仓价)")
else:
# 首次加仓,使用初始入场价
drop_baseline = profit_ratio
logger.info(f"{pair} 首次加仓跌幅: {profit_ratio*100:.2f}% (基于初始入场价)")
# 统一加仓逻辑(增加冷却期检查)
if trade.nr_of_successful_entries <= max_entry_adjustments + 1: if trade.nr_of_successful_entries <= max_entry_adjustments + 1:
if profit_ratio <= current_add_threshold and hold_time > 5: # 仅检查跌幅和时间 # 检查加仓冷却期至少10分钟
if trade.orders:
last_order_time = trade.orders[-1].order_date_utc
time_since_last_add = (current_time - last_order_time).total_seconds() / 60
if time_since_last_add < 10: # 10分钟冷却期
logger.info(f"{pair} 加仓冷却期中,{10 - time_since_last_add:.1f}分钟后可再次加仓")
return None
if drop_baseline <= current_add_threshold and hold_time > 5: # 使用正确跌幅基准
# 统一加仓倍数 # 统一加仓倍数
multipliers = [1, 2, 4, 8] # 固定倍数序列 [首次, 第二次, 第三次, 第四次] multipliers = [1, 2, 4, 8] # 固定倍数序列 [首次, 第二次, 第三次, 第四次]