iff
Syntax Format
iff(condition, then, else)
Overview
The iff
function is a functional version of the if … then … else … operator. The function returns the series with the values from the then and else arguments, depending on the condition. This is the safest and the shortest version of the ternary operator (?:), as Lua does not support ternary operators. This function makes the conditions clear and easy to access in a script.
Parameters
Parameter | Purpose |
---|---|
condition | The condition expression. Condition is considered to be false , if it is nil, nan, false or 0, true otherwise |
then | A value to be set for the current bar of the returned series if the condition is true |
else | A value to be set for the current bar of the returned series if the condition is false |
Returns: series
if any of the arguments is series
, numeric
otherwise.
Example
uptrend = conditional(close > open)
color = iff(uptrend [1], 'green', 'red')