Need help closing orders

 

I ran into a problem that I dont know how to solve. My program has a few open orders and closes them all together but sometimes I think that some of the orders are not filled therefore it keeps waiting till they are filled and that locks up my program. What have you guys found to be the best way to close all open orders? Thank you kindly for your help.

DT

 
Show your code...
 
phy:
Show your code...


Here is the code, for some reason it leaves some open orders from the total and then it just stops working all together. Thank you in advance for the help.

here is the code:



int OrdersTotalLong()
{
int order_total = 0;

for (int i = 0; i < OrdersTotal(); i++)
{
OrderSelect(i,SELECT_BY_POS, MODE_TRADES);
if (OrderType() == OP_BUY)
order_total++;
}
return(order_total);
}

int MaxLongOrder()
{
int order = 0;
double lotsbuyed = 0;

for (int i = 0; i < OrdersTotal(); i++)
{
OrderSelect(i,SELECT_BY_POS, MODE_TRADES);
if ((OrderType() == OP_BUY) && (OrderLots() > lotsbuyed))
{
lotsbuyed = OrderLots();
order = i;
}
}
return(order);
}


int CloseLong()
{
while (OrdersTotalLong() > 0) //until there's no Orders open (close all)
{
if (OrderSelect(MaxLongOrder(), SELECT_BY_POS, MODE_TRADES) == false) continue;


OrderClose(OrderTicket(),OrderLots(), Bid, 3, Green);
}


}
return(0);
}

 

Here is the code, any help greatly appreciated.