You have to loop through the list of all open positions looking for other criterias (_Symbol, open time open price,..) of the position then you can get the ticket number.
void OnTrade() { long order_ticket; int order_magic; ENUM_ORDER_TYPE order_type; int curr_orders=OrdersTotal(); for(int i=curr_orders-1; i>=0; i--) { order_ticket=(long)OrderGetTicket(i); if(OrderGetString(ORDER_SYMBOL)!=_Symbol) continue; order_magic=(int)OrderGetInteger(ORDER_MAGIC); order_type=ENUM_ORDER_TYPE(OrderGetInteger(ORDER_TYPE)); if(order_type==ORDER_TYPE_BUY_STOP) { //.... } if(order_type==ORDER_TYPE_SELL_STOP) { //... } //... } //... return; }
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi guys
To control (OrderSelect) the orders, we must have their ticket numbers.
To catch that ticket number, we can get it when order is sent
int ticket = OrderSend(............)
But what if i want get the ticket numbers of all existing orders by EA (i.e. store the ticket numbers one by one into variables?
I've read the docs and books and have no clues. Please help.