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.
EXPERT ADVISOR PROGRAMMING<br />
Here's how we would use the Slope Direction Line indicator in our expert advisor. If the slope is<br />
trending upward, SlopeUp will return a price value, while SlopeDown will return EMPTY_VALUE, or<br />
2147483647. The opposite applies when the slope is trending downward.<br />
if(SlopeUp != EMPTY_VALUE && SlopeDown == EMPTY_VALUE) // Buy<br />
if(SlopeUp == EMPTY_VALUE && SlopeDown != EMPTY_VALUE) // Sell<br />
These conditions simply check to see which line is equal to EMPTY_VALUE, and which line is not.<br />
Indicator Constants<br />
Time Frames<br />
Many functions in MQL, including indicator and price functions, accept a time frame parameter. As<br />
indicated before, if we use a Timeframe parameter of 0, the current chart time frame will be used. If<br />
we wish to use a different time frame, we will need to specify the time frame in minutes. For<br />
example, M5 is 5, H1 is 60 and H4 is 240. We can also use constants to indicate the time frame:<br />
• PERIOD_M1 – 1 minute.<br />
• PERIOD_M5 – 5 minute.<br />
• PERIOD_M15 – 15 minute.<br />
• PERIOD_M30 – 30 minute.<br />
• PERIOD_H1 – 1 hour (60 minutes).<br />
• PERIOD_H4 – 4 hour (240 minutes).<br />
• PERIOD_D1 – Daily (1440 minutes).<br />
Applied Price<br />
The applied price indicator parameter indicates the price series to use when calculating the indicator<br />
value. You will generally use the close to calculate indicator values, although you may wish to use<br />
other values as well. Here is the list of price series and their associated constants, along with the<br />
integer value:<br />
• PRICE_CLOSE – 0: Close price.<br />
• PRICE_OPEN – 1: Open price.<br />
• PRICE_HIGH – 2: High price.<br />
102