MT5 || python: closing pending order after x minutes

1.2k Views Asked by At

I am using python connected to MT5, and have manage to load pending order with sl, tp, etc. I am now having problem expiring the pending order after 30 min, maybe, how do I put it in the request section? I have tried mt5.ORDER_TIME_SPECIFIED_DAY but nothing happen, though I prefer a much shorter time countdown. I have done it with *.mq5, but unsuccessful with python. Please help!!!

request = {
        'action':       mt5.TRADE_ACTION_PENDING,
        'symbol':       sym,
        'volume':       LotSize,
        'type':         signal,
        'price':        P_price,
        'sl':           P_SL,
        'tp':           P_TP,
        'comment':      '',
        'expiration':   mt5.ORDER_TIME_SPECIFIED_DAY,
        'type_filling': mt5.ORDER_FILLING_RETURN,
    }
    mt5.order_send(request)
1

There are 1 best solutions below

0
On

you need to change ->

"type_time": mt5.ORDER_TIME_SPECIFIED,
"expiration": expiration, 

This needs to be in a timestamp so for example in my code I have put variable there and defined it somewhere else. And then put it as an extra parameter. Or you can define it right in the code, whatever you prefer

expiration = int(datetime(2022, 8, 29, 16).timestamp())

Hope it helps..