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.

Custom Indicators and Scripts<br />

If your indicator is drawn in a separate window (such as an oscillator), and you'd like to add levels to<br />

indicate overbought or oversold levels (such as in the Stochastic or RSI indicators), or the zero level<br />

(such as in the CCI indicator), you can use the SetLevelStyle() and SetLevelValue() functions.<br />

See the MQL Reference under Custom Indicators for more information.<br />

You may also want to specify a short indicator name to be displayed in the top left corner of the<br />

indicator window. Use the IndicatorShortName() function to set this value. The only parameter is a<br />

text string that will appear in the top left corner of the indicator window, as well as in the data<br />

window.<br />

Using Descriptive Buffer Names<br />

Here is our updated indicator code. Note that we've renamed the buffer arrays to be more descriptive<br />

as to their actual function. We've changed the second parameter of the SetIndexBuffer() functions<br />

to reflect the new buffer names. We've also added SetIndexLabel() for each line to display<br />

descriptive names in the Data Window.<br />

//---- buffers<br />

double EMA[];<br />

double UpperBand[];<br />

double LowerBand[];<br />

//+------------------------------------------------------------------+<br />

//| Custom indicator initialization function |<br />

//+------------------------------------------------------------------+<br />

int init()<br />

{<br />

//---- indicators<br />

SetIndexStyle(0,DRAW_LINE);<br />

SetIndexBuffer(0,EMA);<br />

SetIndexLabel(0,"EMA");<br />

SetIndexStyle(1,DRAW_LINE);<br />

SetIndexBuffer(1,UpperBand);<br />

SetIndexLabel(1,"UpperBand");<br />

SetIndexStyle(2,DRAW_LINE);<br />

SetIndexBuffer(2,LowerBand);<br />

SetIndexLabel(2,"LowerBand");<br />

//----<br />

return(0);<br />

}<br />

We've renamed our buffer arrays from the default names (ExtMapBuffer) to more descriptive ones.<br />

EMA[] will be our buffer for the center line, and UpperBand[] and LowerBand[] will be the upper<br />

and lower bands respectively.<br />

149

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

Saved successfully!

Ooh no, something went wrong!