OrderSymbol function


for example, forex

Very often a trader needs to sort out all the open positions or pending orders and perform some operations with the positions or orders placed in the instrument to which the expert advisor is attached. Let’s suppose we are interested only in pending orders.

By means of the OrderSymbol() function, we can receive information of the order or position selected by the OrderSelect() function.

   string OrderSymbol()

We will write a portion of the code that looks through all our pending orders which weren’t deleted and performs some operations with orders placed in the instrument to which the expert advisor is attached.

   int pos;
   for (pos=0; pos=OP_BUYLIMIT)
             {
               // order proves to be pending; we will check the instrument
               if (OrderSymbol()==Symbol())
                 {
                   // perform some actions with the order
                   // ...
                 }               
             }
         }
       else
           Print("Error ", GetLastError(), " at selecting order number  ", pos);

Two moments can be unclear for You in this code.

First, I define the type of order somewhat oddly at the first sight: if (OrderType()>=OP_BUYLIMIT). In fact condition OrderType()>=OP_BUYLIMIT will be true in the cases when an order is selected and will be false when a position is selected. The point is that constants defining the type of order have the following numerical values:

ConstantValueDescription
OP_BUY0Long position
OP_SELL1Selling
OP_BUYLIMIT2Pending order BUY LIMIT
OP_SELLLIMIT3Pending order SELL LIMIT
OP_BUYSTOP4 Pending order BUY STOP
OP_SELLSTOP5 Pending order SELL STOP

As we can see in all cases when a pending order is selected the value of the OrderType() function will be greater than or equal to OP_BUYLIMIT (i.e. greater or equal to 2).

The second unclear moment in the code is the Symbol() function. Thsi function returns a text line with the name of the financial instrument to which the expert advisor is attached:

   string Symbol()


Next article: "OrderComment 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?