lesson 4

/Tag:lesson 4

Multicharts Tutorial – Lesson 04: If statements and conditional branching

Multicharts Tutorial - Lesson 04: If statements and conditional branching Learn how to execute code expressions based on conditions In today's lesson you will learn how to control your program flow and make it execute parts only when certain conditions are met. This is where if statements are used. You can find them in basically every high level programming language and they are the engine that drives each program. If statements can for example be used in coloring a moving average differently based on its relation to the close of a bar. If you want to close all open positions after a certain time, an if statement will come into play. In case you want to trigger an alert when a predefined condition is met, you will also use an if statement for that. This list could go on for quite some time, but I think you already understand that if statements are not only very useful, but also very important. No programming tutorial could be complete without going over them and a good understanding is essential before we can move to more complex things. if...then... The "if...then..." statement is the simplest form of a conditional statement. The condition is tested and if it's true the following code statement will be executed. If the test is false nothing will be done as the following code statement will not be executed. When I say the test is true, don't get confused and think you are limited to testing conditions that include "true" only. In case "ii" is a numeric variable and "MyCondition1" and "MyCondition2" are boolean variables these are three valid "if...then..." statements. In case of the first statement the code checks for [...]