IfThenElse Function

Top  Previous  Next

Returns the second parameter value if the first parameter value is true. Returns the third parameter value if the first parameter value is false. This function is analogous to the Microsoft Excel IF function.

 

Syntax

 

value = IfThenElse( condition, trueValue, falseValue )

 

Parameters

condition

 

a condition that evaluates to true or false

trueValue

 

the value returned if condition is TRUE

falseValue

 

the value returned if condition is FALSE

 

 

 

returns

 

trueValue if condition is TRUE otherwise falseValue

 

Examples

 

value = IfThenElse( 1 = 2, 3, 4 )  ' Returns 4

value = IfThenElse( 2 = 2, 3, 4 )  ' Returns 3

 

This function is useful in calculated indicators, where you can only enter an expression.

 

Example of calculated indicator which will return the true low of the day. This could be part of a true range calculation:

 

IfThenElse( instrument.close[1] < instrument.low, instrument.close[1], instrument.low )