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.

Appendix C<br />

// Init function<br />

int init()<br />

{<br />

UsePoint = PipPoint(Symbol());<br />

UseSlippage = GetSlippage(Symbol(),Slippage);<br />

}<br />

// Start function<br />

int start()<br />

{<br />

// Execute on bar open<br />

if(CheckOncePerBar == true)<br />

{<br />

int BarShift = 1;<br />

if(CurrentTimeStamp != Time[0])<br />

{<br />

CurrentTimeStamp = Time[0];<br />

bool NewBar = true;<br />

}<br />

else NewBar = false;<br />

}<br />

else<br />

{<br />

NewBar = true;<br />

BarShift = 0;<br />

}<br />

// Moving averages<br />

double FastMA = iMA(NULL,0,FastMAPeriod,0,0,0,BarShift);<br />

double SlowMA = iMA(NULL,0,SlowMAPeriod,0,0,0,BarShift);<br />

double LastFastMA = iMA(NULL,0,FastMAPeriod,0,0,0,BarShift+1);<br />

double LastSlowMA = iMA(NULL,0,SlowMAPeriod,0,0,0,BarShift+1);<br />

// Calculate lot size<br />

double LotSize = CalcLotSize(DynamicLotSize,EquityPercent,StopLoss,FixedLotSize);<br />

LotSize = VerifyLotSize(LotSize);<br />

// Begin trade block<br />

if(NewBar == true)<br />

{<br />

// Buy order<br />

if(FastMA > SlowMA && LastFastMA

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

Saved successfully!

Ooh no, something went wrong!