Get Ticket

 

Good afternoon mates. Today I am trying to get 2 pieces of data inside an Expert Advisor.

This EA works by averaging and I am interested in that, under certain conditions, the bot begins to close the first trade of the cycle (that is, it is more extreme), and the last one.


Before all this, I am trying to get the tickets for these trades. To get the ticket of the last one to open, I have defined it like this:

//+------------------------------------------------------------------+
//|      Function: Find the ticket of the last open trade            |
//+------------------------------------------------------------------+
int LastTradeTicket(int direction)
  {
   int LastTicket = 0;
   for(int i = OrdersTotal()-1; i >= 0; i--)
     {
      if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
         continue;
      if(OrderType() > 1)
         continue;
      if((direction < 0 && OrderType() == OP_BUY) || (direction > 0 && OrderType() == OP_SELL))
         continue;
      if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
        {
         LastTicket = OrderTicket();
         break;
        }
     }
   return(LastTicket);
  }

I check that everything is correct with a comment. Solved


The problem is that I can't find a way to get the ticket for the first trade in the series


Could someone give me a hand with this? Thank you very much in advance


Reason: