For future:
bool CheckLimitOrders() { for (int i=0; i < OrdersTotal(); i++) { ulong ticket = OrderGetTicket(i); if(OrderSelect(ticket)) { if (OrderGetInteger(ORDER_MAGIC) == InpMagic && OrderGetString(ORDER_SYMBOL) == _Symbol && ticket != 0){ return true; break; } } } return false; }
tonyalcapon:
Hello,
is this code ok for checking if there are pendings in mql5?
bool CheckLimitOrders(double currentPrice) { bool pendingLimits = false; // Flag to indicate if there are executed pending limit orders for (int i = OrdersTotal() - 1; i >= 0; i--) { if (OrderSelect(i, SELECT_BY_POS) && OrderSymbol() == Symbol() && OrderMagicNumber() == InpMagic) { if (OrderType() == ORDER_TYPE_BUY_LIMIT || OrderType() == ORDER_TYPE_SELL_LIMIT) { if (OrderState() == ORDER_STATE_FILLED) { // Found an executed pending limit order pendingLimits = true; break; // No need to continue loop if we found an executed pending limit order } } } } return pendingLimits; // Return whether there are executed pending limit orders }OrderSelect is used to select each order.
OrderSymbol() and OrderMagicNumber() are used to check if the order belongs to the current symbol and has a specific magic number (if applicable).
OrderType() is used to check the type of the order (buy limit or sell limit).
OrderState() is used to check if the order has been executed ( ORDER_STATE_FILLED ).
Nardus Van Staden #:
OrderSelect is used to select each order.
OrderSymbol() and OrderMagicNumber() are used to check if the order belongs to the current symbol and has a specific magic number (if applicable).
OrderType() is used to check the type of the order (buy limit or sell limit).
OrderState() is used to check if the order has been executed ( ORDER_STATE_FILLED ).
OrderSelect is used to select each order.
OrderSymbol() and OrderMagicNumber() are used to check if the order belongs to the current symbol and has a specific magic number (if applicable).
OrderType() is used to check the type of the order (buy limit or sell limit).
OrderState() is used to check if the order has been executed ( ORDER_STATE_FILLED ).
Thanks, i am still learning.
I find out that the following code is enough: OrdersTotal()
so:
<Improperly formatted code removed by moderator>
MQL5.community - User Memo
- www.mql5.com
You have just registered and most likely you have questions such as, "How do I insert a picture to my a message?" "How do I format my MQL5 source code?" "Where are my personal messages kept?" You may have many other questions. In this article, we have prepared some hands-on tips that will help you get accustomed in MQL5.community and take full advantage of its available features.
tonyalcapon #: i am still learning.
Please edit your post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum #25 (2019)
Messages Editor
Forum rules and recommendations - General - MQL5 programming forum (2023)
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
Hello,
is this code ok for checking if there are pendings in mql5?