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.

Advanced Order Placement<br />

Verifying Pending Order Prices<br />

Here's how we verify the pending order price for a buy stop or sell limit order. The PendingPrice<br />

variable stores our pending order price:<br />

if(PendingPrice < UpperStopLevel) PendingPrice = UpperStopLevel + MinStop;<br />

Notice that the logic here is identical to the code above that checks our buy take profit and sell stop<br />

loss prices. And here's the code to check the pending order price for a sell stop or buy limit order:<br />

if(PendingPrice > UpperStopLevel) PendingPrice = UpperStopLevel – MinStop;<br />

Calculating Lot Size<br />

Aside from choosing suitable stop loss and take profit levels, using an appropriate lot size is one of<br />

the best risk management tools you have. Specifying a lot size can be as simple as declaring an<br />

external variable and using a fixed lot size for every order. In this section, we'll explore a more<br />

sophisticated method that calculates the lot size based on the maximum amount you're willing to lose<br />

per trade.<br />

Over-leveraging is one of the big killers of forex traders. Using lot sizes that are too large in relation<br />

to your equity can wipe out your account just as easily as it can produce big gains. It is<br />

recommended that you use no more than 2-3% of your equity per trade. By this, we mean that the<br />

maximum amount you can lose per trade will be no more that 2-3% of your account.<br />

Money Management<br />

To calculate the lot size using this method, we need to specify a percentage of equity to use and the<br />

stop loss in pips. We'll use the external variable EquityPercent to set the percentage of equity to<br />

use. We'll assume a stop loss of 50 pips is used.<br />

extern double EquityPercent = 2;<br />

extern double StopLoss = 50;<br />

First, we need to calculate the amount of equity specified <strong>by</strong> EquityPercent. If we have a balance<br />

of $10,000, and we are using 2% of our equity, then the calculation is as follows:<br />

double RiskAmount = AccountEquity() * (EquityPercent / 100);<br />

49

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

Saved successfully!

Ooh no, something went wrong!