- import MetaTrader5 as mt5
-
- if not mt5.initialize():
- print("MT5初始化失败")
- quit()
-
- positions = mt5.positions_get()
- for pos in positions:
- new_sl = 1.2000
- new_tp = 1.3000
- request = {
- "action": mt5.TRADE_ACTION_SLTP,
- "position": pos.ticket,
- "sl": new_sl,
- "tp": new_tp,
- }
- result = mt5.order_send(request)
- print(f"修改订单 {pos.ticket} 结果: {result}")
复制代码
|