绿色通道入场机制
This commit is contained in:
parent
144ab6a899
commit
b81b2ce2e1
@ -587,8 +587,25 @@ class FreqaiPrimer(IStrategy):
|
||||
|
||||
# 根据趋势状态调整入场策略
|
||||
if "&-price_value_divergence" in dataframe.columns:
|
||||
if trend_status == "bullish":
|
||||
# 上涨趋势:放宽入场条件,允许追高
|
||||
# 检测当前持仓订单数量(用于绿色通道判断)
|
||||
open_trades = len(self.active_trades) if hasattr(self, 'active_trades') else 0
|
||||
is_green_channel = (trend_status == "bullish" and open_trades <= 2)
|
||||
|
||||
if is_green_channel:
|
||||
# 🟢 牛市绿色通道:持仓≤2个,25USDT入场,5条件满足3个即可
|
||||
cond1 = (dataframe["&-price_value_divergence"] < self.buy_threshold * 1.8) # 超宽松偏离度
|
||||
cond2 = (dataframe["volume_z_score"] > volume_z_score_threshold * 0.4) # 超低成交量要求
|
||||
cond3 = (dataframe["rsi"] < rsi_threshold * 1.4) # 超宽松RSI
|
||||
cond4 = (dataframe["close"] <= dataframe["bb_upperband"] * 1.05) # 允许上轨附近
|
||||
cond5 = (dataframe["stochrsi_k"] < stochrsi_threshold * 1.4) # 超宽松STOCHRSI
|
||||
|
||||
core_conditions = [cond1, cond2, cond3, cond4, cond5]
|
||||
satisfied_count = sum([c.iloc[-1] for c in core_conditions])
|
||||
buy_condition = satisfied_count >= 3
|
||||
logger.info(f"[{pair}] 🟢 牛市绿色通道:持仓{open_trades}≤2个,25USDT入场,5条件满足{satisfied_count}/3个")
|
||||
|
||||
elif trend_status == "bullish":
|
||||
# 牛市正常通道:持仓>2个,75USDT入场,必须满足全部7个条件
|
||||
cond1 = (dataframe["&-price_value_divergence"] < self.buy_threshold * 1.5) # 放宽到1.5倍
|
||||
cond2 = (dataframe["volume_z_score"] > volume_z_score_threshold * 0.7) # 降低成交量要求
|
||||
cond3 = (dataframe["rsi"] < rsi_threshold * 1.2) # 放宽RSI要求
|
||||
@ -596,7 +613,20 @@ class FreqaiPrimer(IStrategy):
|
||||
cond5 = (dataframe["stochrsi_k"] < stochrsi_threshold * 1.2) # 放宽STOCHRSI要求
|
||||
cond6 = pd.Series([True] * len(dataframe), index=dataframe.index) # 取消熊市过滤
|
||||
cond7 = pd.Series([True] * len(dataframe), index=dataframe.index) # 取消超买过滤
|
||||
logger.info(f"[{pair}] 🚀 上涨趋势策略:放宽入场条件")
|
||||
buy_condition = cond1 & cond2 & cond3 & cond4 & cond5 & cond6 & cond7
|
||||
logger.info(f"[{pair}] 🚀 牛市正常通道:持仓{open_trades}>2个,75USDT入场,必须满足全部7个条件")
|
||||
|
||||
else:
|
||||
# 熊市/震荡:严格标准,75USDT入场,必须满足全部7个条件
|
||||
cond1 = (dataframe["&-price_value_divergence"] < self.buy_threshold * 0.7) # 严格到0.7倍
|
||||
cond2 = (dataframe["volume_z_score"] > volume_z_score_threshold * 1.3) # 提高成交量要求
|
||||
cond3 = (dataframe["rsi"] < rsi_threshold * 0.8) # 严格RSI要求
|
||||
cond4 = (dataframe["close"] <= dataframe["bb_lowerband"] * 0.95) # 必须跌破下轨
|
||||
cond5 = (dataframe["stochrsi_k"] < stochrsi_threshold * 0.8) # 严格STOCHRSI要求
|
||||
cond6 = ~bearish_signal_aligned # 保持熊市过滤
|
||||
cond7 = ~stochrsi_overbought_aligned # 保持超买过滤
|
||||
buy_condition = cond1 & cond2 & cond3 & cond4 & cond5 & cond6 & cond7
|
||||
logger.info(f"[{pair}] 📉 熊市/震荡通道:75USDT入场,必须满足全部7个条件")
|
||||
|
||||
elif trend_status == "bearish":
|
||||
# 下跌趋势:严格入场条件,只抄底
|
||||
@ -620,7 +650,7 @@ class FreqaiPrimer(IStrategy):
|
||||
cond7 = ~stochrsi_overbought_aligned
|
||||
logger.info(f"[{pair}] ⚖️ 震荡趋势策略:标准入场条件")
|
||||
|
||||
buy_condition = cond1 & cond2 & cond3 & cond4 & cond5 & cond6 & cond7
|
||||
# 绿色通道和趋势状态的条件已经设置好buy_condition
|
||||
conditions.append(buy_condition)
|
||||
|
||||
# 调试日志
|
||||
@ -867,9 +897,20 @@ class FreqaiPrimer(IStrategy):
|
||||
hold_time = (current_time - trade.open_date_utc).total_seconds() / 60
|
||||
profit_ratio = (current_rate - trade.open_rate) / trade.open_rate
|
||||
|
||||
initial_stake_amount = trade.stake_amount / 3
|
||||
logger.info(f"{pair} 首次入场金额: {initial_stake_amount:.2f}, 当前持仓金额: {trade.stake_amount:.2f}, "
|
||||
f"加仓次数: {trade.nr_of_successful_entries - 1}, 趋势得分: {trend_score:.2f}")
|
||||
# 检测当前持仓订单数量
|
||||
open_trades = len(self.active_trades) if hasattr(self, 'active_trades') else 0
|
||||
|
||||
# 牛市绿色通道判断:持仓≤2个且牛市趋势
|
||||
is_green_channel = (trend_status == "bullish" and open_trades <= 2)
|
||||
|
||||
# 根据绿色通道调整入场金额
|
||||
if is_green_channel:
|
||||
initial_stake_amount = 25.0 # 绿色通道:25USDT入场
|
||||
logger.info(f"{pair} 🟢 牛市绿色通道:25USDT入场,当前持仓{open_trades}个")
|
||||
else:
|
||||
initial_stake_amount = 75.0 # 正常通道:75USDT入场
|
||||
logger.info(f"{pair} 首次入场金额: {initial_stake_amount:.2f}, 当前持仓金额: {trade.stake_amount:.2f}, "
|
||||
f"加仓次数: {trade.nr_of_successful_entries - 1}, 趋势得分: {trend_score:.2f}")
|
||||
|
||||
# 检测趋势状态
|
||||
trend_status = self.detect_trend_status(dataframe, {'pair': pair})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user