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 />

if((false || UseStochastic == false) && FastMA > SlowMA)<br />

if((false || false) && FastMA > SlowMA)<br />

if(false && FastMA > SlowMA)<br />

Regardless of how FastMA > SlowMA evaluates, the entire trade condition is false.<br />

Now lets say that UseStochastic is set to false. In this case, the statement (UseStochastic ==<br />

true && Kline > Dline) evaluates to false:<br />

if((false || UseStochastic == false) && FastMA > SlowMA)<br />

Since the statement UseStochastic == false is true, the stochastic condition evaluates to true.<br />

if((false || true) && FastMA > SlowMA)<br />

if(true && FastMA > SlowMA)<br />

Which means that if FastMA > SlowMA also evaluates to true, the order will be placed. In this case,<br />

the stochastic condition wasn't even considered, aside from evaluating the on/off state of the<br />

indicator.<br />

Comparing Indicator Values Across Bars<br />

Sometimes you will need to compare the indicator value of the current or most recently closed bar to<br />

the indicator value of a previous bar. For example, let's say you want to know whether a moving<br />

average is going up or down. To do this, we compare the indicator reading of the current bar to that<br />

of the previous bar.<br />

We use the Shift parameter of an indicator function to determine which bar to return the indicator<br />

value for. The Shift parameter is always the last parameter in an indicator function. The current bar<br />

has a shift of 0, the previous bar has a shift of 1, and so on. The moving average functions below<br />

will return a moving average value for the current and the previous bar:<br />

double MA = iMA(NULL,0,MAPeriod,0,MAMethod,MAPrice,0);<br />

double LastMA = iMA(NULL,0,MAPeriod,0,MAMethod,MAPrice,1);<br />

108

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

Saved successfully!

Ooh no, something went wrong!