cancelling one pending order when another one gets triggered

 

Hi,

Sorry for probably an easy question but I just started learning how to mql5.

Let's say I have two simple pending orders, a long and a short, waiting to get triggered


trade.BuyStop(0.1,longpriceentry,_Symbol,LTP,LSL,ORDER_TIME_GTC);

trade.SellStop(0.1,shortpriceentyr,_Symbol,STP,SSL,ORDER_TIME_GTC);


I would like to continuously check whether one of the two orders got through, determine which one was triggered (the long or the short) and immediately cancel the one which is still pending.


Could somebody help me with this insight? Do I write an IF statement within OnTick, and check the status with CPositionInfo Select method, and then do a trade.PositionClose ? But how do I know which one to close etc?


thanks in advance

//n00bie

 
giobenoni: I would like to continuously check whether one of the two orders got through, determine which one was triggered (the long or the short) and immediately cancel the one which is still pending.

Unnecessary. There is no need to create pending orders in code.

  1. The pending has the slight advantage, A) you are closer to the top of the queue (filled quicker,) B) there's no round trip network delay (filled quicker.)
  2. Don't worry about it unless you're scalping M1 or trading news.
  3. Humans can't watch the screen 24/7, so they use pending orders; EAs can, so no need for pending orders, have it wait until the market reaches the trigger price and just open an order.
 
giobenoni :

Hi,

Sorry for probably an easy question but I just started learning how to mql5.

Let's say I have two simple pending orders, a long and a short, waiting to get triggered


trade.BuyStop(0.1,longpriceentry,_Symbol,LTP,LSL, ORDER_TIME_GTC );

trade.SellStop(0.1,shortpriceentyr,_Symbol,STP,SSL,ORDER_TIME_GTC);


I would like to continuously check whether one of the two orders got through, determine which one was triggered (the long or the short) and immediately cancel the one which is still pending.


Could somebody help me with this insight? Do I write an IF statement within OnTick, and check the status with CPositionInfo Select method, and then do a trade.PositionClose ? But how do I know which one to close etc?


thanks in advance

//n00bie

The simplest thing is to track (in OnTradeTransaction) the appearance of a new position. If a position has appeared, issue an order to delete pending orders.

 
Vladimir Karputov #:

The simplest thing is to track (in OnTradeTransaction) the appearance of a new position. If a position has appeared, issue an order to delete pending orders.

What if you have many pending orders, how would you select which pending order belongs to which one?