Types of Trade Operations

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

From a previous lesson, it is possible for an expert advisor or script to work on the following

orders:

1. Market
◦ Buy
◦ Sell
2. Pending
◦ Buy Stop
◦ Sell Stop
◦ Buy Limit
◦ Sell Limit

In the course of a trading robot, it would at some point work with trades. Thus, it would need a
means for identifying the various types of trade operations (and order types) that exist.

Computers are comfortable with numbers. So, each type of order or position is assigned a
different number. Humans, on the other hand, are not so much acquainted with numbers as
computers are. In order to easily remember numbers, numbers that correspond to order types
must be assigned to a meaningful keyword.

Words as Numbers
The following table shows the keyword used to identify each type of order operation:

ID Value Description
OP_BUY 0 Buy Operation
OP_SELL 1 Sell Operation
OP_BUYLIMIT 2 Buy Limit Operation
OP_SELLLIMIT 3 Sell Limit Operation
OP_BUYSTOP 4 Buy Stop Operation
OP_SELLSTOP 5 Sell Stop Operation

In some way, we can these identifiers can be considered as predefined variables themselves.
There is no need to redefine these variables, for example, that OP_BUY = 0, and so on. And in
the eyes of the trading robot OP_BUY is the same as 0. And this value is fixed—there is no way
to change their values in the source code.

We can confirm that the information on the table above is true if we run the following sample
code on an EA:

void OnTick()
{
Print("BUY is equal to "+OP_BUY );
Print("SELL is equal to "+OP_ SELL );
Print("BUYLIMIT is equal to "+OP_ BUYLIMIT );
Print("SELLLIMIT is equal to "+OP_ SELLLIMIT );
Print("BUYSTOP is equal to "+OP_BUYSTOP);
Print("SELLSTOP is equal to "+OP_ SELLSTOP );
ExpertRemove();
}

Prints:
BUY is equal to 0
SELL is equal to 1
BUYLIMIT is equal to 2
SELLLIMIT is equal to 3
BUYSTOP is equal to 4
SELLSTOP is equal to 5

Take note that in the source code, the identifiers used are missing the quotation marks we
usually find in strings. In this particular case, the compiler understands that when we used
keywords such as OP_BUY without quotes, we are referring to a number (integer), not a string.

There is a deeper explanation as to why and how these identifiers exist. We will discuss them
in a future lesson.

But for now, this is one of the few things that we need to know in order to proceed to the next
lesson.

You might also like