Quite often it is important to specify the number of lots of some already open position or pending order. The easiest variant to get this value is to select the position or order with the help of the function OrderSelect() and then call the function OrderLots().
double OrderLots()
The function returns the number of lots in the selected order or position.
As it has been already mentioned mainly the function is used to specify the number of lots as a parameter in the functions OrderClose() and OrderModify().
Let’s discuss the format of the function OrderClose():
bool OrderClose(int ticket, double lots, double price, int slippage, color Color=CLR_NONE)
Where:
- ticket — ticker of the order or position;
- lots — number of lots to close the position;
- price — close price;
- slippage — value of the maximum slippage in points;
- color — color of the close arrow on the chart. If there is no such a parameter or its value equals CLR_NONE, the arrow is not shown on the chart.
So, as the second parameter the number of lots should be transferred to the function. The easiest way to do it is to get the number of lots with the help of function OrderLots():
// close the position with ticker 77777 at the current price
// let’s suppose that the function has been already selected with the help of the function OrderSelect
// and we know for sure that this is an open position
if (OrderType() == OP_SELL)
OrderClose(OrderTicket(), OrderLots(), Ask, 3);
else
OrderClose(OrderTicket(), OrderLots(), Bid, 3);
There are two preset variables of the double type in this example:
- Bid — bid of the last quotation on the current instrument (the instrument with the attached adviser);
- Ask — ask of the last quotation on the current instrument.
Next article: "
OrderExpiration() Function"