how i can get the first ticket opned

 
double FirstOrderInfo(string Info,int type =-1)

  {
   for(int i =OrdersTotal() -1 ; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber && (OrderType()==type ||type==-1))
         
   
     {
      
      
    
       
         
        if(Info=="Type") return (OrderType());
      
       
       if(Info=="Price") return (OrderOpenPrice());
       
     
       
            

           }
     }
   return (0);

}



how i can get the first ticket opned ??

 
ALI AMRIOUI:

this cod give the Last Order Info but i wana to get  the First Order Info

 
int order=0;
datetime first=0;

double FirstOrderInfo(string Info,int type =-1)

  {
   for(int i =OrdersTotal() -1 ; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber && (OrderType()==type ||type==-1))
      
    if(first==0 || OrderOpenTime()<first)
    
    
    
    {
    
    first=OrderOpenTime();
      order=OrderTicket(); 
        
  if(Info=="Type"  ) return (OrderType());
  if(Info=="Price" ) return (OrderOpenPrice());
       
         
     }
     }
   return (0);

}

and if i do that .. then what worong ??
 
  1.  if(first==0 || OrderOpenTime()<first)

    This works, but you can simplify by just setting first to the maximum possible and removing the first test.

    #define  MAX_DATETIME   D'3000.12.31 23:59:59'
    #define  MIN_DATETIME   0  // Thu, 01 Jan 1970 00:00:00 GMT

  2. Go through your loop, and find the earliest order.

  3. Finally, after you have exited the loop and now know the earliest, you can return your value.
 
ALI AMRIOUI #: i found it ... its  work like that ... thanks friend

Your posted code is the same as your original. It does not "work like that"

 
William Roeder #:

Your posted code is the same as your original. It does not "work like that"

yes i test it  right now.. its donst work


what i should do??

 
William Roeder #:
  1. This works, but you can simplify by just setting first to the maximum possible and removing the first test.

  2. Go through your loop, and find the earliest order.

  3. Finally, after you have exited the loop and now know the earliest, you can return your value.

how i can use this code???

#define  MAX_DATETIME   D'3000.12.31 23:59:59'
#define  MIN_DATETIME   0  // Thu, 01 Jan 1970 00:00:00 GMT
 
ALI AMRIOUI #:

how i can use this code???

how i can know if the first ticket is buy or sell??

 
What part of "setting first to the maximum possible" was unclear?
 
William Roeder #:
What part of "setting first to the maximum possible" was unclear?
#define  MAX_DATETIME   D'3000.12.31 23:59:59'
#define  MIN_DATETIME   0  // Thu, 01 Jan 1970 00:00:00 GMT

int order=MIN_DATETIME;


double FirstOrderInfo(string Info,int type =-1)

  {
   for(int i =OrdersTotal() -1 ; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber && (OrderType()==type ||type==-1))
      
    if( order==OrderTicket() &&  OrderOpenTime()< MAX_DATETIME  )
    
    
    
    {
    
  
   
      
  if(Info=="Type"  ) return (OrderType());
  
  

  
  if(Info=="Price" ) return (OrderOpenPrice());
       
      
     }
     }
   return (0);

}


like that .. but still dont work
 
  1. Of course, that doesn't work. Order is not a datetime, and OrderOpenTime will always be less than MAX_DATETIME.

  2. datetime first=0;
    What part of "setting first to the maximum possible" was unclear?
Reason: