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

Appendix D<br />

Include File<br />

This is the include file with the functions used in the expert advisor in Appendix C.<br />

#property copyright "<strong>Andrew</strong> <strong>Young</strong>"<br />

#include <br />

double CalcLotSize(bool argDynamicLotSize, double argEquityPercent,double argStopLoss,<br />

double argFixedLotSize)<br />

{<br />

if(argDynamicLotSize == true && argStopLoss > 0)<br />

{<br />

double RiskAmount = AccountEquity() * (argEquityPercent / 100);<br />

double TickValue = MarketInfo(Symbol(),MODE_TICKVALUE);<br />

if(Point == 0.001 || Point == 0.00001) TickValue *= 10;<br />

double LotSize = (RiskAmount / argStopLoss) / TickValue;<br />

}<br />

else LotSize = argFixedLotSize;<br />

}<br />

return(LotSize);<br />

double VerifyLotSize(double argLotSize)<br />

{<br />

if(argLotSize < MarketInfo(Symbol(),MODE_MINLOT))<br />

{<br />

argLotSize = MarketInfo(Symbol(),MODE_MINLOT);<br />

}<br />

else if(argLotSize > MarketInfo(Symbol(),MODE_MAXLOT))<br />

{<br />

argLotSize = MarketInfo(Symbol(),MODE_MAXLOT);<br />

}<br />

if(MarketInfo(Symbol(),MODE_LOTSTEP) == 0.1)<br />

{<br />

argLotSize = NormalizeDouble(argLotSize,1);<br />

}<br />

else argLotSize = NormalizeDouble(argLotSize,2);<br />

}<br />

return(argLotSize);<br />

180

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

Saved successfully!

Ooh no, something went wrong!