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.

EXPERT ADVISOR PROGRAMMING<br />

We'll use the identifiers SlopePeriod, SlopeMethod and SlopePrice for the external variables in our<br />

expert advisor.<br />

// External variables<br />

extern int SlopePeriod = 80;<br />

extern int SlopeMethod = 3;<br />

extern int SlopePrice = 0;<br />

Here is how the iCustom() function will look for this particular indicator, along with the external<br />

variables:<br />

iCustom(NULL,0,"Slope Direction Line",SlopePeriod,SlopeMethod,SlopePrice,0,0);<br />

NULL indicates that we are using the current chart symbol, and 0 is the current chart period. "Slope<br />

Direction Line" is the name of the indicator file. SlopePeriod, SlopeMethod and SlopePrice<br />

are the three indicator parameters. We are using the default Mode index of 0, and the Shift is the<br />

current bar.<br />

Although the Slope Direction Line indicator is drawn as a single line, it is actually composed of two<br />

different buffers. Depending on whether the indicator price is moving up or down, the color (and the<br />

buffer) change.<br />

If you attach the indicator to a chart and view the Data<br />

Window in MetaTrader, you'll see two values for the Slope<br />

Direction Line. The first value displays a price when the<br />

indicator value is increasing. The line is blue <strong>by</strong> default. The<br />

second value displays a price when the indicator value is<br />

decreasing. This line is red <strong>by</strong> default.<br />

We need to determine the Mode index for both of these<br />

lines. The easiest way to do this is to look at the source<br />

code. In the init() function, you will see several lines of<br />

code that are used to declare and set the properties for the<br />

indicator buffers:<br />

Fig 6.2 – Data Window<br />

SetIndexBuffer(0, Uptrend);<br />

SetIndexBuffer(1, Dntrend);<br />

SetIndexBuffer(2, ExtMapBuffer);<br />

...<br />

SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);<br />

SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);<br />

100

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

Saved successfully!

Ooh no, something went wrong!