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.

Order Conditions and Indicators<br />

Let's use iClose() to get a close price for a different chart period. For example, we're using a 1 hour<br />

chart, but we want to check the close price of the previous bar on the 4 hour chart:<br />

double H4Close = iClose(NULL,PERIOD_H4,1);<br />

NULL refers to the current chart symbol. PERIOD_H4 is an integer constant that refers to the H4 chart<br />

period. 1 is our shift, which is the bar previous to the current bar. Let's use another example that<br />

returns the close of the current bar on another chart:<br />

double GBPClose = iClose(GBPUSD,0,0);<br />

GBPUSD is the symbol that we're using. We've specified 0 as our period, so the chart period we're<br />

checking on GBPUSD will be the same as our current chart. The shift is 0, which is the current bar.<br />

You can use a loop operator such as for or while to increment the Shift parameter and cycle<br />

through the chart history. This for loop retrieves the close price for each of the last ten bars, and<br />

prints it to the log:<br />

for(int Count = 0; Count

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

Saved successfully!

Ooh no, something went wrong!