MQL4 If & Else Conditional Operators
Investing in assets such as stocks, bonds, cryptocurrencies, futures, options, and CFDs involves considerable risks. CFDs are especially risky with 74-89% of retail accounts losing money due to high leverage and complexity. Cryptocurrencies and options exhibit extreme volatility, while futures can also lead to significant losses. Even stocks and bonds can depreciate quickly during market downturns, and total loss can ensure if the issuing company fails. Furthermore, the stability of your broker matters; in case of bankruptcy, the presence of an effective investor compensation scheme is crucial for protecting your assets. It's vital to align these investments with your financial goals and if needed, consult with financial professionals to navigate complex financial markets.
We earn commissions from some affiliate partners at no extra cost to users (partners are listed on our ‘About Us’ page in the ‘Partners’ section). Despite these affiliations, our content remains unbiased and independent. We generate revenue through banner advertising and affiliate partnerships, which do not influence our impartial reviews or content integrity. Our editorial and marketing teams operate independently, ensuring the accuracy and objectivity of our financial insights.
![](/Content/dist/images/icons/CaretDown.png)
Data is continually updated by our staff and systems.
Last updated: 02/07/2020
![MQL4 If & Else Conditional Operators](../../../../Content/dist/articles/images/elkmgtiyo1j.jpg)
We use the conditional operators If and Else to construct our trading conditions. Learn in this MQL4 If & Else Conditional Operators article how to program the Expert Advisor to execute 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:
{OpenBuyOrder(…);
}
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.
You might also like to read: