How to deal with Re-Quotes?

 
Hi All,
I’m not sure how to handle re-quotes. I have the following code but it didn’t work as expected in forward testing. Could someone help?
Thank you,
StrangeGuy

extern int              NumberOfTries        = 10,
                           Slippage                  = 5;
....

void subCloseOrder()
{
   int
         cnt, 
         total       = 0,
         ticket      = 0,
         err         = 0,
         c           = 0;

   total = OrdersTotal();
   for(cnt=total-1;cnt>=0;cnt--)
   {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

      if(OrderSymbol()==Symbol() &&
         OrderMagicNumber()==MagicNumber)
      {
         switch(OrderType())
         {
            case OP_BUY      :
               for(c=0;c<NumberOfTries;c++)
               {
                  ticket=OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Violet);
                  err=GetLastError();
                  if(err==0)
                  { 
                     if(ticket>0) break;
                  }
                  else
                  {
                     if(err==0 || err==4 || err==136 || err==137 || err==138 || err==146) //Busy errors
                     {
                        Sleep(5000);
                        continue;
                     }
                     else //normal error
                     {
                        if(ticket>0) break;
                     }  
                  }
               }   
               break;
               
            case OP_SELL     :
               for(c=0;c<NumberOfTries;c++)
               {
                  ticket=OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Violet);
                  err=GetLastError();
                  if(err==0)
                  { 
                     if(ticket>0) break;
                  }
                  else
                  {
                     if(err==0 || err==4 || err==136 || err==137 || err==138 || err==146) //Busy errors
                     {
                        Sleep(5000);
                        continue;
                     }
                     else //normal error
                     {
                        if(ticket>0) break;
                     }  
                  }
               }   
               break;
               
            case OP_BUYLIMIT :
            case OP_BUYSTOP  :
            case OP_SELLLIMIT:
            case OP_SELLSTOP :
               OrderDelete(OrderTicket());
         }
      }
   }      
}



I received only one re-quote. The idea would be that I close at my ideal price. It should re-quote me at least (NumberOfTries) times until it reached my price (+/- Slippage). I wouldn’t want the EA to continue with this unresolved. Maybe loop?

2008.01.22 13:15:59 'x': requote 1.4603 / 1.4605 for order #xxxxx114 sell 1.00 EURUSDm closing at 1.4599
2008.01.22 13:15:57 'x': request was accepted by server
2008.01.22 13:15:50 'x': close order #xxxxx114 sell 1.00 EURUSDm at 1.4529 sl: 0.0000 tp: 0.0000 at price 1.4599

 
You need a RefreshRates() in your timed loops.

Whether that fixes your problem or not, I don't know. in fact, I don't know what your problem is.

What is your problem other than "but it didn’t work as expected " ?
 

You need a RefreshRates() in your timed loops.

Whether that fixes your problem or not, I don't know. in fact, I don't know what your problem is.

What is your problem other than "but it didn’t work as expected " ?


Thanks Phy, I will give the RefreshRates() a try but not sure if that is the issue.
Did you not read my text under the code? This text explains my problem.
 
No, it doesn't explain to me what you consider the problem.

Assuming you are buying to close the order, your max price is 1.4599+5 (slippage) = 1.4604, and the current quote was 1.4605
 
The point is that it only requoted one time as shown in the post. Yes, the requote was out of bounds but I should have received another quote at least (NumberOfTries) times until it reached my price (+/- Slippage). Right?
 
I don't know why, code "looks" ok, put in some debug statements to see where it goes next time.
 
Thanks for your input Phy and a second eye on the code. I will take your suggestion.
Reason: