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 />

regardless of whether or not the broker uses fractional pips. We'll call this function PipPoint,<br />

because it will always return the point value that is equal to one pip.<br />

double PipPoint(string Currency)<br />

{<br />

int CalcDigits = MarketInfo(Currency,MODE_DIGITS);<br />

if(CalcDigits == 2 || CalcDigits == 3) double CalcPoint = 0.01;<br />

else if(CalcDigits == 4 || CalcDigits == 5) CalcPoint = 0.0001;<br />

return(CalcPoint);<br />

}<br />

The string argument Currency is the symbol of the currency pair that we want to retrieve the point<br />

for. The MarketInfo() function with the MODE_DIGITS parameter returns the number of decimal<br />

places (digits) for that pair. The if-else statement assigns the appropriate point value to the<br />

CalcPoint variable, depending on the number of digits.<br />

Here's an example of the usage of this function. You will be using the current chart pair the vast<br />

majority of the time, so we will pass the Symbol() function as the argument. This will return the<br />

point for the current chart.<br />

double UsePoint = PipPoint(Symbol());<br />

Here's a set of examples using specific pairs:<br />

double UsePoint = PipPoint(EURUSD);<br />

// Result is 0.0001<br />

double UsePoint = PipPoint(USDJPY);<br />

// Result is 0.01<br />

We will be using this function to find the single pip point value for the remainder of this book. As<br />

we've demonstrated, the Point variable won't work correctly on fractional pip brokers when<br />

calculating the value of a single pip. You can never assume that the EA will only be used on a 2 and 4<br />

digit broker, so it is necessary to automatically determine the point value of a single pip using<br />

PipPoint().<br />

Slippage and Point<br />

Let's digress for a minute and create a function to resize the slippage parameter properly. As<br />

mentioned earlier in this chapter, on a broker with fractional pip quotes, the slippage parameter for<br />

the OrderSend() function will need to be increased <strong>by</strong> a factor of 10 to get the correct slippage<br />

value.<br />

27

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

Saved successfully!

Ooh no, something went wrong!