Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

smaColor = smaValue[0] >= smaValue[1] ? color.green : color.red
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading