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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

EXPERT ADVISOR PROGRAMMING<br />

Chapter 6<br />

Order Conditions and Indicators<br />

We've spent the last few chapters creating functions that carry out the order mechanics that are<br />

common to every expert advisor. These functions are meant to be used in a variety of trading<br />

situations, and should be as reusable and flexible as possible. This allows us to concentrate on coding<br />

the unique trading conditions for our trading system.<br />

This is where most of your work is going to be focused – getting the expert advisor to trade your<br />

system as accurately as possible. We'll need to identify the exact conditions for opening and closing<br />

orders, as well as determining stop loss and take profit prices. Almost every trading system uses price<br />

and/or indicator data. Let's examine the ways we can access and use this information in our expert<br />

advisors.<br />

Price Data<br />

Along with the current Bid or Ask price (which we've already covered in previous chapters), you may<br />

need to use bar price data, namely the high, low, open or close of a particular bar. For the current<br />

chart, you can use the predefined series arrays High[], Low[], Open[] and Close[].<br />

An array is a variable that holds multiple values. You cycle through the values <strong>by</strong> changing the index,<br />

which is contained in the square brackets. For example Open[0] is the open price of the current bar.<br />

0 is the index, and <strong>by</strong> changing it, we can get the open price of other bars. The bar previous to the<br />

current bar would have an index of 1, and so on. We will frequently be using either the current bar or<br />

the previous bar's price values.<br />

If you need a high, low, open or close value for a symbol other than the current chart, or if you need<br />

price data for a period other than the current chart period, you can use the functions iHigh(),<br />

iLow(), iOpen() and iClose(). Here's the syntax of these functions, using iClose() as our<br />

example:<br />

double iClose(string Symbol, int Period, int Shift)<br />

• Symbol – The symbol of the currency pair to use.<br />

• Period – The period of the chart to use, in minutes.<br />

• Shift – The backward shift relative to the current bar.<br />

94

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

Saved successfully!

Ooh no, something went wrong!