# i have a hard time deleting a pending order !!

42

I got this code that send 2 pending orders than i got an other code where u try to delete the one that did not got hit unstead my code his deleting both pending orders before they get hit

here is the code:

for(int i=OrdersTotal()-1; i>=0; i--)
{
{
{
{

if(!OrderDelete(OrderTicket(),clrNONE)){ // <-- try to close the order
Print("Order Delete failed, order number: ",OrderTicket()," Error: ",GetLastError(), " On: ", OrderSymbol());
}
else{
Print("Pending Order was deleted: ", OrderTicket(), " On: ", OrderSymbol());
}

}
}
}
{
if(  OP_SELLSTOP>0)
{
if( OP_SELL>0)
{

if(!OrderDelete(OrderTicket(),clrNONE)){ // <-- try to close the order
Print("Order Delete failed, order number: ",OrderTicket()," Error: ",GetLastError(), " On: ", OrderSymbol());
}
else{
Print("Pending Order was deleted: ", OrderTicket(), " On: ", OrderSymbol());
}
}

}
}

}
15692

1.  Why are you comparing constants? Order Properties - Trade Constants - Standard Constants, Enumerations and Structures - MQL4 Reference if( OP_BUYSTOP>0     )           {              if( OP_BUY>0 ) You can only delete pending orders. When OrderType() > OP_SELL if( 4>0     ) // Always true           {              if( 0>0 ) // Never true.

2. if(!OrderSelect(i,SELECT_BY_POS, MODE_TRADES) == true) continue;
You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So Don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled. Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence.
42

Still does not work !!
Moderator
10638

mrgoodprice144:
Still does not work !!
Show what you have done
42

for(int i=OrdersTotal()-1; i>=0; i--)
{
{

{

if(!OrderDelete(OrderTicket(),clrNONE)){
Print("Order Delete failed, order number: ",OrderTicket()," Error: ",GetLastError(), " On: ", OrderSymbol());
}
else{
Print("Pending Order was deleted: ", OrderTicket(), " On: ", OrderSymbol());
}

}

{

if(  OP_SELL)
{

if(!OrderDelete(OrderTicket(),clrNONE)){
Print("Order Delete failed, order number: ",OrderTicket()," Error: ",GetLastError(), " On: ", OrderSymbol());
}
else{
Print("Pending Order was deleted: ", OrderTicket(), " On: ", OrderSymbol());
}
}

}

}
}
Whys is it  so comlicated to write a logical code i got 2 pending orders if one get hit the second one is deleted that 's it .
Moderator
10638

mrgoodprice144:
Whys is it  so comlicated to write a logical code i got 2 pending orders if one get hit the second one is deleted that 's it .

WHRoeder has already told you. Code like