OrderSelect function


for example, forex

Format of the OrderSelect() function:

   bool    OrderSelect ( int index, int select, int pool=MODE_TRADES )

As we can see the unction returns a value of a logic type: true — when an order or a position were selected successfully, false — in case of an error. The code of this error may be received later with the help of the GetLastError() function.

There are two ways to select an order/position:

  • by the number of ticket;
  • by the number of the order/position in the list.

If You know the ticket of the order or position then the value SELECT_BY_TICKET should be passed as parameter select while the number of the ticket of the order or position as parameterindex. The third parameter isn’t used in this case and it can be omitted.

An example of selection by the ticket:

   //---- we select order/position with ticket  77777
   if ( OrderSelect (77777, SELECT_BY_TICKET) == true) 
     Print("Ордер #77777 selected successfully");
  else
    Print("OrderSelect() returned an error - ",GetLastError());

If You don’t know the ticket there is another way to select an order or position. For this You have to select an order or position from the list of open positions or pending orders that weren’t deleted (the value of parameter pool is equal to MODE_TRADES) or from the list of closed positions or deleted orders (parameter pool equals MODE_HISTORY). In the both cases parameter select must be equal to SELECT_BY_POS. In parameter index You should indicate the number of this position or order in the list of open positions or pending orders which weren’t deleted (pool equals to MODE_TRADES) of in the list of closed positions and deleted pending orders (pool equals to MODE_HISTORY).

This method is very useful when You need to «run», for example through all the open positions:

   int pos;
   int total = OrdersTotal();
   for ( pos = 0; pos


Next article: "OrdersTotal function"

+7 (495) 710-76-76
© 1998—2008 «Alpari»

close

Your Personal Area

For alpari.classic enter your account number (a letter and 4 figures) and the code word for the Personal Area.

For alpari.micro account: enter your login (6 figures) and the password for MT.

Open an account!Forgotten your password?