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

extern bool UseTimer = true;<br />

extern bool UseLocalTime = false;<br />

extern int StartMonth = 6;<br />

extern int StartDay = 15;<br />

extern int StartHour = 7;<br />

extern int StartMinute = 0;<br />

extern int EndMonth = 6;<br />

extern int EndDay = 15;<br />

extern int EndHour = 2;<br />

extern int EndMinute = 30;<br />

And here is the code for checking whether to allow trading or not. The variable TradeAllowed<br />

determines whether to open new trades. If UseTimer is set to false, TradeAllowed is automatically<br />

set to true. Otherwise, we evaluate our start and end times in relation to the current time to see if we<br />

will allow trading or not.<br />

if(UseTimer == true)<br />

{<br />

// Convert start time<br />

string StartConstant = StringConcatenate(Year(),".",StartMonth,".",StartDay," ",<br />

StartHour,":",StartMinute);<br />

datetime StartTime = StrToTime(StartConstant);<br />

if(StartMonth == 12 && StartDay == 31 && EndMonth == 1) int EndYear = Year() + 1;<br />

else EndYear = Year();<br />

// Convert end time<br />

string EndConstant = StringConcatenate(EndYear,".",EndMonth,".",EndDay," ",<br />

EndHour,":",EndMinute);<br />

datetime EndTime = StrToTime(EndConstant);<br />

// Choose local or server time<br />

if(UseLocalTime == true) datetime CurrentTime = TimeLocal();<br />

else CurrentTime = TimeCurrent();<br />

// Check for trade condition<br />

if(StartTime CurrentTime)<br />

{<br />

bool TradeAllowed = true;<br />

}<br />

else TradeAllowed = false;<br />

}<br />

else TradeAllowed = true;<br />

116

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

Saved successfully!

Ooh no, something went wrong!