//+------------------------------------------------------------------+//| DELETE PENDING ORDERS |//+------------------------------------------------------------------+void deletePendingOrder(int ordertype)
{
int res;
//--- variables for returning values from order propertiesulong ticket;
double open_price;
double initial_volume;
datetime time_setup;
string symbol;
int type;
int order_magic;
long positionID;
uint total=OrdersTotal();
string comment;
//--- go through orders in a loop//Print("total orders "+total);int count=0;
ulong ticktsToDelete[];
ArrayResize(ticktsToDelete,total);
for(uint i=0; i<total; i++)
{
//--- return order ticket by its position in the list
ticket=OrderGetTicket(i);
if(OrderSelect(ticket))
{
//--- return order properties
open_price =OrderGetDouble(ORDER_PRICE_OPEN);
time_setup =(datetime)OrderGetInteger(ORDER_TIME_SETUP);
symbol =OrderGetString(ORDER_SYMBOL);
order_magic =(int)OrderGetInteger(ORDER_MAGIC);
comment = OrderGetString(ORDER_COMMENT);
positionID =OrderGetInteger(ORDER_POSITION_ID);
initial_volume=OrderGetDouble(ORDER_VOLUME_INITIAL);
type =(int)OrderGetInteger(ORDER_TYPE);
//Alert("symbol "+symbol+" order_magic"+order_magic+" comment "+comment);Print(ticket+ " (symbol==selectedSymbol)="+ " type="+type +" ordertype= "+ordertype);
if(symbol==selectedSymbol && order_magic==MAGIC_NUMBER && type==ordertype)
{
ticktsToDelete[count++]=ticket;
}
}
}
for(uint i=0; i<count; i++)
{
if(!m_trade.OrderDelete(ticktsToDelete[i]))
Alert("Could not delete pending order for ");
}
}
After a lots of research and brainstorming this is my solution. But before the solution I would like to tell the problem of the using this code given by phi, which is the below code
It will delete running loop trade which causes problem when you have lots of pending orders. it may not delete all pending orders . so better to store the tickts of pending orders and delete them in a separate loop
The pending has the slight advantage, A) you are closer to the top of the queue (filled quicker), B) there's no round trip network delay (filled quicker.)
Don't worry about it unless you're scalping M1 or trading news.
Humans can't watch the screen 24/7, so they use pending orders; EAs can, so no need for pending orders, have it wait until the market reaches the trigger price and just open an order.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
It will delete running loop trade which causes problem when you have lots of pending orders. it may not delete all pending orders . so better to store the tickts of pending orders and delete them in a separate loop
Alternative code.
Forum on trading, automated trading systems and testing trading strategies
Delete pending orders on deInit
fxsaber, 2023.06.06 17:41
There is no need to create pending orders in code.
The pending has the slight advantage, A) you are closer to the top of the queue (filled quicker), B) there's no round trip network delay (filled quicker.)
Don't worry about it unless you're scalping M1 or trading news.
Humans can't watch the screen 24/7, so they use pending orders; EAs can, so no need for pending orders, have it wait until the market reaches the trigger price and just open an order.