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 />
// start() function<br />
for(int Count = CalculateBars; Count >= 0; Count--)<br />
{<br />
EMA[Count] = iMA(NULL,0,BandsPeriod,BandsShift,BandsMethod,BandsPrice,Count);<br />
double StdDev = iStdDev(NULL,0,BandsPeriod,BandsShift,BandsMethod,BandsPrice,Count);<br />
}<br />
UpperBand[Count] = EMA[Count] + (StdDev * Deviations);<br />
LowerBand[Count] = EMA[Count] - (StdDev * Deviations);<br />
We've added external variables to adjust the remaining parameters for the iMA() and iStdDev()<br />
functions. We also added a parameter to adjust the number of standard deviations. To calculate this,<br />
we simply multiply StdDev <strong>by</strong> Deviations. Now we have a fully adjustable Bollinger Bands indicator<br />
that is more flexible than the standard MetaTrader indicator. The full code is listed in Appendix E.<br />
You can do more with custom indicators than just recalculate built-in indicators. Depending on your<br />
level of mathematical knowledge, you can code indicators that aren't included with MetaTrader, or<br />
even create your own. You can also draw and manipulate objects as well. If you'd like to learn more<br />
about custom indicator creation, see the MQL Reference topics Custom indicators, Object functions<br />
and Math & Trig.<br />
Scripts<br />
A script is an MQL program that runs only once, when it is first attached to a chart. Scripts can be<br />
used to automate a series of trading actions, such as closing all orders on the chart or sending a<br />
pending order. Some scripts, such as the period_converter script that ships with MetaTrader, can<br />
redraw the chart based on a custom time period.<br />
A script source code file should have either the show_confirm or show_inputs property directive.<br />
The show_confirm property prompts the user to confirm the operation of the script, while<br />
show_inputs displays the script properties dialog.<br />
#property show_confirm<br />
#property show_inputs<br />
// shows confirm dialog<br />
// shows properties dialog<br />
If your script has parameters that need to be adjusted, use the show_inputs property. Otherwise,<br />
use show_confirm.<br />
152