If ( double false value);

Default values:


Returns true value if condition is true and false value otherwise. There are two ways to use the function. First, you can use it as the right side of an equation with 3 parameters: a condition, a true value and a false value. Secondly, you can use it in a conjunction with else to create more complex conditions.

Note that input arguments can only be numerical of type double. If other values are needed (e.g. Color constants), use the if-expression. E.g. for CustomColor arguments, the following code is valid:

AssignPriceColor(if close > open then Color.UPTICK else Color.DOWNTICK);

The following script will result in compilation error as type CustomColor is not compatible with type double:

AssignPriceColor(if(close > open, Color.UPTICK, Color.DOWNTICK));

Input parameters

Parameter Default value Description
condition - Defines condition to be tested.
true value - Defines value to be returned if condition is true.
false value - Defines value to be returned if condition is false.


plot Maximum1 = If(close > open, close, open);
plot Maximum2 = if close > open then close else open;
plot Maximum3;
if close > open {
Maximum3 = close;
} else {
Maximum3 = open;

The code draws either close or open value depending on the condition in the if-statement. If close is higher than open, then close is drawn, otherwise open is drawn. Maximum2 and Maximum3 plots use alternative solutions such as if-expression and if-statement correspondingly.