We know already how to place a pending order. For this the OrderSend() function is used. Also we can modify parameters of pending orders with the help of the OrderModify() function.
In this article I will explain how a pending order can be deleted. This can be done by means of the OrderDelete() function.
bool OrderDelete(int ticket)
This function deletes a pending order with ticker ticket. The function returns true in case of successful deleting and false — in case an error emerges. The code of the error can be received by calling the GetLastError() function.
We will consider the usage of the OrderDelete() function by the following example:
Let’s suppose that our expert advisor according to some logic (we won’t go into details here) will place at once two pending orders in one instrument — Buy Limit and Sell Limit. Our task is to delete the remained pending order if one of them triggered.
We will suppose that only our expert advisor works in this instrument.
We’ll suppose that at the moment of placing of each pending order a magic number was set, the same for each pending order. And we’ll suppose that this magic number is stored in variable MyMagicNumber.
// we will look through all open positions and placed orders
int pos;
for(pos=0; posOP_SELL))
{
// the order is found – we’ll delete it
if (OrderDelete(OrderTicket()))
{
Print("Order deleted");
}
else
{
Print("Error ", GetLastError(), " at deleting order");
}
}
}
}
// exit the loop
break;
}
}
}
Next article: "
OrderClose function"