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 />
double iMA(string Symbol, int Timeframe, int MAPeriod, int MAShift, int MAMethod,<br />
int MAPrice, int Shift)<br />
• Symbol – The symbol of the chart to apply the moving average to.<br />
• Timeframe – The time period of the chart to apply the moving average to.<br />
Every indicator function in MQL starts off with these two parameters. After this are the indicatorspecific<br />
parameters. These correspond to the contents of the Parameters tab in the Indicator<br />
properties.<br />
• MAPeriod – The look-back period of the moving average.<br />
Almost every indicator has at least one period parameter. Most indicators are calculated using a price<br />
series taken from the previous bars. For example, a period setting of 10 would mean that the<br />
indicator uses price data from the last ten bars to calculate the indicator value.<br />
• MAShift – The forward shift of the moving average line, in bars. This is different than the<br />
Shift parameter below.<br />
• MAMethod – The calculation method of the moving average. Choices include simple,<br />
exponential, smoothed or linear weighted.<br />
Any indicator that uses a moving average may give you the option to choose the MA calculation<br />
method. We'll talk about moving average methods later in the chapter.<br />
• MAPrice – The price array to use when calculating the moving average.<br />
This can be the close, open, high, low or some type of average; such as median, typical or weighted<br />
prices. We'll discuss applied price constants later in the chapter.<br />
• Shift – The backward shift of the bar to return the calculation for.<br />
The Shift parameter is the final parameter in any indicator function. This is the index of the bar to<br />
return the indicator value for. A value of 0 returns the indicator value for the current bar. A value of 3<br />
will return the indicator value from 3 bars ago.<br />
The moving average and similar indicators are drawn directly on the chart. You can create trade<br />
conditions based on the relationship between indicators and price. Our moving average cross is an<br />
example of a price relationship between two indicators. When one indicator's price is greater than the<br />
other, a buy or sell signal is generated.<br />
96