How do I change the code to get the first position?

 

Hello to all professors

With this code, I get the last selling position

How do I change the code to get the first position?

//+------------------------------------------------------------------+
double FindLastSellPrice()
  {
   double oldorderopenprice=0;
   int oldticketnumber;
   double unused=0;
   int ticketnumber=0;
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      unused=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(OrderSymbol()!="EURUSD" || OrderMagicNumber()!=Magic2) continue;
      if(OrderSymbol()=="EURUSD" && OrderMagicNumber()==Magic2 && OrderType()==OP_SELL)
        {
         oldticketnumber=OrderTicket();
         if(oldticketnumber>ticketnumber)
           {
            oldorderopenprice=OrderOpenPrice();

            ticketnumber=oldticketnumber;
           }
        }
     }
   return (oldorderopenprice);
  }
//+------------------------------------------------------------------+


 
ghobar:

Hello to all professors

With this code, I get the last selling position

How do I change the code to get the first position?


the last smallest "i" against the succeeding "i" that both "i" meets your intended condition above is the first sell position index
int first=0,last=0;
double firstprice=0.0,lastprice=0.0;
for...
{
  if(OrderSymbol()=="EURUSD" && OrderMagicNumber()==Magic2 && OrderType()==OP_SELL)
  {
    if (last==0)
    { 
      last = i; first = i;
        .
        .
        .
      lastprice = price(i);    
    }
    else 
    {
      if (i<first)
      {
        .
        .
        .
        first = i;
        firstprice = price(i);
      }
      continue;
    }
  }
  continue;
} 
just typed
Reason: