25.10.2016 Views

Expert Advisor Programming by Andrew R. Young

Expert Advisor Programming by Andrew R. Young

Expert Advisor Programming by Andrew R. Young

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Order Placement<br />

OrderSend(Symbol(),OP_BUYLIMIT,LotSize,PendingPrice,Slippage,BuyStopLoss,<br />

BuyTakeProfit,"Buy Limit Order",MagicNumber,0,Green);<br />

Note that we used OP_BUYLIMIT to indicate a buy limit order. Otherwise, our parameters are identical<br />

to those for stop orders.<br />

For a sell limit order, the pending order price must be greater than the current Ask price. Here's an<br />

example of a sell limit order:<br />

OrderSend(Symbol(),OP_SELLLIMIT,LotSize,PendingPrice,Slippage,SellStopLoss,<br />

SellTakeProfit,"Sell Limit Order",MagicNumber,Expiration,Red);<br />

Calculating Stop Loss & Take Profit<br />

There are several ways of calculating stop loss and take profit prices. The most common method is to<br />

specify the number of pips away from the order opening price to place your stop. For example, if we<br />

have a stop loss setting of 50 pips, that means that the stop loss price will be 50 pips away from our<br />

order opening price.<br />

We can also use an indicator value, an external parameter or some other type of price calculation. All<br />

we will need to do then is verify that the stop loss or take profit price is valid.<br />

Calculating in Pips<br />

For this, the most common method of calculating stops, we will use an external variable in which the<br />

user specifies the number of pips for the stop loss and take profit. We then calculate the stops<br />

relative to the order opening price.<br />

For buy market orders, the opening price will be the Ask, and for sell market orders, the opening<br />

price will be the Bid. For pending stop and limit orders, we assign a a valid opening price that is<br />

something other than the current market price. We will assign the appropriate price to the variable<br />

OpenPrice.<br />

Here are the external variables we'll use for our stop loss and take profit settings:<br />

extern int StopLoss = 50;<br />

extern int TakeProfit = 100;<br />

25

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!