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.

Order Conditions and Indicators<br />

The first SetIndexBuffer() function sets an indicator buffer with an index of 0, and uses the array<br />

Uptrend. We can guess from the array name that this applies to to the blue indicator line. The<br />

second function does likewise for for the array DnTrend. Note the SetIndexStyle() functions at the<br />

bottom that sets buffers 0 and 1 to draw a solid line.<br />

The third buffer, with the index of 2 and the array ExtMapBuffer, is used for calculation only. We can<br />

therefore conclude that 0 and 1 are the buffer indexes that contain our indicator price information.<br />

Based on the array identifiers, 0 is the uptrend line, and 1 is the downtrend. Here is how we declare<br />

our indicators:<br />

double SlopeUp = iCustom(NULL,0,"Slope Direction Line",SlopePeriod,SlopeMethod,<br />

SlopePrice,0,1);<br />

double SlopeDown = iCustom(NULL,0,"Slope Direction Line",SlopePeriod,SlopeMethod,<br />

SlopePrice,1,1);<br />

Note that the Mode parameter – the next to last one – has been set to the appropriate indicator<br />

buffer index – 0 for SlopeUp, and 1 for SlopeDown. The Shift parameter – the very last one – has<br />

been set to 1, which checks the closing value of the last bar.<br />

It's a good idea to double check that you're using the correct Mode parameters. Add a Print()<br />

function to your expert advisor, and run a back test in the Strategy Tester using "Open prices only" as<br />

the testing model. Make sure the Shift parameter is set to 1 in the iCustom() function.<br />

Print("Slope Up: "+SlopeUp+", Slope Down: "+SlopeDown+" Time: "+TimeToStr(Time[1]));<br />

The Print() function prints the value of our indicator buffers to the log, along with the time and<br />

date of the previous bar. You can view the log under the Journal tab in the Strategy Tester window.<br />

Here is the output of the Print() function in the log:<br />

Slope Up: 2147483647.00000000, Slope Down: 1.50483900 Time: 2009.11.26 16:00<br />

The value for SlopeUp, 2147483647, is a very large integer that represents the EMPTY_VALUE state of<br />

a custom indicator. You can actually use this as a trading condition. SlopeDown returns the indicator<br />

value of the previous bar. Time indicates the bar that we want to find on the chart.<br />

Click the Open Chart button in the Strategy Tester window to open a chart with your indicator<br />

already applied. Find the bar indicated in the log <strong>by</strong> Time, and make sure the indicator values in the<br />

Data Window match those printed in the log. If not, adjust the Mode parameter in the iCustom()<br />

function until you find the correct buffer.<br />

101

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

Saved successfully!

Ooh no, something went wrong!