Edgoro
Compile error · Old code in v6 (v4 and v5 to v6)

Pine Script: Could not find function or function reference

Fix "Could not find function or function reference" in Pine Script v6: add the ta., math. or str. namespace, replace iff(), or check the function name.

Pine Editor console · line 3
Could not find function or function reference 'rsi'

Cause

The function name doesn't exist in this Pine Script version. Usually it is a v4 name without its namespace (rsi() is now ta.rsi()), a removed function such as iff(), a typo, or a function declared below the line that calls it.

Broken code

TradingView reports the error on line 3.

Pine Script v6
//@version=6
indicator("RSI")
r = rsi(close, 14)
plot(r)

Fixed code

The same script, corrected for Pine Script v6. Paste it into the Pine Editor and save.

Pine Script v6
//@version=6
indicator("RSI")
r = ta.rsi(close, 14)
plot(r, "RSI", color.purple)
hline(70, "Overbought")
hline(30, "Oversold")

Why it works

Pine Script v5 grouped the built-in functions into namespaces: indicators under ta., math under math., strings under str., data requests under request.. In most cases the name after the namespace stayed the same, so adding the prefix is the whole fix.

Common renames

v4v5 and v6
sma(), ema(), rsi(), atr()ta.sma(), ta.ema(), ta.rsi(), ta.atr()
crossover(), crossunder(), cross()ta.crossover(), ta.crossunder(), ta.cross()
highest(), lowest(), change()ta.highest(), ta.lowest(), ta.change()
valuewhen(), barssince()ta.valuewhen(), ta.barssince()
abs(), max(), min(), round()math.abs(), math.max(), math.min(), math.round()
tostring()str.tostring()
security()request.security()
study()indicator()
iff(cond, a, b)cond ? a : b

iff() and other causes

  • iff() was removed in v5. Could not find function or function reference 'iff' goes away with the ternary operator: iff(close > open, 1, 0) becomes close > open ? 1 : 0.
  • Your own function is declared further down. A user-defined function must be declared above the first line that calls it.
  • A library function without its import. Add import user/library/version as alias at the top and call alias.functionName().

Questions

What happened to iff() in Pine Script?

It was removed in v5. Use the ternary operator instead: condition ? valueIfTrue : valueIfFalse, or an if expression for longer branches.

How do I find the new name of an old Pine Script function?

Search the Pine Script v6 reference manual for the old name. Most v4 functions kept their name and moved into the ta., math., str. or request. namespace.

The scripts on this page are minimal examples written to show the error and its fix, not trading systems. Trading involves substantial risk of loss and is not suitable for every investor. Edgoro is a software tool, not a broker or financial adviser: nothing it produces is investment advice, and past or backtested performance does not guarantee future results.

Still getting an error?

Paste your script and the message into the free Pine Script error fixer: it explains what went wrong and returns a corrected v6 version. Or describe the indicator in plain English and let Edgoro write the code.