Hi, I want to select the newest order.

 

Hi, I want to select the newest order.

Following code is for searching all orders?

How can I modify the code  to select the only one order (newest one) ?


I want to select only the newest order to compare the price, etc....

How can I know the newest order information?

I want to know OrderOpenPrice() for the newest order.

If I want to know the newest current order price,

  OrderSelect(0, SELECT_BY_POS, MODE_TRADES);

Print(OrderOpenPrice());

Is this OK?

for(int i = OrdersTotal() - 1; i >= 0; i--){
   if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false) break;
   if(OrderMagicNumber() != MagicNumber) continue;
   if(OrderSymbol() != Symbol()) continue;
   
   //positions
}
 

if me, 

using global variable or static variable


int g_lastTicket ;


g_lastTicket = Ordersend( ~~~~)


OrderSelect(g_lastTicket,SELECT_BY_TICKET);


only my think.   I'm beginner :)

I think you should consider exception handling about OrderSend is failed. 

 

I used

  OrderSelect(0, SELECT_BY_POS, MODE_TRADES);

Print(OrderOpenPrice());

But when next order is placed, the open price is not changed. Always the same value.

Why?

 
kajironpu: But when next order is placed, the open price is not changed. Always the same value.

Why?

Because the next order is not position zero.

Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
          Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 and MetaTrader 4 - MQL4 programming forum
          MagicNumber: "Magic" Identifier of the Order - MQL4 Articles

Go back to your first post OrderSelect loop.

Reason: