Is This Code Correct ?

Jean Francois Le Bas  

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

Vladimir Karputov  
Never use 'while' and 'Sleep' - you have to beat your hands for that.
Reason: