Open max order in MT5 using python script
Python
To control the order flow (e.g., 20 orders per second instead of 10), you can adjust the num_orders variable and the condition in the loop that checks the elapsed time. For example, to open 20 orders per second, you can modify the loop condition as follows:
Beforehand need to check limitations imposed by your broker.
import MetaTrader5 as mt5 import time # Initialize the MetaTrader 5 connection if not mt5.initialize(): print("initialize() failed, error code =", mt5.last_error()) quit() # Set the desired number of orders num_orders = 10 # Set the symbol and order parameters symbol = "EURUSD" lot = 0.1 order_type = mt5.ORDER_TYPE_BUY price = mt5.symbol_info_tick(symbol).ask # Start the timer start_time = time.time() # Open the orders for i in range(num_orders): request = { "action": mt5.TRADE_ACTION_DEAL, "symbol": symbol, "volume": lot, "type": order_type, "price": price, "magic": 123456, "comment": "Python script order", "type_time": mt5.ORDER_TIME_GTC, "type_filling": mt5.ORDER_FILLING_IOC, } result = mt5.trade_send_order(request) if result.retcode != mt5.TRADE_RETCODE_DONE: print(f"Order {i + 1} failed to open, error code: {result.retcode}") else: print(f"Order {i + 1} opened successfully, order ID: {result.order}") # Check if one second has elapsed elapsed_time = time.time() - start_time if elapsed_time >= 1.0: break # Shut down the MetaTrader 5 connection mt5.shutdown()
To control the order flow (e.g., 20 orders per second instead of 10), you can adjust the num_orders variable and the condition in the loop that checks the elapsed time. For example, to open 20 orders per second, you can modify the loop condition as follows:
elapsed_time = time.time() - start_time if elapsed_time >= 1.0 / 20: # Open a new order every 1/20 of a second break
Beforehand need to check limitations imposed by your broker.
Hi guys,
How can I open 10 or 20 orders in one second in MT5 using the python API? and how can i control this folow, I mean (10 orders per second or 20 ....etc)
Many thanks in advance