How to define limit order with mt5.TRADE_ACTION_PENDING

bergen288  

I am trying to place XAUUSD order with Python/MetaTrader5 combination in my demo account.  When "action" is mt5.TRADE_ACTION_DEAL, it is a valid market order, but I am unhappy with large slippage.  So I changed the action to mt5.TRADE_ACTION_PENDING to place limit SELL order with price + DEVIATION.  

    request = {
        "action": mt5.TRADE_ACTION_PENDING,
        "symbol": symbol,
        "volume": volume,
        "type": action_type,
        "price": price,
        "deviation": DEVIATION,
        "sl": action_sl,
        "tp": action_tp,
        "magic": MAGIC_NUMBER,
        "comment": "Create position",
        "type_time": mt5.ORDER_TIME_DAY,
        "type_filling": mt5.ORDER_FILLING_IOC,
    }

Unfortunately, order is failed with return code 10013 (invalid request).  What do I miss in my request and how to fix it?  Thanks. 

1. order_send(): by XAUUSD 0.01 lots at 1806.76 with DEVIATION=1 points
2. order_send failed, retcode=10013
   retcode=10013
   deal=0
   order=0
   volume=0.0
   price=0.0
   bid=0.0
   ask=0.0
   comment=Invalid request
   request_id=2
   retcode_external=0
   request=TradeRequest(action=5, magic=123456789, order=0, symbol='XAUUSD', volume=0.01, price=1806.76, stoplimit=0.0, sl=1808.76, tp=1796.76, deviation=1, type=1, type_filling=1, type_time=1, expiration=0, comment='Create position', position=0, position_by=0)
       traderequest: action=5
       traderequest: magic=123456789
       traderequest: order=0
       traderequest: symbol=XAUUSD
       traderequest: volume=0.01
       traderequest: price=1806.76
       traderequest: stoplimit=0.0
       traderequest: sl=1808.76
       traderequest: tp=1796.76
       traderequest: deviation=1
       traderequest: type=1
       traderequest: type_filling=1
       traderequest: type_time=1
       traderequest: expiration=0
       traderequest: comment=Create position
       traderequest: position=0
       traderequest: position_by=0
quit
Vladimir Karputov  

What's happened

"type" : action_type,

?

Where is the printout of the value before sending the order?

bergen288  
Vladimir Karputov #:

What's happened

?

Where is the printout of the value before sending the order?

It’s either mt5.ORDER_TYPE_BUY or mt5.ORDER_TYPE_SELL depending on my condition. In my case above, it is Sell as confirmed by type=1.
Vladimir Karputov  
bergen288 # :
It’s either  mt5.ORDER_TYPE_BUY or  mt5.ORDER_TYPE_SELL depending on my condition. In my case above, it is Sell as confirmed by type=1.

Read MQL5 Help - pending order != position


Add: OrderSend

Documentation on MQL5: Trade Functions / OrderSend
Documentation on MQL5: Trade Functions / OrderSend
  • www.mql5.com
OrderSend - Trade Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
bergen288  
bergen288 #:
It’s either mt5.ORDER_TYPE_BUY or mt5.ORDER_TYPE_SELL depending on my condition. In my case above, it is Sell as confirmed by type=1.
Maybe I should use mt5.ORDER_TYPE_SELL_LIMIT along with TRADE_ACTION_PENDING.
Vladimir Karputov  
bergen288 #:
Maybe I should use mt5.ORDER_TYPE_SELL_LIMIT along with TRADE_ACTION_PENDING.

Yes!

bergen288  
Vladimir Karputov #:

Yes!

Now, my limit order works, but it is hard to get filled in demo account.  I hope real account will be much better.  Otherwise, I may be forced to go back to market order.


 Thanks.

Reason: