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

Pine Script: Could not find function 'security' (fix)

security() became request.security() in Pine Script v5. Fix the error and request higher-timeframe data in v6 without repainting.

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

Cause

security() is the v4 name of the function that requests data from another symbol or timeframe. Since v5 it lives in the request namespace as request.security().

Broken code

TradingView reports the error on line 3.

Pine Script v6
//@version=6
indicator("Daily close", overlay = true)
dailyClose = security(syminfo.tickerid, "D", close)
plot(dailyClose)

Fixed code

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

Pine Script v6
//@version=6
indicator("Daily close", overlay = true)
dailyClose = request.security(syminfo.tickerid, "D", close[1], lookahead = barmerge.lookahead_on)
plot(dailyClose, "Previous daily close", color.orange)

Why it works

The arguments are the same: symbol, timeframe, expression. The fixed version also changes the request to the usual non-repainting form: close[1] with lookahead = barmerge.lookahead_on returns the last completed daily close on every bar, historical and live alike, so the line doesn't change after the fact. A plain request.security(syminfo.tickerid, "D", close) also compiles, but on the live bar it shows the daily close as it forms. More in how request.security works and repainting explained.

Other renamed request functions and variables

v4v5 and v6
security()request.security()
financial()request.financial()
quandl()request.quandl()
tickeridsyminfo.tickerid
periodtimeframe.period

The old variable names give Undeclared identifier "tickerid" and Undeclared identifier "period" rather than a "could not find function" message.

Questions

What is the v5 and v6 version of security()?

request.security(symbol, timeframe, expression). The arguments are the same as in v4; only the name moved into the request namespace.

Why does my request.security() line look different in real time?

Requesting the current higher-timeframe close shows a value that is still forming on the live bar, while historical bars show final values. Use close[1] with lookahead = barmerge.lookahead_on to get only completed values.

How many request.security() calls can a script make?

Up to 40 unique request.*() calls per script, or 64 with TradingView's Ultimate plan. Identical calls are reused rather than counted again.

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.