what's wrong here? (close and delet several opened and pending orders )

 

I'm Intended use OrderClose and OrderDelete functions, with a system that can open multiple operations.
What's wrong here?:

(condition1=entry, condition2=other entry, condition3=exit)


if (condition1==true)
{
ordersend(OP_BUY...)
OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
ordersend(OP_BUYSTOP...)
OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
}
if (condtion2==true)
{
OrderSend(OP_SELLSTOP...)
OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
}

if (condition3==true && OrdersTotal()>1)
{
while (OrdersTotal()>0)
{
if (OrdersTotal()>0)
OrderClose(OrderTicket(),OrderLots(),Bid,3,CLR_NONE);
}
{
if (OrdersTotal()>0)
OrderDelete(OrderTicket());
}
}


the MT4 test giveme error: wrong ticket in orderdelet.

The idea is if last condition is true, stay between orderclose and orderdelete until they are all closed and removed

thanks

trader201

 
for(int i=OrdersTotal()-1;i>=0;i--)
{
 OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if (condition1==true)
{
 buyticket=OrderSend(OP_BUY...)
 buystopticket=OrderSend(OP_BUYSTOP...)
}
if (condtion2==true)
{
 sellstopticket=OrderSend(OP_SELLSTOP...)
}
if (condition3==true && OrdersTotal()>0)
{
 OrderClose(buyticket,OrderLots(),Bid,3,CLR_NONE); 
 OrderDelete(buystopticket);
 OrderDelete(selltopticket);
}
}
maybe something like this?
 
ido370:
maybe something like this?


Hello ido370. The problem persist. Still say: "invalid ticket for orderclose function"

Thanks

Reason: