How to close all Pending orders in same time in Mt5

 

Hello,


I would like to close all pending orders in same time.

i tried with open positions and succeeded but dont now how to do with open pending orders.

this is my code for open positions:


    
    num_positions=mt.positions_total()
    symbol_info=mt.symbol_info("EURUSD")
    symbol="EURUSD"
    volume=0.1
    positions=mt.positions_get()
    m=(5,6,7)
    x=mt.symbol_info_tick("EURUSD").ask
    z=mt.symbol_info_tick("EURUSD").bid 

       


    if num_positions in m :
        def  close_position_sell(position):
            tick=mt.symbol_info_tick(position.symbol)  
            request={ 
                "action": mt.TRADE_ACTION_DEAL, 
                "symbol":position.symbol, 
                "volume":position.volume,
                "type":mt.ORDER_TYPE_SELL,    
                "position":position.ticket,       
                "price":mt.symbol_info_tick("EURUSD").bid,
                "deviation":0,
                "comment": "python script close",
                "type_time": mt.ORDER_TIME_GTC,
                "Type_filling":mt.ORDER_FILLING_IOC,
            }

            result=mt.order_send(request)
            return result

        for position in positions:
            close_position_sell(position)



    if num_positions in m :
        def  close_position_sell(position):
            tick=mt.symbol_info_tick(position.symbol)  
            request={ 
                "action": mt.TRADE_ACTION_DEAL, 
                "symbol":position.symbol, 
                "volume":position.volume,
                "type":mt.ORDER_TYPE_BUY,    
                "position":position.ticket,       
                "price":mt.symbol_info_tick("EURUSD").ask,
                "deviation":0,
                "comment": "python script close",
                "type_time": mt.ORDER_TIME_GTC,
                "Type_filling":mt.ORDER_FILLING_IOC,
            }

            result=mt.order_send(request)
            return result

        for position in positions:
            close_position_sell(position)
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Order Properties - Trade Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
josip2247: I would like to close all pending orders in same time. i tried with open positions and succeeded but dont now how to do with open pending orders. this is my code for open positions:


You don't close Orders, you remove them with the "TRADE_ACTION_REMOVE" action.

You also have to get them from the Orders and not the Positions, using orders_get, from the total orders available with orders_total.

EDIT: Please note that the links I have provided are for Python code integration, given that your code sample is in Python.

 

Thank you!