How do I automatically cancel an unfilled pending stop order before the strategy places another trade?

 

I have a stop limit order strategy I would like to program a way to automatically cancel an unfilled pending order placed by the strategy before it places a new order.

So automatically cancel the pending order at the open of the next bar for example OR if the price of the current bar (0) breaks above or below a certain price level (the high or low of a previous bar for example). 

 
EchoBay88: I have a stop limit order strategy I would like to program a way to automatically cancel an unfilled pending order placed by the strategy before it places a new order. So automatically cancel the pending order at the open of the next bar for example OR if the price of the current bar (0) breaks above or below a certain price level (the high or low of a previous bar for example). 

Assuming you mean in code, use the OrderSend function to issue a removal/deletion of the order in question. before placing the new order.

TRADE_ACTION_REMOVE

Delete the pending order placed previously

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
 
Fernando Carreiro #:

Assuming you mean in code, use the OrderSend function to issue a removal/deletion of the order in question. before placing the new order.

TRADE_ACTION_REMOVE

Delete the pending order placed previously

Thank you Fernando, where exactly would I put that in my code to delete pending orders before the next order is placed?
 
EchoBay88 #: Thank you Fernando, where exactly would I put that in my code to delete pending orders before the next order is placed?
Do you know how to code?
 
Fernando Carreiro #:
Do you know how to code?
Learning to code
 
EchoBay88 #: Learning to code

Then unfortunately it is difficult for us to tell you where to put the code.

One would assume that if you already coded an EA that places orders, then you should already be familiar with how OrderSend works, and that you would simply execute the "remove" just before you place the new order using the same OrderSend function but with different request parameters.

Also, since you posted in the MQL5 section, my answer is relevant to MQL5 code. If however, your code is MQL4, then please let us know because MQL4 trade functions are completely different to MQL5.

Reason: