Expert Advisor Programming by Andrew R. Young
Expert Advisor Programming by Andrew R. Young
Expert Advisor Programming by Andrew R. Young
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
EXPERT ADVISOR PROGRAMMING<br />
• OrderProfit() – Returns the profit (in the deposit currency) for the selected order.<br />
We'll need to use OrderSelect() before closing or modifying an order. Let's illustrate how we use<br />
OrderSelect() to close an order.<br />
Closing Orders<br />
When we close a market order, we are exiting the trade at the current market price. For buy orders,<br />
we close at the Bid price, and for sell orders, we close at the Ask. For pending orders, we simply<br />
delete the order from the trade pool.<br />
OrderClose()<br />
We close market orders using the OrderClose() function. Here is the syntax:<br />
bool OrderClose(int Ticket, double Lots, double Price, int Slippage, color Arrow);<br />
• Ticket – The ticket number of the market order to close.<br />
• Lots – The number of lots to close. Most brokers allow partial closes.<br />
• Price – The preferred price at which to close the trade. For buy orders, this will be the<br />
current Bid price, and for sell orders, the current Ask price.<br />
• Slippage – The allowed slippage from the closing price, in pips.<br />
• Color – A color constant for the closing arrow. If no color is indicated, no arrow will be<br />
drawn.<br />
You can close part of a trade <strong>by</strong> specifying a partial lot size. For example, if you have a trade open<br />
with a lot size of 2.00, and you want to close half of the trade, then specify 1 lot for the Lots<br />
argument. Note that not all brokers support partial closes.<br />
It is recommended that if you need to close a position in several parts, you should place multiple<br />
orders instead of doing partial closes. Using the example above, you would place two orders of 1.00<br />
lot each, then simply close one of the orders when you want to close out half of the position. In this<br />
book, we will always be closing out the full order.<br />
The following example closes a buy market order:<br />
OrderSelect(CloseTicket,SELECT_BY_TICKET);<br />
34