Pending Order Regarded As Live Order

 

Hi,

I'm facing a strange issue.

I have a "Flag" order, a Pending order (OP_BUYLIMIT / OP_SELLLIMIT) with a specific comment.

This order, could be triggered when market moves very quick, and my CloseOrders function closes this "triggered flag order", by checking with its OrderType, OP_BUY / OP_SELL.

However, MQL4 OrderClose function picks up the non-triggered order in my CloseOrders function, and keeps generating the error code 4108 with the message "pending order #179289705 cannot be closed".

00:09:46 H1SModelAuto USDCAD,H1: strH1SpanSideFlag = 3 // Taken from OrderType(); SELL Limit

00:09:46 H1SModelAuto USDCAD,H1: pending order #179290291 cannot be closed

00:09:46 H1SModelAuto USDCAD,H1: H1_CloseOrders(): OrderClose() function returned the error of 4108

SRC has been attached below.

else if(strComnt == strH1SpanSideFlag) is the place where it is checking the specific flag I'm talking about.

I also attached a screenshot that shows the pending order 179290291. (Time difference between server and local is 5 hours.)

If anybody has heard similar story and has any idea how I could avoid this problem, it would be much appreciated if you could share the information!  

 

void H1_CloseOrders()
{
   int ordSide, ticket, total, i, errCode; //, OrdHour, CurHour;
   double settPrice;
   bool bClose, bDelete;
   string strComnt;
   errCode = 0;  
   total = OrdersTotal();
   if (total > 0)
   {
      for (i = 0; i < total; i++)
      {
         bClose = bDelete = false;
         if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == true)
         {
            if (OrderSymbol()==chartSymb)   
            {      
               if ((ordSide == OP_BUY) || (ordSide == OP_SELL)) //Excluding Pending Orders OP_BUYLIMIT & OP_SELLLIMIT
               { 
                  strComnt = OrderComment();                   
                  if(strComnt == strAdjFlag)
                  {
                     if (ordSide == OP_BUY)
                     {
                        if ((Open[0] > Close[0]) && (UpperBuffer1[0] > Close[0]))
                        {
                           bClose = true; RefreshRates(); settPrice = Bid;
                           CloseJunkouOrders();                   
                        }
                     }
                     else if (ordSide == OP_SELL)
                     {
                        if ((Open[0] < Close[0]) && (LowerBuffer1[0] < Close[0]))
                        {
                           bClose = true; RefreshRates(); settPrice = Ask;
                           CloseJunkouOrders();                           
                        }
                     }                     
                  }                  
                  else if (strComnt == strSpanChg)
                  {
                     if (ordSide == OP_BUY)
                     {
                        if ((MovingBuffer9[2] > MovingBuffer21[2]) && (MovingBuffer9[0] < MovingBuffer21[0]))
                        {bClose = true; settPrice = Bid;}
                     }
                     else if (ordSide == OP_SELL)
                     {
                        if ((MovingBuffer9[2] < MovingBuffer21[2]) && (MovingBuffer9[0] > MovingBuffer21[0]))
                        {bClose = true; settPrice = Bid;}
                     }                     
                  }
                  else if(strComnt == strH1SpanSideFlag)
                  {
                     Print("strH1SpanSideFlag = ", OrderType());
                     if (ordSide == OP_BUY)
                     {
                        if (curSpan == OP_SELL)
                        {
                           if (High[0] > MovingBuffer21[0]) {bClose = true; settPrice = Bid;}                           
                        }
                     }
                     else if (ordSide == OP_SELL)
                     {
                        if (curSpan == OP_BUY)
                        {
                           if (Low[0] < MovingBuffer21[0]) {bClose = true; settPrice = Ask;}
                        }
                        //else if (curSpan == OP_SELL) // Let tkProf to handle the order
                     }                     
                  }                                    
                  if (bClose == true)
                  {
                     ticket = OrderTicket();
                     
                     if (OrderClose(ticket, OrderLots(), settPrice, 3, clrNONE) == false) Print("H1_CloseOrders(): OrderClose() function returned the error of ", GetLastError());
                     else Print("Order Closed by H1_CloseOrders() function.");   
                  }
               }
            }
         }
      }
   }
}
 
miko.szy:

Hi,

I'm facing a strange issue.

I have a "Flag" order, a Pending order (OP_BUYLIMIT / OP_SELLLIMIT) with a specific comment.

This order, could be triggered when market moves very quick, and my CloseOrders function closes this "triggered flag order", by checking with its OrderType, OP_BUY / OP_SELL.

However, MQL4 OrderClose function picks up the non-triggered order in my CloseOrders function, and keeps generating the error code 4108 with the message "pending order #179289705 cannot be closed".

00:09:46 H1SModelAuto USDCAD,H1: strH1SpanSideFlag = 3 // Taken from OrderType(); SELL Limit

00:09:46 H1SModelAuto USDCAD,H1: pending order #179290291 cannot be closed

00:09:46 H1SModelAuto USDCAD,H1: H1_CloseOrders(): OrderClose() function returned the error of 4108

SRC has been attached below.

else if(strComnt == strH1SpanSideFlag) is the place where it is checking the specific flag I'm talking about.

I also attached a screenshot that shows the pending order 179290291. (Time difference between server and local is 5 hours.)

If anybody has heard similar story and has any idea how I could avoid this problem, it would be much appreciated if you could share the information!  

 

Hello. may be so? 

void H1_CloseOrders()
{
   int ordSide, ticket, total, i, errCode; //, OrdHour, CurHour;
   double settPrice;
   bool bClose, bDelete;
   string strComnt;
   errCode = 0;  
   total = OrdersTotal();
   if (total > 0)
   {
      for (i = 0; i < total; i++)
      {
         bClose = bDelete = false;
         if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == true)
         {
            if (OrderSymbol()==chartSymb)   
            {    
             ordSide=OrderType();
               if (ordSide<2) //Excluding Pending Orders OP_BUYLIMIT & OP_SELLLIMIT
               { 
                  strComnt = OrderComment();                   
                  if(strComnt == strAdjFlag)
                  {
                     if (ordSide == OP_BUY)
                     {
                        if ((Open[0] > Close[0]) && (UpperBuffer1[0] > Close[0]))
                        {
                           bClose = true; RefreshRates(); settPrice = Bid;
                           CloseJunkouOrders();                   
                        }
                     }
                     else if (ordSide == OP_SELL)
                     {
                        if ((Open[0] < Close[0]) && (LowerBuffer1[0] < Close[0]))
                        {
                           bClose = true; RefreshRates(); settPrice = Ask;
                           CloseJunkouOrders();                           
                        }
                     }                     
                  }                  
                  else if (strComnt == strSpanChg)
                  {
                     if (ordSide == OP_BUY)
                     {
                        if ((MovingBuffer9[2] > MovingBuffer21[2]) && (MovingBuffer9[0] < MovingBuffer21[0]))
                        {bClose = true; settPrice = Bid;}
                     }
                     else if (ordSide == OP_SELL)
                     {
                        if ((MovingBuffer9[2] < MovingBuffer21[2]) && (MovingBuffer9[0] > MovingBuffer21[0]))
                        {bClose = true; settPrice = Bid;}
                     }                     
                  }
                  else if(strComnt == strH1SpanSideFlag)
                  {
                     Print("strH1SpanSideFlag = ", OrderType());
                     if (ordSide == OP_BUY)
                     {
                        if (curSpan == OP_SELL)
                        {
                           if (High[0] > MovingBuffer21[0]) {bClose = true; settPrice = Bid;}                           
                        }
                     }
                     else if (ordSide == OP_SELL)
                     {
                        if (curSpan == OP_BUY)
                        {
                           if (Low[0] < MovingBuffer21[0]) {bClose = true; settPrice = Ask;}
                        }
                        //else if (curSpan == OP_SELL) // Let tkProf to handle the order
                     }                     
                  }                                    
                  if (bClose == true)
                  {
                     ticket = OrderTicket();
                     
                     if (OrderClose(ticket, OrderLots(), settPrice, 3, clrNONE) == false) Print("H1_CloseOrders(): OrderClose() function returned the error of ", GetLastError());
                     else Print("Order Closed by H1_CloseOrders() function.");   
                  }
               }
            }
         }
      }
   }
}
 

Hi Boeing747,

 Thanks a lot!

It beautifully worked! ;)