# help with pending order !!

42

I try to delete a pending order when one of the 2 pending orders got hit but unstead the code is not deleting the pending order  at all

i dont understand why , my code is very simple and explicit here is the code.

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

{
continue;
}
{
result=OrderDelete(ticket,clrNONE);
Print("Error DELETING PENDING order : ", GetLastError());break;
}

if(ticket!=OP_SELL && ticket==OP_SELLSTOP )
{
continue;
}

else  if(ticket==OP_SELLSTOP && OP_SELL ==true)
{
result=OrderDelete(ticket,clrNONE);
Print("Error DELETING PENDING order : ", GetLastError());break;
}

}```
16096

1. ```for(int i=OrdersTotal()-1; i>=0; i--)
```
Why are you looping for the number of existing orders, when nothing inside the loop depends on i?
2. ```    else if(ticket==OP_BUYSTOP && OP_BUY==true)
{
result=OrderDelete(ticket,clrNONE);```
The constant OP_BUY equals zero and zero is equals false, so OP_BUY==true will never be true.
3. OrderDelete requires a ticket number (e.g. 567438948) So it will never be 4 (buy stop.)
4. ```else  if(ticket==OP_SELLSTOP && OP_SELL ==true)
{
result=OrderDelete(ticket,clrNONE);```
The constant OP_SELL equals one and non-zero is equals true, so OP_SELL==true will always be true.
5. OrderDelete requires a ticket number (e.g. 567438948) So it will never be 5 (sell stop.)
6. First you must find out if there are any open orders, then if any you must find and delete any pending orders. This can not be done in one loop. (pending higher position than open order.) Search about OrderSelect loop or read Loops and Closing or Deleting Orders - MQL4 forum
7. Humans can't watch the screen 24/7 so they use pending orders; EA's can. Why don't you wait until the market reaches your trigger price and open an order?
8. Matter of style.
 ```if(condition) {A} else if(condition2) {B} else {C} D```An if/else implies you do A (or B) or C and then continues with D. ```      if(ticket!=OP_BUY && ticket==OP_BUYSTOP)       {       continue;       }      else if(ticket==OP_BUYSTOP && OP_BUY==true)``` If A ends with a return, continue or break there is no A then D, so don't use the else. ```      if(ticket!=OP_BUY && ticket==OP_BUYSTOP)       {       continue;       }       // ticket can not be a OP_BUYSTOP here because you already continued.       if(ticket==OP_BUYSTOP && OP_BUY==true)```
9. Fix the indenting of your code.
42

thanks what you said sound logic i'm kind of new to this but  i will work on it .
42

Hi,

I finally did it !!!!!