In my mql4 Expert Advisor, I've written this function to close all the buy trades at once. When I test it via the Strategy Tester, it closes some buy trades, but for a few other buy trades it returns the: OrderClose error 4051:invalid ticket for OrderClose function
error.
void Close_All_Buy_Trdes(){
for (int i=0;i<=OrdersTotal();i++){
OrderSelect(i,SELECT_BY_POS);
if(OrderType()==OP_BUY {
OrderClose(OrderTicket(),OrderLots(),Bid,3);
}
}
}
What is the reason for this happening?