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.
Advanced Order Placement<br />
Modifying a Pending Order Price<br />
OrderModify() can also be used to modify the order price of a pending order. If the pending order<br />
price has already been hit and the order has been filled, it is no longer a pending order, and the price<br />
cannot be changed.<br />
We'll use the variable NewPendingPrice to represent our changed order price. We'll assume the price<br />
has already been calculated and is valid. Here's how we modify a pending order price:<br />
OrderSelect(Ticket,SELECT_BY_TICKET);<br />
if(NewPendingPrice != OrderOpenPrice())<br />
{<br />
bool TicketMod = OrderModify(Ticket,NewPendingPrice,OrderStopLoss(),<br />
OrderTakeProfit(),0);<br />
}<br />
As always, we retrieve the order information using OrderSelect(). This way we can pass the<br />
unchanged stop loss and take profit prices to the OrderModify() function. Before modifying the<br />
order, we'll check to make sure that our new pending order price is not the same as the current<br />
pending order price.<br />
For OrderModify(), we specify our order ticket, the new order price stored in NewPendingPrice,<br />
and the unchanged stop loss and take profit values represented <strong>by</strong> OrderStopLoss() and<br />
OrderTakeProfit(). We're not using an expiration time for this order, so we use 0 for the expiration<br />
parameter.<br />
Verifying Stops and Pending Order Prices<br />
Stop loss, take profit and pending order prices must be a minimum distance away from the Bid and<br />
Ask prices. If a stop or pending order price is too close to the current price, an error will result, and<br />
the order will not be placed. This is one of the most common trading errors, and it can easily be<br />
prevented if the trader is careful to set their stops and pending orders a sufficient distance from the<br />
price.<br />
But during periods of rapid price movement, valid stop loss prices can be made invalid <strong>by</strong> widening<br />
spreads. Different brokers have varying stop levels, so a stop loss that is valid on one broker may be<br />
too close for another. Some trading systems will set stops and pending order prices based on<br />
indicator values, highs or lows, or some other method of calculation where a minimum distance is not<br />
guaranteed.<br />
45