What is the wrong with this functions ?.

 

I want to check whether the pending orders are for the current symbol or not (both buy and sell pending orders, 

but the code does not work. I'm still learning MQL5, so I appreciate your help. 

bool NoBuyStopOrders()
{
    for (int i = 0; i < OrdersTotal(); i++)
    {
        if (OrderSelect(ORDER_TICKET))// Select order by ticked number
        {
            if (OrderGetInteger(ORDER_TYPE) == ORDER_TYPE_BUY_STOP)
            {
                return false; // Buy stop order  found
            }
        }
    }
    return true; // No buy stop order found
}


bool NoSellStopOrders()
{
    for (int i = 0; i < OrdersTotal(); i++)
    {
        if (OrderSelect(ORDER_TICKET))// Select order by ticked number
        {
            if (OrderGetInteger(ORDER_TYPE) == ORDER_TYPE_SELL_STOP)
            {
                return false; // Buy stop order  found
            }
        }
    }
    return true; // No buy stop found
}
MQL5 programming for traders - Book on MQL5.com
MQL5 programming for traders - Book on MQL5.com
  • www.mql5.com
Modern trading relies heavily on computer technology. Automation now extends beyond the boundaries of exchanges and brokerage offices, becoming...
 
Hapu Arachchilage Tharindu Lakmal:

I want to check whether the pending orders are for the current symbol or not (both buy and sell pending orders, 

but the code does not work. I'm still learning MQL5, so I appreciate your help. 

bool NoSellStopOrders()
{    
    int count=0;
    for (int i = 0; i < OrdersTotal(); i++)
    {
        ulong ticket=OrderGetTicket(i);      
        if (OrderSelect(ticket))// Select order by ticked number
        {
            if (OrderGetString(ORDER_SYMBOL) == Symbol()
               && OrderGetInteger(ORDER_TYPE) == ORDER_TYPE_SELL_STOP)
            {
                ++count;
            }
        }
    }
    return (count == 0); 
}
 
Cornelius Eichhorst #:
This loop should be in reverse, for reliability.

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