去掉三元表达式,使用最基础的写法
This commit is contained in:
parent
41c339d6bb
commit
c541dceb24
@ -811,7 +811,10 @@ class FreqaiPrimer(IStrategy):
|
||||
pass
|
||||
|
||||
# 输出诊断日志
|
||||
ml_prob_str = f"{entry_prob:.2f}" if entry_prob is not None else "N/A"
|
||||
if entry_prob is not None:
|
||||
ml_prob_str = f"{entry_prob:.2f}"
|
||||
else:
|
||||
ml_prob_str = "N/A"
|
||||
self.strategy_log(
|
||||
f"[入场诊断] {metadata['pair']} | "
|
||||
f"价格: {current_close:.6f} | "
|
||||
@ -949,7 +952,14 @@ class FreqaiPrimer(IStrategy):
|
||||
# 冷启动保护:程序启动后前20分钟内不允许入场
|
||||
if hasattr(self, "_strategy_start_time") and self.config.get("runmode") != RunMode.BACKTEST:
|
||||
warmup_minutes = 20
|
||||
elapsed_minutes = (current_time - self._strategy_start_time).total_seconds() / 60.0
|
||||
# 确保两个时间对象都具有相同的时区信息,避免时区不匹配错误
|
||||
if current_time.tzinfo is None:
|
||||
# 如果current_time是naive datetime,将其转换为utc timezone
|
||||
current_time_with_tz = current_time.replace(tzinfo=datetime.timezone.utc)
|
||||
else:
|
||||
current_time_with_tz = current_time
|
||||
|
||||
elapsed_minutes = (current_time_with_tz - self._strategy_start_time).total_seconds() / 60.0
|
||||
if elapsed_minutes < warmup_minutes:
|
||||
self.strategy_log(
|
||||
f"[{pair}] 策略启动未满 {warmup_minutes} 分钟(已运行 {elapsed_minutes:.1f} 分钟),跳过本次入场信号"
|
||||
@ -964,7 +974,12 @@ class FreqaiPrimer(IStrategy):
|
||||
# 检查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 current_time.tzinfo is None:
|
||||
current_time_with_tz = current_time.replace(tzinfo=datetime.timezone.utc)
|
||||
else:
|
||||
current_time_with_tz = current_time
|
||||
time_diff = (current_time_with_tz - last_entry).total_seconds() * 0.0166666667 # 转换为分钟(使用乘法避免除法)
|
||||
if time_diff < self.entry_interval_minutes.value:
|
||||
self.strategy_log(f"[{pair}] 入场间隔不足: 距离上次入场 {time_diff:.1f}分钟 < {self.entry_interval_minutes.value}分钟,取消本次入场")
|
||||
allow_trade = False
|
||||
@ -1029,6 +1044,10 @@ class FreqaiPrimer(IStrategy):
|
||||
market_state = str(last_row.get('market_state', 'unknown'))
|
||||
|
||||
# 输出诊断日志
|
||||
if entry_prob is not None:
|
||||
ml_prob_str = f"{entry_prob:.2f}"
|
||||
else:
|
||||
ml_prob_str = "N/A"
|
||||
self.strategy_log(
|
||||
f"[入场诊断] {pair} | "
|
||||
f"价格: {current_close:.6f} | "
|
||||
@ -1038,7 +1057,7 @@ class FreqaiPrimer(IStrategy):
|
||||
f"RSI: {rsi_1h:.1f} | "
|
||||
f"MACD: {macd_cross} | "
|
||||
f"市场: {market_state} | "
|
||||
f"ML入场概率: {entry_prob:.2f if entry_prob is not None else 'N/A'}"
|
||||
f"ML入场概率: {ml_prob_str}"
|
||||
)
|
||||
# ========== 诊断统计结束 ==========
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user