English

## Orderselect - by ticket.

 Moderator3427 GumRai 2015.02.12 03:43 #   I don't know whether this is the simplest way, but it should work. I have not tested it.```//Function to find 2nd last order int Find2ndOrder()     {     int as=0;     int ot=OrdersTotal();     int ticketarray[];     ArrayResize(ticketarray,as,ot);     datetime datearray[];     ArrayResize(datearray,as,ot);     for(int x=ot-1;x>=0;x--)        {        if(OrderSelect(x,SELECT_BY_POS,MODE_TRADES))           if(OrderMagicNumber()==MagicNumber)              {              as++;              ArrayResize(ticketarray,as);              ticketarray[as-1]=OrderTicket();              ArrayResize(datearray,as);              datearray[as-1]=OrderOpenTime();              }        }     if(as<2)        return(0);     int index=ArrayMaximum(datearray,WHOLE_ARRAY,0);     datearray[index]=0;     index=ArrayMaximum(datearray,WHOLE_ARRAY,0);     return(ticketarray[index]);     }``` But at least it may give you something to think about. This obviously doesn't work with closed orders, you will need to modify if you need to include closed orders.
 13012 WHRoeder 2015.02.12 14:40 #   GumRai: I don't know whether this is the simplest way, but it should work.SimplerNot compiled, not tested```//Function to find nTh order int Find2ndOrder(int nTh=0){ // 0 last     int ticketarray[][2];  int count=0;     for(int x=OrdersTotal()-1;x>=0;x--) if(        OrderSelect(x,SELECT_BY_POS,MODE_TRADES))     && OrderMagicNumber()==MagicNumber     ){        ArrayResize(ticketarray,count+1);        ticketarray[count][0] = OrderOpenTime();        ticketarray[count][1] = OrderTicket();        ++count;     }     if(count