Setting Expiration To Pending Order Alternative?

 

My broker doesn't allow setting expiration dates on pending orders unfortunately (Error 147).

Is there an alternative to remove an order at x minutes if it didn't get filled?

I was thinking I could do the following:

  • Use OrderSend with no expiration date set
  • Sleep for x minutes after sending order
  • Use OrderOpenTime to see if it opened (what does it return if it didn't open?)
  • If it's not opened, use OrderClose to remove it?

Do you guys know if this works?

Edit: If OrderDelete works successfully, it means that the order did not fill, correct?

 

Do you guys know if this works? Yes, (even without the sleep (unless u get no ticks)).

If OrderDelete works successfully, it means that the order did not fill, correct? Yes.

 

I just got it to work! And yes without Sleep and I mean that both programmatically and biologically at 3:40 am.

I realize when it's not filled yet the OrderType of the order is a Buy Stop or Sell Stop, but once it fills, the OrderType turns into a Buy or Sell, which gives me an easy conditional check to OrderDelete the order with success!

I didn't even need OrderCloseTime or OrderOpenTime.

 
:) congrats :)
Reason: