Clarification on OrderSelect Function

 
int n = ?;
  
  if (OrderSelect(n, SELECT_BY_POS)==true)
   {    
    ticket_number = OrderTicket();
   }

If I have only one order open and no pending orders, what should the value of n be in order for me to determine the ticket_number of the open order?

Thanks.

 
0
 
qjol:
0

thanks
 
  1. forestmyopia:
    If I have only one order open and no pending orders, what should the value of n be in order for me to determine the ticket_number of the open order?
        for(iPos = OrdersTotal()-1; iPos >= 0 ; iPos--) if (
            OrderSelect(iPos, SELECT_BY_POS)                // Only my orders w/
        &&  OrderMagicNumber()  == magic.number             // my magic number
        &&  OrderSymbol()       == Symbol()                 // and my pair.
        ){
            ticket_number = OrderTicket();
            :

  2. qjol:
    0
    Wong. That assume that the EA is only on one chart and that there are no other EAs or manual trading.
 
WHRoeder:
  1. forestmyopia:
    If I have only one order open and no pending orders, what should the value of n be in order for me to determine the ticket_number of the open order?

  2. qjol:
    0
    Wong. That assume that the EA is only on one chart and that there are no other EAs or manual trading.

c for your self

forestmyopia:

If I have only one order open and no pending orders, what should the value of n be in order for me to determine the ticket_number of the open order?

Thanks.

 
If I have only one order open and no pending orders
He's a newbie. He's only thinking about his code at the moment. You want his code to fail the moment he adds it to another chart? He will assume OrderSelect(0) will be per chart not all charts. You MISLEAD him. If you don't want to be helpful, DON'T post.
 

You are missing something badly. First you need to check if EVER there is such an order. Otherwise, even if you fill in n=0, or n=whatever, will not help in the selection. My recommendation is before you start, at least do a simple checks along this line. For eg:

if(OrdersTotal()>0){ //then only, perform selection

I have seen and assisted with codes which gives prbs, you just search the threads in this forum, and you will find dozens of them. The reason is bec. of this orderselect(), not done correctly.

 

forestmiopia had that covered in his original code

if (OrderSelect(n, SELECT_BY_POS)==true)

 
SDC:

forestmiopia had that covered in his original code

if (OrderSelect(n, SELECT_BY_POS)==true)

I was referring to the some of the above codes that iterate this way:

for(iPos = OrdersTotal()-1; iPos >= 0 ; iPos--) if (

Covered or not, just be safe.

Reason: