how can get 1st 2nd 3rd order ticket number and their information

 

i have grid order

example

1st order ticket = 1 , lot = 0.1 ,openprice = 1.2345
2nd order ticket = 2 ,lot = 0.2 ,openprice = 1.2367
3rd order ticket = 3 ,lot = 0.3 ,openprice = 1.2389

i want to get their informations

i tried as follow ,but not work , can get only first order information

  datetime buyOrderTime=TimeCurrent();

   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && 
         OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
        {
        
         if(OrderType()==OP_BUY)
           {
            
            double OpenPriceLong=NormalizeDouble(OrderOpenPrice(),Digits);
       
            if(OrderOpenTime()<buyOrderTime)
              {
               buyOrderTime=OrderOpenTime();
               FirstBuyOrder=OrderTicket();
                FirstBuyLot = OrderLots();
                FirstBuyOpenprice = OrderOpenPrice();
              }
              if(FirstBuyOrder == OrderTicket())
              {
                secondBuyOrder=FirstBuyOrder+1;
                if(secondBuyOrder>FirstBuyOrder)
                {
                   secondBuyLot = OrderLots();
                   secondBuyOpenprice = OrderOpenPrice();
                }
              }
              
               if(secondBuyOrder == secondBuyOrder+1)
              {
                thirdBuyOrder=secondBuyOrder+1;
                if(thirdBuyOrder>secondBuyOrder)
                {
                  thirdBuyLot = OrderLots();
                  thirdBuyOpenprice = OrderOpenPrice();
                }
              }
              
             
           }
  
      }
    }

how can i get 2nd 3rd order info ,

plz help me

 
  1.   datetime buyOrderTime=TimeCurrent();
    ⋮
                if(OrderOpenTime()<buyOrderTime)

    That if will always be true.

  2.             double OpenPriceLong=NormalizeDouble(OrderOpenPrice(),Digits);
    

    Prices you get from the terminal are always normalized.

  3.                if(secondBuyOrder == secondBuyOrder+1)

    When will that if ever be true?

  4. Get your values, then work with them. When working with multiple values, arrays and structs are your friend.

           struct Order{
              datetime time;
              double   lots;
              double   price;
              int      ticket;
           };
           Order buys[]; int count=0;
           for(int i=0;i<OrdersTotal();i++) if(
              OrderSelect(i,SELECT_BY_POS) 
           && OrderMagicNumber()   == Magic)
           && OrderType()          == OP_BUY)
           && OrderSymbol()        == Symbol() 
           ){
              ArrayResize(buys, count+1);
              buys[count].time     = Ordertime();
              buys[count].lots     = OrderLots();
              buys[count].price    = Orderprice();
              buys[count].ticket   = OrderTicket();
              ++count;
           }
    
          if(count >= 3) // thirdBuyLot is buys[2].lot

 
William Roeder #:
  1. That if will always be true.

  2. Prices you get from the terminal are always normalized.

  3. When will that if ever be true?

  4. Get your values, then work with them. When working with multiple values, arrays and structs are your friend.


thanks for reply but i cannot get wanted value , counting continue and only get 1st order values and cannot get next order values

 datetime buyOrderTime=TimeCurrent();
    for(int i=0;i<OrdersTotal();i++) {
    if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
       {
          if(OrderType()==OP_BUY)
           {
          ArrayResize(buys, count+1);
          buys[count].time     = OrderOpenTime();
          buys[count].lots     = OrderLots();
          buys[count].price    = OrderOpenPrice();
          buys[count].ticket   = OrderTicket();
          ++count;
          
         
          
           }
       }
       
     }
2022.10.21 21:01:17.865 2021.02.04 19:20:00  testgridorderticket EURUSDm,H1: 2nd2021.02.03 12:20:00
2022.10.21 21:01:17.865 2021.02.04 19:20:00  testgridorderticket EURUSDm,H1: 1st2021.02.03 12:20:00

if(count>=1){buys[1].lots}
if(count>=2){buys[2].lots}

they are same values , buy[2].lots cannot get 2nd order value.

how can i fix that

 
  1. LONNV #:, counting continue and only get 1st order values and cannot get next order values

    The loop gets all matching orders.

    Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?
              Code debugging - Developing programs - MetaEditor Help
              Error Handling and Logging in MQL5 - MQL5 Articles (2015)
              Tracing, Debugging and Structural Analysis of Source Code - MQL5 Articles (2011)
              Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator - MQL5 Articles (2010)

  2. LONNV #: , buy[2].lots cannot get 2nd order value.

    buy[2] is not the second order, it is the third.

  3. You showed prints but not the code that makes them; your error is there.
 
William Roeder #:
  1. The loop gets all matching orders.

    Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?
              Code debugging - Developing programs - MetaEditor Help
              Error Handling and Logging in MQL5 - MQL5 Articles (2015)
              Tracing, Debugging and Structural Analysis of Source Code - MQL5 Articles (2011)
              Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator - MQL5 Articles (2010)

  2. buy[2] is not the second order, it is the third.

  3. You showed prints but not the code that makes them; your error is there.

i will show you count variable value.it couting more than actual open order ,i mean open order is only one but it still counting over 1

2022.10.22 03:25:49.563 2021.03.08 20:42:30  testgridorderticket EURUSDm,H1: counting6995

you see , it count 6995 .open order is only two.

this make non sense, what wrong in for looping?

 for(int i=0;i<OrdersTotal();i++) {
    if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
       {
          if(OrderType()==OP_BUY)
           {
          ArrayResize(buys, count+1);
          buys[count].time     = OrderOpenTime();
          buys[count].lots     = OrderLots();
          buys[count].price    = OrderOpenPrice();
          buys[count].ticket   = OrderTicket();
          count++;
      
        
          
           }
       }
       
     }
     Print("counting"+count+"");
        
      if(count>=1){
        Print("time"+ buys[0].time+"");
        Print("lot"+ buys[0].lots+"");
        Print("price"+ buys[0].price+"");
        Print("ticket"+ buys[0].ticket+"");
        }
   
        if(count>=2){
        Print("2nd time"+ buys[1].time+"");
        Print("2nd lot"+ buys[1].lots+"");
        Print("2nd price"+ buys[1].price+"");
        Print("2nd ticket"+ buys[1].ticket+"");
        }
 
            

counting is not correct ,so if(count>= ) condition are not correct anymore.

 
LONNV #: this make non sense, what wrong in for looping?

Nothing is wrong in the for loop.

Do you really expect an answer? There are no mind readers here and our crystal balls are cracked. Always post all relevant code (using Code button) or attach the source file.
     How To Ask Questions The Smart Way. (2004)
          Be precise and informative about your problem

We can't see your broken code. Where do you initialize count to zero?

 
William Roeder #:

Nothing is wrong in the for loop.

Do you really expect an answer? There are no mind readers here and our crystal balls are cracked. Always post all relevant code (using Code button) or attach the source file.
     How To Ask Questions The Smart Way. (2004)
          Be precise and informative about your problem

We can't see your broken code. Where do you initialize count to zero?

i not understand what you mean , count value is 0 in predefined , looping count from 0 and continue counting non stop. but cannot get 2nd 3rd order values ,
 
LONNV #: i not understand what you mean , count value is 0 in predefined , looping count from 0 and continue counting non stop. but cannot get 2nd 3rd order values ,
  1. If you used strict, variables have no initial value.
  2. Counting filtered orders has nothing to do with the for loop position index.
    for(int i=0;i<OrdersTotal();i++) {
        if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           ⋮
              buys[count].ticket   = OrderTicket();
              count++;

 
William Roeder #:
  1. If you used strict, variables have no initial value.
  2. Counting filtered orders has nothing to do with the for loop position index.
my bad,sorry, i declare count=0 in global variable, it make non stop counting, now i change this count=0 inside OnTick() function, it correct count now.
Reason: