Error in TradingView Pine script: Could not find function or function reference 'iff'

Viewed 55

I want to write a script that plot a moving average.
I want the color to be dynamic (green when rising, red when falling).
I tried to use the iff function, but I get an error: Error: Could not find function or function reference 'iff'

//@version=5
indicator("SMA", overlay=true)
smaValue = ta.sma(close, 20)

// Error: Could not find function or function reference 'iff'.
smaColor = iff(smaValue[0] >= smaValue[1], color.green, color.red)

plot(smaValue, color=smaColor, title="SMA")
1 Answers

You can use a ternary instead in Pine @version 5:

smaColor = smaValue[0] >= smaValue[1] ? color.green : color.red
Related