How to loop through the current ACTIVE orders to get max/min OrderOpenPrice() for each OrderType()?

 

We know that, in order to access such order details; the order should be selected first by indexing the opened positions.

i.e.

for ( int i = 0; i <= OrdersTotal() - 1; i ++ )
    {
    // --- Select & Gather Order Info ...  
    }

Now, the gathered OrderOpenPrice() at i = k should be stored somehow in order to be compared with its corresponding value for the next iteration (k+1).

For me, I see that; additional auxiliary index say j should be used to carry out that task, but WHAT and HOW?

What is the relation between i and j with respect to OrdersTotal()?

and How can we implement another inner loop (using j index) under the main loop (using i index)?

Any ideas please?

 
int i,active ;
double TopPrice=0, MinPrice=100000 ; //Min price must start as a large number
int TopTicket, MinTicket ; 
active = OrdersTotal() ;
for (i=active-1; i>=0; i--)
    {
     if ( OrderSelect(i,SELECT_BY_POS,MODE_TRADES) )
       {
        if ( OrdType == OrderType() && Symbol()=OrderSymbol() ) //or other checks to filter out orders from other charts
          {
           if ( MinPrice > OrderOpenPrice() ) { MinPrice=OrderOpenPrice() ; MinTicket = OrderTicket() ; }
           if ( MaxPrice < OrderOpenPrice() ) { MaxPrice=OrderOpenPrice() ; MaxTicket = OrderTicket() ; }
          } //end if ( OrdType ==
       } // end if ( OrderSelect
    } //end for