降低ema门槛
This commit is contained in:
parent
c541dceb24
commit
71e8e7dcaa
@ -460,15 +460,9 @@ class FreqaiPrimer(IStrategy):
|
||||
(df_1h['ema_5_1h'] > df_1h['ema_20_1h']) &
|
||||
(df_1h['ema_5_1h'].shift(1) <= df_1h['ema_20_1h'].shift(1))
|
||||
)
|
||||
# 检测 EMA5 向下穿越 EMA20(用于防止趋势反转时入场)
|
||||
df_1h['ema5_cross_below_ema20'] = (
|
||||
(df_1h['ema_5_1h'] < df_1h['ema_20_1h']) &
|
||||
(df_1h['ema_5_1h'].shift(1) >= df_1h['ema_20_1h'].shift(1))
|
||||
)
|
||||
else:
|
||||
# 数据不足时,默认为False
|
||||
df_1h['ema5_cross_above_ema20'] = False
|
||||
df_1h['ema5_cross_below_ema20'] = False
|
||||
|
||||
# 使用 rolling 计算 RSI(减少看前偏差)
|
||||
delta_1h = df_1h['close'].diff()
|
||||
@ -725,18 +719,14 @@ class FreqaiPrimer(IStrategy):
|
||||
# 条件3:EMA20斜率必须满足阈值(避免过于平缓的趋势)
|
||||
if 'ema_20_1h' in dataframe.columns:
|
||||
ema20_slope = (dataframe['ema_20_1h'] - dataframe['ema_20_1h'].shift(5)) / dataframe['ema_20_1h'].shift(5)
|
||||
# 设置最小斜率阈值(例如0.002,即0.2%)
|
||||
min_ema20_slope = 0.002
|
||||
# 设置最小斜率阈值(降低到0.0001,即0.01%)- 更宽松的条件
|
||||
min_ema20_slope = 0.0001
|
||||
ema20_slope_condition = ema20_slope > min_ema20_slope
|
||||
# 所有条件必须同时满足
|
||||
ema_trend_filter = ema_trend_filter & ema20_slope_condition
|
||||
|
||||
# 条件4:防止趋势反转时入场(EMA5向下穿越EMA20时不允许入场)
|
||||
if 'ema5_cross_below_ema20' in dataframe.columns:
|
||||
# 检查当前是否发生了EMA5向下穿越EMA20的情况
|
||||
ema5_downward_cross = dataframe['ema5_cross_below_ema20']
|
||||
# 如果发生了向下穿越,则不允许入场
|
||||
ema_trend_filter = ema_trend_filter & ~ema5_downward_cross
|
||||
|
||||
# 调试信息:输出EMA20斜率信息
|
||||
# self.strategy_log(f"[调试] EMA20斜率检查: 当前斜率={ema20_slope.iloc[-1]:.6f}, 阈值={min_ema20_slope:.6f}, 条件={ema20_slope_condition.iloc[-1]}")
|
||||
else:
|
||||
# 如果列不存在,创建一个全False的Series(不允许入场)
|
||||
self.strategy_log(f"[{metadata['pair']}] 警告:ema_5_1h或ema_20_1h列不存在,过滤条件设为False")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user