Check Pending Order

 

Hi All,

I need some help here.

I'm trying to detect pending order of the same price so that I will not send same PO for the same price but it is not working

here is my code

double adjustpt = SymbolInfoDouble(_Symbol, SYMBOL_POINT);

//+------------------------------------------------------------------+
//| Check Pending Orders                                             |
//+------------------------------------------------------------------+
bool CheckPendingOrders(ENUM_ORDER_TYPE type, double price)
  {
//---

   for(int i = OrdersTotal() - 1; i >= 0; i--)
   {
      if(order.SelectByIndex(i) &&
         order.Symbol() == _Symbol &&
         order.Magic() == MagicNum &&
         order.OrderType() == type)
         {
            if(MathAbs(order.PriceOpen() - price) < 5 * adjustpt)   return(true);
         }
   }

//---
   return(false);
  }
 
Dua Yong Rew: I'm trying to detect pending order
There is no need to create pending orders in code.
  1. 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.)
  2. Don't worry about it unless you're scalping M1 or trading news.
  3. 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.
 
William Roeder #:
There is no need to create pending orders in code.
  1. 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.)
  2. Don't worry about it unless you're scalping M1 or trading news.
  3. 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.

Hi,

Thanks for the reply,

But I find working with pending order easier because my EA scan past bars and lay pending orders, if I were to check every now and then, it can be very CPU extensive.

Anyone has any idea?