I want my EA to check and make sure that it can only have one pending order in the pool at any one time, so I wrote the following code to do that:
int CheckOrders()
{
//----
int i,orders;
int tickets[];
//----
int ticket = 0;
int total = OrdersTotal();
//----
for(i=total;i>=0;i--) tickets[i] = 0;
//----
for(i=total;i>=0;i--){
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){
if(OrderMagicNumber()==magic_base && OrderType()>1){
orders++;
tickets[i] = OrderTicket();
Print("tickets = ",tickets[i]);
}
}
}
Print("total = ",total," orders = ",orders);
while(orders>1){
for(i=total;i>=0;i--){
if(ticket==0 && tickets[i]>0) ticket = tickets[i];
if(ticket>tickets[i]) ticket = tickets[i];
}
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)){
OrderDelete(ticket);
}
orders--;
}
Print("ticket = ",ticket);
//----
return(0);
}
It displays the number of pending orders in the pool by the same EA correctly, but it won't delete the unwanted pending orders, because it always shows that tickets[i] = 0. and because of this, the OrderDelete(ticket) won't work. Could sb please tell me why this would happen?
int CheckOrders()
{
//----
int i,orders;
int tickets[];
//----
int ticket = 0;
int total = OrdersTotal();
//----
for(i=total;i>=0;i--) tickets[i] = 0;
//----
for(i=total;i>=0;i--){
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){
if(OrderMagicNumber()==magic_base && OrderType()>1){
orders++;
tickets[i] = OrderTicket();
Print("tickets = ",tickets[i]);
}
}
}
Print("total = ",total," orders = ",orders);
while(orders>1){
for(i=total;i>=0;i--){
if(ticket==0 && tickets[i]>0) ticket = tickets[i];
if(ticket>tickets[i]) ticket = tickets[i];
}
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)){
OrderDelete(ticket);
}
orders--;
}
Print("ticket = ",ticket);
//----
return(0);
}
It displays the number of pending orders in the pool by the same EA correctly, but it won't delete the unwanted pending orders, because it always shows that tickets[i] = 0. and because of this, the OrderDelete(ticket) won't work. Could sb please tell me why this would happen?