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

Multiple statements must be enclosed in braces.<br />

The else operator evaluates an alternate condition, provided that the previous if statement(s) are<br />

false. You can combine else and if to create an alternate condition that will only be executed if it's<br />

true.<br />

For example, this code evaluates three conditions in order. If one of them is true, only that block of<br />

code will be executed. If none of them are true, none of them will be executed:<br />

if(Condition1 == true) // Execute condition 1<br />

else if(Condition2 == true) // Execute condition 2<br />

else if(Condition3 == true) // Execute condition 3<br />

The else operator can be used <strong>by</strong> itself at the end of an if-else sequence to indicate a condition<br />

that will be executed <strong>by</strong> default if all of the other if operators are false. As above, only one of the<br />

conditions will be executed:<br />

if(Condition1 == true) // Execute condition 1<br />

else if(Condition2 == true) // Execute condition 2<br />

else<br />

{<br />

// Execute condition 3 if 1 and 2 are false<br />

}<br />

If you have multiple if operators without any else operators, each one will be executed if it is true –<br />

it doesn't matter whether the subsequent if statement is true or false:<br />

if(Condition1 == true) // Execute condition 1<br />

if(Condition2 == true) // Execute condition 2<br />

Relation Operations<br />

We begin evaluating true and false conditions <strong>by</strong> comparing values using greater than, less than,<br />

equal to, not equal to and so on. Here's a list of relation operations:<br />

• == Equal To – If x == y, the condition is true.<br />

• > Greater Than – If x > y, the condition is true.<br />

• < Less Than – If x < y, the condition is true.<br />

• >= Greater Than or Equal To – If x >= y, the condition is true.<br />

104

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

Saved successfully!

Ooh no, something went wrong!