只要加仓至少1次, 只要盈利,立即退出

This commit is contained in:
zhangkun9038@dingtalk.com 2025-08-30 10:11:12 +08:00
parent 295b7b6982
commit 42e51f8d91

View File

@ -1559,6 +1559,33 @@ class FreqaiPrimer(IStrategy):
adjusted_rate = proposed_rate * (1 + 0.0025)
logger.info(f"[{pair}] 自定义卖出价:{adjusted_rate:.6f}(原价:{proposed_rate:.6f}")
return adjusted_rate
def custom_exit(self, pair: str, trade: Trade, current_time: datetime, current_rate: float,
current_profit: float, **kwargs):
"""
自定义退出逻辑当发生1次或以上加仓且盈利时立即退出交易
参数
- pair: 交易对
- trade: 当前交易对象
- current_time: 当前时间
- current_rate: 当前价格
- current_profit: 当前总盈利
返回
- 退出原因字符串 True触发退出False不退出
"""
# 检查是否有过加仓nr_of_successful_entries > 1表示至少有一次加仓
has_additional_entries = trade.nr_of_successful_entries > 1
# 检查是否盈利
is_profitable = current_profit > 0
# 如果有过加仓且盈利,立即退出
if has_additional_entries and is_profitable:
logger.info(f"[{pair}] 检测到{trade.nr_of_successful_entries - 1}次加仓且当前盈利{current_profit*100:.2f}%,触发立即退出")
return "加仓后盈利退出"
# 其他情况不触发自定义退出
return False
def get_market_trend(self, dataframe: DataFrame = None, metadata: dict = None) -> int:
try: