0% found this document useful (0 votes)
0 views4 pages

151 Order Functions

The document outlines three important order-related functions in trading: OrderSelect(), OrderModify(), and OrderDelete(). OrderSelect() is used to select an order for processing, OrderModify() allows modification of existing orders, and OrderDelete() is used to delete pending orders. Each function includes details on parameters, usage, and expected return values, along with links to further documentation.

Uploaded by

Wafa Noor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views4 pages

151 Order Functions

The document outlines three important order-related functions in trading: OrderSelect(), OrderModify(), and OrderDelete(). OrderSelect() is used to select an order for processing, OrderModify() allows modification of existing orders, and OrderDelete() is used to delete pending orders. Each function includes details on parameters, usage, and expected return values, along with links to further documentation.

Uploaded by

Wafa Noor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Black Algo Technologies

Functions For Orders – Select, Modify and Delete


So far, we have been using OrderSend() to submit our orders. Today, we will briefly look at 3 other
important order related functions: OrderSelect(), OrderModify() and OrderDelete(). We will be using
them more often from here on.

OrderSelect()

What it does: It selects a position or order1 for further processing (calculations, order manipulation
etc).

This function is slightly less intuitive. It returns a value, and it does an action (selects an order). We
are more interested in the action. The word “select” may be confusing from a programming point of
view. Think of it this way, when an order is selected, something happens in the background that
loads up the order. We don’t see it directly. But if we use certain order functions when the order is
loaded up, these functions will be applied to the order.

Example:

if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true) {

OrderClose(OrderTicket(),OrderLots(),Price,Slip*K,arrow_color);

In this case, the order selected will be closed using OrderClose().

The next question is “How do we know which order are we selecting?” When we use OrderSelect(),
we are selecting an order in our order pool. Our order pool refers to the list of opened and pending
order (see fig 1 below2).

Fig 1: Order Pool/List

Selecting Orders:

There are 2 ways to select orders (See 2nd input of OrderSelect()). First, is to select by the order
position in the list. Second, is to select by order ticket (1st column of fig 1). The first way is more
common as it is more convenient to select by position. The second way requires us to keep a log of
all order ticket values and this is cumbersome.

1
Definitions: Position describes an opened trade. Order is a pending trade.
2
http://book.mql4.com/trading/orderclose

blackalgotechnologies.com
Black Algo Technologies

If you are still unclear, don’t worry. In the upcoming Lecture “Order Management”, you will get a
clearer picture on how OrderSelect() is being used.

Function:

bool OrderSelect(
int index, // index or order ticket
int select, // flag
int pool=MODE_TRADES // mode
);

Parameters:

ticket
[in] Order index (order index starts from 0 not 1) or order ticket depending on the second
parameter.

select
[in] Selecting flags. It can be any of the following values:

SELECT_BY_POS - index in the order pool.


SELECT_BY_TICKET - index is order ticket.

pool=MODE_TRADES
[in] Optional order pool index. Used when the selected parameter is SELECT_BY_POS. It can be any
of the following values:

MODE_TRADES (default)- order selected from trading pool(opened and pending orders),
MODE_HISTORY - order selected from history pool (closed and canceled order).

Returned value
It returns true if the function succeeds, otherwise falses. To get the error information, one has to call
the GetLastError() function.

The OrderSelect() function is used to retrieve values for the following order functions (list not
exhaustive):

OrderClosePrice(), OrderCloseTime(), OrderComment(), OrderCommission(), OrderExpiration(), Order


Lots(), OrderMagicNumber(),OrderOpenPrice(), OrderOpenTime(), OrderPrint(), OrderProfit(), OrderS
topLoss(), OrderSwap(), OrderSymbol(), OrderTakeProfit(), OrderTicket(), OrderType(), OrderClose()

Documentation: http://docs.mql4.com/trading/orderselect

blackalgotechnologies.com
Black Algo Technologies

OrderModify()

What it does: It modifies a previously opened or pending orders.

We will use this to modify entry pending place, take profit levels, stop loss levels and order
expiration3. This is the function we use to create trailing stops. See BelindaSizing_Complete line 184
(Trailing Stops).

Function:

bool OrderModify(
int ticket, // ticket
double price, // price
double stoploss, // stop loss
double takeprofit, // take profit
datetime expiration, // expiration
color arrow_color // color
);

Parameters:

ticket
[in] Unique number of the order ticket.

price
[in] New open price of the pending order.

stoploss
[in] New StopLoss level.

takeprofit
[in] New TakeProfit level.

expiration
[in] Pending order expiration time.

arrow_color
[in] Arrow color for StopLoss/TakeProfit modifications in the chart. If the parameter is missing or has
CLR_NONE value, the arrows will not be shown in the chart.

Returned value
If the function succeeds, it returns true, otherwise false. To get the detailed error information, call
the GetLastError() function.

Documentation: http://docs.mql4.com/trading/ordermodify

3
Expiration date and time for a pending order. See: http://docs.mql4.com/trading/ordersend (10th input) and
http://docs.mql4.com/trading/orderexpiration

blackalgotechnologies.com
Black Algo Technologies

OrderDelete()

What it does: It deletes a pending order.

This function is important when we deal with pending orders. A common mistake beginners make
when implementing pending orders is to not include OrderDelete() or order expiration. Without these,
the order will be there perpetually.

OrderDelete() is preferred when we choose to delete orders based on certain conditions. For
instance, we implement a breakout strategy and submit 2 orders, one buy stop and one sell stop.
When either of the order gets filled, we delete the other one. In this case, order expiration is not
useful. OrderDelete() will be our tool of choice.

Function:

bool OrderDelete(
int ticket, // ticket
color arrow_color // color
);

Parameters:

Parameters
ticket
[in] Unique number of the order ticket.

arrow_color
[in] Color of the arrow on the chart. If the parameter is missing or has CLR_NONE value arrow will
not be drawn on the chart.

Returned value
If the function succeeds, it returns true, otherwise false. To get the detailed error information, call
the GetLastError() function.

Documentation: http://docs.mql4.com/trading/orderdelete

blackalgotechnologies.com

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy