动态止损
This commit is contained in:
parent
2718e7a024
commit
bc8407365f
@ -19,6 +19,7 @@ class FreqaiPrimer(IStrategy):
|
||||
- 使用 FreqAI 提供的趋势和波动率信号进行交易决策
|
||||
"""
|
||||
|
||||
use_custom_stoploss = True
|
||||
plot_config = {
|
||||
"main_plot": {},
|
||||
"subplots": {
|
||||
@ -223,3 +224,21 @@ class FreqaiPrimer(IStrategy):
|
||||
|
||||
# 返回新的 minimal_roi
|
||||
return new_minimal_roi
|
||||
|
||||
def custom_stoploss(self, pair: str, trade: Trade, current_time: datetime,
|
||||
current_rate: float, current_profit: float, **kwargs) -> float:
|
||||
"""
|
||||
动态止损回调函数,基于 FreqAI 预测的 &-stoploss_target 值。
|
||||
"""
|
||||
|
||||
# 获取当前币种的 dataframe
|
||||
dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)
|
||||
last_candle = dataframe.iloc[-1]
|
||||
|
||||
# 获取预测的止损目标
|
||||
stoploss_target = last_candle.get("&-stoploss_target", -0.01)
|
||||
|
||||
# 将 stoploss_target 转换为负数(因为 stoploss 是负值)
|
||||
dynamic_stoploss = min(-0.005, stoploss_target) # 设置最小止损限制
|
||||
|
||||
return dynamic_stoploss
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user