Is This Code Correct ?

 

Hi

I just figured out the way to properly test if orders were closed the right way, but i'm wondering if the code is correct (because it accounts for situations when there are requotes and I can't simulate that)

and what could be done to improve the code ?


thanks so much


#define numRetriesOrder 5
bool CloseAll()
{
   uint retcode = 0;
   int nRetries = numRetriesOrder;         
   while (retcode != TRADE_RETCODE_DONE && nRetries > -1)
   {
      if (nRetries < numRetriesOrder)
         Sleep(100);
         
      CloseAll(myTrade);
      
      nRetries--;            
   }
   
   if (retcode == TRADE_RETCODE_DONE)
      return true;
      
   return false;
} 

void CloseAll(CTrade& myTrade)
{
   ulong ticket;
   
   bool ret = false;
   
   int total = PositionsTotal();
   for(int j=total-1;j>=0;j--)
   {
      if ((ticket=PositionGetTicket(j))>0)
      {  
         PositionSelectByTicket(ticket);   
         
         if (PositionGetInteger(POSITION_MAGIC) == Magic)
         {
            myTrade.PositionClose(ticket,-1); 
         }
      }
   } 
}


Jeff

 
nobody to help me ? ....
 
Never use 'while' and 'Sleep' - you have to beat your hands for that.
 
Vladimir Karputov:
Never use 'while' and 'Sleep' - you have to beat your hands for that.

thanks so much Vladimir

ok so I think i can just remove the sleep function

so for the buys it will retry N times

but for the close, I need to set a higher number, because while a buy can be skipped, a close cannot

thanks


Jeff