custom_exit 拒绝加仓2次后的退出
This commit is contained in:
parent
a46825151f
commit
b0660d5b2e
@ -1586,13 +1586,34 @@ class FreqaiPrimer(IStrategy):
|
||||
|
||||
return adjusted_rate
|
||||
|
||||
def custom_exit(self, pair: str, trade: Trade,
|
||||
current_time: datetime, current_rate: float,
|
||||
current_profit: float, **kwargs) -> str | bool | None:
|
||||
"""
|
||||
自定义退出信号逻辑:当加仓次数 >= 2时,拒绝一切exit信号(止损除外)
|
||||
|
||||
:param pair: 当前分析的币对
|
||||
:param trade: 交易对象
|
||||
:param current_time: 当前时间
|
||||
:param current_rate: 当前价格
|
||||
:param current_profit: 当前利润(比例)
|
||||
:param kwargs: 其他参数
|
||||
:return: 返回None或False表示不退出,返回字符串或True表示退出
|
||||
"""
|
||||
if trade.entry_side_count >= 2:
|
||||
# 当加仓次数 >= 2时,拒绝所有退出信号(止损除外)
|
||||
logger.info(f"[{pair}] 加仓次数 {trade.entry_side_count} >= 2,拒绝退出信号(止损除外)")
|
||||
return None # 阻止所有非止损的退出
|
||||
|
||||
# 加仓次数 < 2时,允许正常退出
|
||||
return None
|
||||
|
||||
def custom_exit_price(self, pair: str, trade: Trade,
|
||||
current_time: datetime, proposed_rate: float,
|
||||
current_profit: float, exit_tag: str | None, **kwargs) -> float:
|
||||
if trade.entry_side_count >= 2:
|
||||
# 当加仓次数 >= 2 时,只允许止损退出
|
||||
# 止损逻辑由Freqtrade自动处理,无需显式检查
|
||||
return None # 禁用其他退出信号
|
||||
"""
|
||||
自定义退出价格逻辑
|
||||
"""
|
||||
adjusted_rate = proposed_rate * (1 + 0.0025)
|
||||
logger.info(f"[{pair}] 自定义卖出价:{adjusted_rate:.6f}(原价:{proposed_rate:.6f})")
|
||||
return adjusted_rate
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user