Return OrderSelect

 

Is it possible to find which order has been selected elsewhere?

I'm inside the typical OrderSelect loop, then call a function which also runs through such a loop, and when returning I've lost track of the order that was selected in the 1st loop.

I could obviously store the ordernumber and restore it after returning from the 2nd loop, but it would have 'cleaner' to do that inside the 2nd loop...so that it does not change

the selected order between entry and exit.

 
DayTrader:

Is it possible to find which order has been selected elsewhere?

I'm inside the typical OrderSelect loop, then call a function which also runs through such a loop, and when returning I've lost track of the order that was selected in the 1st loop.

I could obviously store the ordernumber and restore it after returning from the 2nd loop, but it would have 'cleaner' to do that inside the 2nd loop...so that it does not change

the selected order between entry and exit.

Well the documentation actually doesn't tell you what goes on with this function. I think of it in terms of the OrderSelect function copying the values of the relevant order details into a set of variables accessible by OrderTicket, OrderLots etc. I used to think of it as the OrderSelect creating a pointer to a structure. In fact both ideas give the same result, although the pointer method is computationally more efficient.

If you don't want to save the OrderTicket before going to the second loop (which I assume is a function call) and reselect by Ticket when you return, then you could save the OrderTicket before the start of the second loop and restore it at the end. The result is the same and requires that additional OrderSelect by Ticket.

 
exactly
type FunctionWithOrderSelect(){
    int ticket = OrderTicket();                 // Remember caller's selected ticket
    : do whatever with another OrderSelect
    if (!OrderSelect(ticket, SELECT_BY_TICKET)) // Restore caller's selected ticket
        Alert("OrderSelect(",ticket,",ticket) failed: ", GetLastError());
}