
等级: 新手上路
- 注册:
- 2025-4-17
- 曾用名:
|

楼主 |
发表于 2025-4-29 10:40
|
显示全部楼层
# 空头开仓(均线死叉)
short_entry_condition = (
ma_short[-1] < ma_long[-1] and # 死叉条件
ma_short[-2] >= ma_long[-2] and # 确认信号
rsi_filter and # 避免超卖区
atr[-1] > np.mean(atr[-5:-1]) * 0.7 # 波动率放大
)
if short_entry_condition: # 上一周期未死叉
sell_volume = min(132, unit)
print(f"[空头开仓] 价格:{last_price:.2f}, 数量:{sell_volume}, 短期MA:{ma_short[-1]:.2f}, 长期MA:{ma_long[-1]:.2f}, RSI:{rsi[-1]:.2f}")
sell_open(context.s1, "market", volume=sell_volume,serial_id = 3)
context.sell_price_history.append(last_price)
if len(context.sell_price_history) > context.max_hold_periods_short:
context.sell_price_history.pop(0)
# === 多头交易逻辑 ===
# 关键价格
X_high = high[:-1].max()
Y_low = low[-context.Y-1:-1].min()
# 多头开仓
if high[-1] >= 0.993*X_high:
print(f"[多头开仓] 价格:{last_price:.2f}, 数量:{unit}, X周期高点:{X_high:.2f}, ATR:{atr[-2]:.2f}")
buy_open(context.s1, "Market", 0, unit,serial_id = 4)
context.entry = atr[-2]
context.num = 1
context.enterprice = last_price |
|