Check pendings

 

Hello, 

is this code ok for checking if there are pendings in mql5?

// Funzione per verificare se ci sono ordini limitati eseguiti

void CheckLimitOrders(double currentPrice)

{

    bool pendingLimits = false; // Flag per indicare se ci sono ordini limit pendenti


    for (int i = OrdersTotal() - 1; i >= 0; i--)

    {

        if (m_order.SelectByIndex(i))

        {

            if (m_order.Symbol() == m_symbol.Name() && m_order.Magic() == InpMagic)

            {

                if (m_order.Type() == ORDER_TYPE_BUY_LIMIT || m_order.Type() == ORDER_TYPE_SELL_LIMIT)

                {

                    if (m_order.State() == ORDER_STATE_STARTED || m_order.State() == ORDER_STATE_PLACED)

                    {

                        pendingLimits = true; // Ci sono ordini limit pendenti

                    }

                }

            }

        }

    }
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Requests to execute trade operations are formalized as orders. Each order has a variety of properties for reading. Information on them can be...
 
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 ).

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
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)

Reason: