-
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.
- 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.)
-
` OrderSelect(OrdersTotal()-1,SELECT_BY_POS,MODE_TRADES); //selecting tha last order
Magic number only allows an EA to identify its trades from all others. Using OrdersTotal/OrdersHistoryTotal (MT4) or PositionsTotal (MT5), directly and/or no Magic number/symbol filtering on your OrderSelect / Position select loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum (2013)
PositionClose is not working - MQL5 programming forum (2020)
MagicNumber: "Magic" Identifier of the Order - MQL4 Articles (2006)
Orders, Positions and Deals in MetaTrader 5 - MQL5 Articles (2011)
Limit one open buy/sell position at a time - General - MQL5 programming forum (2022) -
Do an OrderSelect loop and find if you have an open order. If you do, do another OrderSelect loop to find the pending order.
From my GUI/Trade Assistant EA: Indicators: Money Manager Graphic Tool - Risk Management - Articles, Library comments - MQL5 programming forum - Page 8 #80 (2022.02).
uint nAbove = 0, nBelow = 0; for(int iPos = OrdersTotal(); iPos > 0;) if( select_order(--iPos, SELECT_BY_POS, MODE_TRADES) && OrderType() > OP_SELL // Pending ) if(OrderOpenPrice() > Ask) ++nAbove; else ++nBelow; static bool isOCO = false; bool wasOCO = isOCO; isOCO = nAbove * nBelow != 0; Comment(""); if(isOCO) // Two pending Comment("OCO active"); else if(wasOCO) // One opened or tried. for(int iPos = OrdersTotal(); iPos > 0;) if( select_order(--iPos, SELECT_BY_POS, MODE_TRADES) && OrderType() > OP_SELL // Pending ){ int ticket = OrderTicket(); if(!OrderDelete(ticket)) Alert(StringFormat("OrderDelete(%i):%i", ticket, _LastError) ); }

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I need help bros. I have two pending orders in market. when one order is execute,the remaining pending order need to close. how can delete this pending order.
This code not work well, when one pending order execute as new order the remaining pending order not close immediately. plz help