Oldest_Open_Price_Order

 

for sharing and improving 

 

 

double Oldest_Open_Price_Order(int Magic){

   double open_price = 0;
   int TotalOrders = OrdersTotal();
   
      for (int x=0;x<TotalOrders;x++){
      
         OrderSelect(x,SELECT_BY_POS,MODE_TRADES); 
         
         if (OrderMagicNumber() == Magic 
         && OrderSymbol()==Symbol() 
         && (OrderType() == 0 
         || OrderType() == 1)){
         
            
            
            open_price = OrderOpenPrice();
            
            break;
         
         }
      
      }
      
   return open_price;
}

 

 

  Waiting for comments and developing

 

From the documentation

Consecutive selection of orders using the SELECT_BY_POS parameter returns information in the sequence in which it was received from the trading server. Sorting of the resulting list of orders cannot be guaranteed.


So you must check each order and find the oldest one.

 
GumRai:

From the documentation

So you must check each order and find the oldest one.

you mean that i must check the date of every order ?
 
el3reef:
you mean that i must check the date of every order ?
  • Yes, you must check the OrderOpenTime() so as to find the correct order. Just keep a running status and by the end of the loop you will have the data for the order in question.
  • When using OrderType(), don't compare to fixed values, instead use the build in constants, such as OP_BUY and OP_SELL.
  • Always check the boolean results of the OrderSelect() before using the Order data. There is no guarantee that it will ALWAYS select the order, so always check. If you compile with the "#property strict" this will be one of the warnings, so try to use that.