We use the conditional operators if and else to construct our trading conditions.
The if operator evaluates a true and false condition. If the condition is true, the code immediately after the if statement is executed. If the condition is false, it will skip ahead to the code following the if block:
If there is only one statement folowing the if operator, it can be written like this:
Multiple statements must be enclosed in braces.
The else operator evaluates an alternative condition, provided that the previous if statement(s) are false. You can combine else and if to create an alternative condition that will only be executed if it is true.
For example, this code evaluates three conditions in order. If one of them is true, only that block of code will be executed. If none of them are true, none of them will be executed:
else if (Condition2 = true) // execute condition2
else if (Condition3 = true) // execute condition3
The else operator can be used by itself at the end of an if-else sequence to indicate a condition that will be executed by default if all of the other if operators are false.