BINANCE:BTCUSDT   Bitcoin / TetherUS
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
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()
Clause de non-responsabilité

Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.