Branching Commands
<< Click to Display Table of Contents >> Branching Commands |
Branching controls the flow of execution in your script. It allows you to branch into separate logical sequences based on logical conditions.
An if statement allows you to execute different paths of logic depending on a given condition.
// Single case condition |
The above example will print "NinjaTrader" to the NinjaScript Output window, since x is equal to 0.
// Either/Or decision |
The above example will print "NinjaScript" to the NinjaScript Output window, since x is not equal to 0.
// Multiple case decision |
The above example will print "My Algorithm" to the NinjaScript Output window, since x is not equal to either 0 or 1.
The switch statement executes a set of logic depending on the value of a given parameter.
// Switch example |
The above example will print out "x is equal to two" to the NinjaScript Output window. The other two case statements will not be executed, since their conditions do not evaluate to true.