Why do you use MarketInfo instead Bid and Ask, if anyway "if (OrderSymbol() == Symbol())"?
OrderClose ( OrderTicket (), OrderLots (), OrderClosePrice (), 0 ) ;

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I had 5 or 6 open positions, when I executed the following routine.
All of the positions closed successfully except one Buy order, with the error "Invalid Trade Parameters"
Any ideas on the cause and possible solution?? Thank you.
void closeAllOrders()
{
int iOrders = OrdersTotal();
for(int i=iOrders-1; i>=0; i--)
{
OrderSelect(i, SELECT_BY_POS);
if (OrderSymbol() == Symbol())
{
int iType = OrderType();
bool bResult = false;
switch(iType)
{
//Close opened long positions
case OP_BUY : bResult = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),99,Blue);
break;
//Close opened short positions
case OP_SELL : bResult = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),99,Red);
break;
//Close pending orders
case OP_BUYLIMIT :
case OP_BUYSTOP :
case OP_SELLLIMIT :
case OP_SELLSTOP : bResult = OrderDelete( OrderTicket() );
}
if(bResult == false)
{
Alert("Order ",OrderTicket()," Failed to close. ",ErrorDescription(GetLastError()));
//Sleep(3000);
}
}
}
return(0);
}