Get the ticket number of active trade for current symbol

 
I only have one trade a time per symbol trading. I need to get the ticket number of that trade for an OrderClose based on a function. How do I get the ticket number of this order?
 

MM

Something like this - OTTOMH :)

int ReturnFirstTicket(iMN int)
{
// Takes an input of MagicNumber

int icnt, itotal, iTicket;



itotal=OrdersTotal();

   for(icnt=0;icnt<itotal;icnt++) 
     {                               // order loop boundary
      OrderSelect(icnt, SELECT_BY_POS, MODE_TRADES);
      
       // check for opened position, symbol & MagicNumber
      if(OrderType()<=OP_SELL && OrderSymbol()==Symbol()  && OrderMagicNumber()==iMN)  // Open orders for pair on chart and the right Magic Number
        {     
         iTicket = OrderTicket();
         break;
        }
        

     }  // order loop boundary

return(iTicket);
     
}

Good Luck

-BB-

 
BarrowBoy:

MM

Something like this - OTTOMH :)

Good Luck

-BB-

Thanks for the help a while back BarrowBoy. I've got a new EA that trades more than one order a time. I need to pull up the last order that was placed. How would I do that?

 

Just create a loop, descending the order pool starting at OrdersTotal()-1 and ending at 0 selecting each order by position in the pool using OrderSelect().

Check the OrderOpenTime() for each order to determine which is the most recent.


CB


Reason: