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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

EXPERT ADVISOR PROGRAMMING<br />

Next are the declarations for our buffer arrays. We have three buffers named ExtMapBuffer(1-3).<br />

We will change these array identifiers to something more descriptive shortly.<br />

The init() function is where we set the properties for our indicator buffers. SetIndexBuffer()<br />

binds a buffer array to a buffer index. The buffer index is what we refer to when we set the<br />

properties for an indicator line, and also when we call an indicator line from an EA using the<br />

iCustom() function. The first parameter is an integer from 0 to 7, and the second parameter is the<br />

name of the buffer array.<br />

Drawing Properties<br />

The SetIndexStyle() function sets the type of line to draw, along with the properties of that line.<br />

Every indicator line will have a corresponding SetIndexStyle() function. Here is the syntax:<br />

void SetIndexStyle(int BufferIndex, int LineType, int LineStyle = EMPTY,<br />

int LineWidth = EMPTY, color LineColor = CLR_NONE)<br />

• BufferIndex – The index of the buffer, from 0 to 7.<br />

• LineType – Sets the type of line to draw. DRAW_LINE draws a single line, DRAW_HISTOGRAM<br />

draws a vertical histogram (see the OsMA or Awesome Oscillator indicators for examples),<br />

DRAW_ARROW draws a symbol, and DRAW_NONE draws no line.<br />

• LineStyle – An optional parameter indicating the drawing style. Used mainly for lines of type<br />

DRAW_LINE. By default, a solid line is drawn (STYLE_SOLID). You can also draw dashed<br />

(STYLE_DASH) and dotted (STYLE_DOT) lines.<br />

• LineWidth – An optional parameter indicating the width of the line in pixels. The default<br />

value is 1.<br />

• LineColor – An optional parameter indicating the color of the line. If you use the wizard, the<br />

color is set using #property declarations, but you can set the color here as well.<br />

If you are using DRAW_ARROW as the LineType, the SetArrow() function allows you to set the<br />

Wingdings font symbol to draw on the chart. The first parameter is the buffer index, and the second<br />

is an integer constant representing the symbol to draw. The symbols can be found in the MQL<br />

Reference under Standard Constants – Arrow Codes.<br />

You may want to add a description for the indicator lines that will be displayed in the tooltip or in the<br />

data window. To do this, use the SetIndexLabel() function. The first parameter is the buffer index,<br />

and the second parameter is a text description. We'll add these to our indicator shortly.<br />

148

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

Saved successfully!

Ooh no, something went wrong!