Breakout-System - Cancel Order

 

Hi,

I need some help.

I designed a simple Breakoutsystem, which generates two orders like the following:

Ticket = OrderSend(Symbol(),OP_BUYSTOP,Lots,kauf_stopp_preis,3,kauf_stopp_preis-anfangs_stopp,kauf_stopp_preis +TakeProfit*Point,NULL,Magic1,TradeTime+EndHour*60*60,Blue); //TradeTime+EndHour*60*60

Ticket = OrderSend(Symbol(),OP_SELLSTOP,Lots,verkauf_stopp_preis,3,verkauf_stopp_preis+anfangs_stopp,verkauf_stopp_preis-TakeProfit*Point,NULL,Magic2,TradeTime+EndHour*60*60,Red); //TradeTime+EndHour*60*60

So there are two order to get stopped into the market.

If one of them gets executet, the other order must bedeleted.

Can I delete an order by using the MagicNumber?

If that works, can somebody tell me the code???

Thanks

 

Here you can test simple version of it.

EURUSD only.

Initial-Stop 45...65 - optimum 60

TakeProfit 20 ... 35 - optimum 30

TF daily only.

Files:
orbsv.ex4  8 kb
 

int mgc=87697;

int total=OrdersTotal();

bool cancelorder=false;

for(cnt=0;cnt<total;cnt++) {

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if((OrderMagicNumber()==mgc) && (OrderType()==OP_BUY || OrderType()==OP_SELL)) cancelorder=true;

}

if(cancelorder) {

for(cnt=0;cnt<total;cnt++) {

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if((OrderMagicNumber()==mgc) && (OrderType()==OP_BUYSTOP || OrderType()==OP_SELLSTOP)) OrderDelete(OrderTicket());

}

}

 

THANKS!!!

Reason: