Selecting first order opened

 

Hi,

I would like to select in an EA the first order opened in the current symbol (not necessary opened with an EA) to collect some information (OrderOpenPrice, StopLoss...) but i have some difficulties to code it with the function orderselect.

Does anyone know how to do it ?

Thanks for your help.

TAAD

 

i think you have to iterate trough all you open orders (if you want to use only currently open orders) or trough your history and compare the OrderOpenTime

i am thinking of something like:

int order=0;
datetime first=0;
for(int i=OrdersTotal()-1;i>=0;i--){
  OrderSelect(i,SELECT_BY_POS);
  if(OrderSymbol()==Symbol()){
    if(first==0 || OrderOpenTime()<first){
      first=OrderOpenTime();
      order=OrderTicket();
    }
  }
}
return (order);

just wrote this code here, nothing tested...

good luck

 
TAAD:

[...] but i have some difficulties to code it with the function orderselect.

https://www.mql5.com/en/forum/126165
 
thanks for your help.
 
zzuegg #:

i think you have to iterate trough all you open orders (if you want to use only currently open orders) or trough your history and compare the OrderOpenTime

i am thinking of something like:

just wrote this code here, nothing tested...

good luck

Thanks @zzuegg This helped me a lot, 20yrs after

Reason: