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")
>Solution :
You can use a ternary instead in Pine @version 5:
smaColor = smaValue[0] >= smaValue[1] ? color.green : color.red