OrderClose is driving me crazy!!!

 
Will somebody out there please help me before I toss MQL4 out the window. I have written a program for a simple EA. Everything works except for anything to do with OrderCLose. OrderSend works fine, but closing an order works intermittently. I must be missing something with OrderClose. My program only has one order open at any time, and so it can't be that hard for the server to close one simple order. However, the OrderClose works unpredictably. Sometimes it will close and other times it will not. How could this be? I've tried increasing the spread, but this does not give consistent results. Could somebody please provide me with a snippet of code that would guarantee my program will close an order every time I invoke the OrderClose function!! Thanks!!
 

Try this.

while(OrdersTotal()>0)
{
if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES))
{
OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),3,CLR_NONE);
}
}

 
cybernet69 wrote >>

Try this.

while(OrdersTotal()>0)
{
if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES))
{
OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),3,CLR_NONE);
}
}

Thanks for the code. I will try it.

 
forestmyopia wrote >>

Thanks for the code. I will try it.

Hey, the code works great! Thanks again!

 
Zero slippage will often cause an order close to be skipped. FWIW.
Reason: