5 Ambil chart ini Ambil chart ini import MetaTrader5 as mt5 # เชื่อมต่อกับเซิร์ฟเวอร์ MetaTrader 4 if not mt5.initialize(): print("initialize() failed") mt5.shutdown() # ดึงราคาปัจจุบันของ EURUSD symbol = "EURUSD" rates = mt5.copy_rates_from_pos(symbol, mt5.TIMEFRAME_M1, 0, 1) if rates is None: print("copy_rates_from_pos() failed") mt5.shutdown() current_price = rates[0][4] print("Current price of", symbol, ":", current_price) # ส่งคำสั่งซื้อ Buy หรือ Sell action = mt5.ORDER_BUY lot = 0.1 price = current_price request = { "action": action, "symbol": symbol, "volume": lot, "price": price, "type": mt5.ORDER_TYPE_MARKET, "deviation": 20, "magic": 234000, "comment": "Python bot order", "type_time": mt5.ORDER_TIME_GTC, "type_filling": mt5.ORDER_FILLING_FOK } result = mt5.order_send(request) if result.retcode != mt5.TRADE_RETCODE_DONE: print("order_send() failed with retcode:", result.retcode) mt5.shutdown() mt5.shutdown()
Pernyataan Penyangkalan Informasi dan publikasi tidak dimaksudkan untuk menjadi, dan bukan merupakan saran keuangan, investasi, perdagangan, atau rekomendasi lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di
Persyaratan Penggunaan .