入场最短间隔时间用hyperopt优化
This commit is contained in:
parent
a155540533
commit
a22a4da63c
@ -45,12 +45,11 @@ class FreqaiPrimer(IStrategy):
|
||||
# 格式: {pair: timestamp}
|
||||
self._volatility_timestamp = {}
|
||||
self._volatility_cache = {}
|
||||
self._volatility_update_interval = 3600 # 波动系数更新间隔(秒),设置为1小时
|
||||
self._volatility_update_interval = 1200 # 波动系数更新间隔(秒),设置为1小时
|
||||
|
||||
# 入场间隔控制:记录每个交易对最近一次入场的时间
|
||||
# 格式: {pair: datetime}
|
||||
self._last_entry_time = {}
|
||||
self._entry_interval_minutes = 42 # 两次入场至少间隔4 2分钟
|
||||
|
||||
# 只用于adjust_trade_position方法的波动系数获取
|
||||
def get_volatility_coefficient(self, pair: str) -> float:
|
||||
@ -242,6 +241,9 @@ class FreqaiPrimer(IStrategy):
|
||||
h1_max_candles = IntParameter(100, 300, default=200, optimize=True, load=True, space='buy')
|
||||
h1_rapid_rise_threshold = DecimalParameter(0.05, 0.15, decimals=3, default=0.11, optimize=True, load=True, space='buy')
|
||||
h1_max_consecutive_candles = IntParameter(1, 4, default=2, optimize=True, load=True, space='buy')
|
||||
|
||||
# 入场间隔控制参数(分钟)
|
||||
entry_interval_minutes = IntParameter(20, 200, default=42, optimize=True, load=True, space='buy')
|
||||
# 定义可优化参数
|
||||
# 初始入场金额: 75.00
|
||||
|
||||
@ -659,12 +661,12 @@ class FreqaiPrimer(IStrategy):
|
||||
|
||||
# 仅对多头交易进行检查
|
||||
if side == 'long':
|
||||
# 检查1:入场间隔控制(42分钟)
|
||||
# 检查1:入场间隔控制(使用hyperopt参数)
|
||||
if pair in self._last_entry_time:
|
||||
last_entry = self._last_entry_time[pair]
|
||||
time_diff = (current_time - last_entry).total_seconds() * 0.0166666667 # 转换为分钟(使用乘法避免除法)
|
||||
if time_diff < self._entry_interval_minutes:
|
||||
logger.info(f"[{pair}] 入场间隔不足: 距离上次入场 {time_diff:.1f}分钟 < {self._entry_interval_minutes}分钟,取消本次入场")
|
||||
if time_diff < self.entry_interval_minutes.value:
|
||||
logger.info(f"[{pair}] 入场间隔不足: 距离上次入场 {time_diff:.1f}分钟 < {self.entry_interval_minutes.value}分钟,取消本次入场")
|
||||
allow_trade = False
|
||||
|
||||
# 检查2:检查是否处于剧烈拉升的不稳固区域
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user