入场条件改成动态范围内具体值由get_market_trend来确定
This commit is contained in:
parent
caa068101d
commit
5c36aabec4
@ -9,27 +9,27 @@
|
||||
"max_open_trades": 5
|
||||
},
|
||||
"buy": {
|
||||
"ADD_POSITION_THRESHOLD": -0.011,
|
||||
"ADD_POSITION_THRESHOLD": -0.036,
|
||||
"BUY_THRESHOLD_MAX": -0.016,
|
||||
"BUY_THRESHOLD_MIN": -0.027,
|
||||
"COOLDOWN_PERIOD_MINUTES": 8,
|
||||
"MAX_ENTRY_POSITION_ADJUSTMENT": 2
|
||||
"BUY_THRESHOLD_MIN": -0.043,
|
||||
"COOLDOWN_PERIOD_MINUTES": 9,
|
||||
"MAX_ENTRY_POSITION_ADJUSTMENT": 3
|
||||
},
|
||||
"sell": {
|
||||
"EXIT_POSITION_RATIO": 0.587,
|
||||
"SELL_THRESHOLD_MAX": 0.067,
|
||||
"SELL_THRESHOLD_MIN": 0.012,
|
||||
"TRAILING_STOP_DISTANCE": 0.014,
|
||||
"TRAILING_STOP_START": 0.01
|
||||
"EXIT_POSITION_RATIO": 0.483,
|
||||
"SELL_THRESHOLD_MAX": 0.058,
|
||||
"SELL_THRESHOLD_MIN": 0.017,
|
||||
"TRAILING_STOP_DISTANCE": 0.011,
|
||||
"TRAILING_STOP_START": 0.012
|
||||
},
|
||||
"protection": {},
|
||||
"trailing": {
|
||||
"trailing_stop": true,
|
||||
"trailing_stop_positive": 0.213,
|
||||
"trailing_stop_positive_offset": 0.307,
|
||||
"trailing_only_offset_is_reached": false
|
||||
"trailing_stop_positive": 0.08,
|
||||
"trailing_stop_positive_offset": 0.092,
|
||||
"trailing_only_offset_is_reached": true
|
||||
}
|
||||
},
|
||||
"ft_stratparam_v": 1,
|
||||
"export_time": "2025-06-27 18:37:00.554316+00:00"
|
||||
"export_time": "2025-06-28 05:04:00.521861+00:00"
|
||||
}
|
||||
@ -270,32 +270,52 @@ class FreqaiPrimer(IStrategy):
|
||||
]
|
||||
|
||||
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||
"""
|
||||
生成买入信号,优化条件以增加交易机会
|
||||
"""
|
||||
pair = metadata.get('pair', 'Unknown')
|
||||
conditions = []
|
||||
|
||||
# 获取市场趋势得分
|
||||
trend_score = self.get_market_trend(dataframe=dataframe, metadata=metadata)
|
||||
|
||||
# 动态调整 cond2 和 cond3 的阈值
|
||||
# volume_z_score 阈值范围:0.5 (强牛市, trend_score=100) 到 2.0 (强熊市, trend_score=0)
|
||||
volume_z_score_min = 0.5
|
||||
volume_z_score_max = 2.0
|
||||
volume_z_score_threshold = self.linear_map(trend_score, 0, 100, volume_z_score_max, volume_z_score_min)
|
||||
|
||||
# rsi 阈值范围:40 (强牛市, trend_score=100) 到 60 (强熊市, trend_score=0)
|
||||
rsi_min = 40
|
||||
rsi_max = 60
|
||||
rsi_threshold = self.linear_map(trend_score, 0, 100, rsi_max, rsi_min)
|
||||
|
||||
if "&-price_value_divergence" in dataframe.columns:
|
||||
cond1 = (dataframe["&-price_value_divergence"] < self.buy_threshold)
|
||||
cond2 = (dataframe["volume_z_score"] > 1.5)
|
||||
cond3 = (dataframe["rsi"] < 45)
|
||||
cond2 = (dataframe["volume_z_score"] > volume_z_score_threshold)
|
||||
cond3 = (dataframe["rsi"] < rsi_threshold)
|
||||
cond4 = (dataframe["close"] <= dataframe["bb_lowerband"])
|
||||
buy_condition = cond1 & cond2 & cond3 & cond4
|
||||
conditions.append(buy_condition)
|
||||
|
||||
divergence_value = dataframe['&-price_value_divergence'].iloc[-1] if not dataframe['&-price_value_divergence'].isna().all() else np.nan
|
||||
volume_z_score_value = dataframe['volume_z_score'].iloc[-1] if not dataframe['volume_z_score'].isna().all() else np.nan
|
||||
rsi_value = dataframe['rsi'].iloc[-1] if not dataframe['rsi'].isna().all() else np.nan
|
||||
logger.debug(f"[{pair}] 买入条件检查 - "
|
||||
f"&-price_value_divergence < {self.buy_threshold:.6f}: {cond1.iloc[-1]}, "
|
||||
f"volume_z_score > 1.5: {cond2.iloc[-1]}, "
|
||||
f"rsi < 40: {cond3.iloc[-1]}, "
|
||||
f"close <= bb_lowerband: {cond4.iloc[-1]}")
|
||||
f"&-price_value_divergence={divergence_value:.6f} < {self.buy_threshold:.6f}: {cond1.iloc[-1]}, "
|
||||
f"volume_z_score={volume_z_score_value:.2f} > {volume_z_score_threshold:.2f}: {cond2.iloc[-1]}, "
|
||||
f"rsi={rsi_value:.2f} < {rsi_threshold:.2f}: {cond3.iloc[-1]}, "
|
||||
f"close={dataframe['close'].iloc[-1]:.6f} <= bb_lowerband={dataframe['bb_lowerband'].iloc[-1]:.6f}: {cond4.iloc[-1]}")
|
||||
else:
|
||||
logger.warning(f"[{pair}] ⚠️ &-price_value_divergence 列缺失,跳过该条件")
|
||||
logger.warning(f"[{pair}] ⚠️ &-price_value_divergence 列缺失,跳过买入信号生成")
|
||||
|
||||
if len(conditions) > 0:
|
||||
combined_condition = reduce(lambda x, y: x & y, conditions)
|
||||
if combined_condition.any():
|
||||
dataframe.loc[combined_condition, 'enter_long'] = 1
|
||||
logger.debug(f"[{pair}] 入场信号触发,条件满足")
|
||||
logger.info(f"[{pair}] 买入信号触发,条件满足,趋势得分:{trend_score:.2f}")
|
||||
else:
|
||||
logger.debug(f"[{pair}] 买入条件均不满足,未触发入场信号")
|
||||
logger.debug(f"[{pair}] 买入条件未满足,无买入信号")
|
||||
else:
|
||||
logger.debug(f"[{pair}] 无有效买入条件")
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user