enum or switch? - switching orders for closing? - page 3

 

For me it is really hard to understand what you want.

You only have 2 options:

int Ticket;

void OnTick(){
  ...
  Ticket = OrderSend(..);
  ...
  OderClose( Ticket, ..);
  ...
} 

and

for(int b=OrdersTotal()-1; b>=0; b--) {
     if( !OrderSelect(b, SELECT_BY_POS ) )      continue; // NOT Ticket! Read the reference!!
     if(  OrderMagicNumber() != MagicNumber1  ) continue;
     if(  OrderSymbol() != Symbol())            continue;
     ...
     OrderClose( OrderTicket(), OrderLots(),... );
     ...
}
 
DomGilberto:
I am wanting a way that when I select externally the order ticket number, in that code above, it will use that ticket number within the function and close just that ticket number? Hope that makes sense?

1. If you place orders manually then you do not have the order ticket , nor can you assign a magic number. Therefore you need a code that will get the order ticket(s) and then you can map the ordinal number (this is what you select) to the order ticket to close the order.

2. And if you place orders through code (i.e. OrderSend()) then you have the order ticket and you could store it in a simple array at position corresponding to the number of the order (its ordinal number, i.e. 1 .. 4) and therefore retrieve it later on by position (ordinal number = what you select), to close the order.

 

In example:

You entered 4 pending orders manually.

Then your code has to scan the order queue and get the order tickets into an array of a capacity of 4, in the right order.

Then, when you later on select an order number (its ordinal number 1 .. 4) for closure, your code simply looks up the order's ticket at that position form the array and closes the order.

Here a (incomplete) code sample how this could look like:

#property strict

input int selector = -1;
int tickets[4] = {-1, -1, -1, -1};

int OnInit()
{
        /* scan order queue for pending orders and retrieve tickets */
}

void OnTick()
{
        if(selector > -1) {
                if(OrderSelect(tickets[selector], SELECT_BY_TICKET)) {
                        if(OrderClose(OrderTicket(), ...)) {
                                tickets[selector] = -1;
                        }
                }
        }
}