Working with code becomes more and more flexible! If-statement is now available in Pine Script language. This statement defines what block of statements must be checked when conditions of the expression are satisfied.
Attention! To have access to and use the if statement, one should specify the version of Pine Script language in the very first line of code: //@version=2
//@version=2 study("if statement") out = if close > open high else low plot(out)
You can read more about if statement in the Pine Script Tutorial.
If statement may be also useful in strategy trading:
//@version=2 strategy("My Strategy", overlay=true) longCondition = crossover(sma(close, 14), sma(close, 28)) if (longCondition) strategy.entry("My Long Entry Id", strategy.long) shortCondition = crossunder(sma(close, 14), sma(close, 28)) if (shortCondition) strategy.entry("My Short Entry Id", strategy.short)