Skip to content

Make a Pine Script input to select a TradingView instrument symbol

Make a Pine Script input to select a TradingView instrument symbol

Section titled “Make a Pine Script input to select a TradingView instrument symbol”

TL;DR
Use input.symbol(defval, title=...) to present an instrument search box. Store the returned ticker string (e.g., "NASDAQ:QQQ") and feed it to request.security() or UI elements.

DifficultyBeginner
Time to implement10-15 min
CategoryInputs
//@version=5
indicator("Symbol picker demo", overlay=false)
otherSymbol = input.symbol("NASDAQ:QQQ", "Compare with")
otherClose = request.security(otherSymbol, timeframe.period, close)
plot(close, "Chart close")
plot(otherClose, "Other close", color=color.new(color.orange, 0))
Tip. Provide exchange prefixes in the default (`"NYSE:SPY"`) if you want TradingView to lock onto a specific listing. Otherwise it auto-fills the symbol’s default market.

Symbol inputs let end users compare assets, drive correlation stats, or synchronise signals across markets without editing code. Pairing the selection with request.security() keeps background data in sync with the active chart.

  • Configure input.symbol() with titles, groups, and tooltips.
  • Store the selected ticker string and reuse it in requests or labels.
  • Build comparison charts or lookups using request.security() and plotting helpers.
  • Handle edge cases when users clear or change the selection.
CallPurpose
input.symbol(defval, title=?, tooltip=?, group=?, inline=?, confirm=?)Renders the instrument picker.
request.security(symbol, timeframe, expression, ...)Loads data for the chosen instrument.
plot(series, title, color?)Visualises the comparison instrument.
label.new(x, y, text, ...)Annotates the chart with the selected ticker for clarity.
input.source()Optional companion input for selecting which price series to compare.
  1. Create the symbol input
    Supply a helpful default, a clear label, and optional grouping/tooltip text.

    otherSymbol = input.symbol("SP:SPX", "Benchmark", group="Comparison", tooltip="Instrument to compare against the chart")
  2. Load the selected instrument
    Request data from the returned symbol using the current chart period (timeframe.period) or a custom resolution.

    otherPrice = request.security(otherSymbol, timeframe.period, close)
  3. Display or use the data
    Plot, compute statistics, or emit alerts based on the secondary instrument.

    correlation = ta.correlation(close, otherPrice, 30)
    plot(correlation, "30-bar correlation", color=color.new(color.blue, 0))
//@version=5
indicator("Cross-market watcher", overlay=false)
benchmark = input.symbol("SP:SPX", "Benchmark symbol")
priceSrc = input.source(close, "Price source")
length = input.int(50, "Correlation length", minval=5)
benchmarkSeries = request.security(benchmark, timeframe.period, priceSrc)
correlation = ta.correlation(priceSrc, benchmarkSeries, length)
plot(correlation, "Correlation", color=color.new(color.green, 0))
hline(0.8, "High correlation", color=color.new(color.green, 60))
hline(0.0, "Neutral", color=color.new(color.gray, 60))
hline(-0.8, "Inverse correlation", color=color.new(color.red, 60))
if barstate.islast
label.new(bar_index, correlation,
text="Benchmark: " + benchmark + "\nLength: " + str.tostring(length),
style=label.style_label_left,
textcolor=color.white,
bgcolor=color.new(color.blue, 70))
Why this works.
  • The symbol input gives users control over which instrument to compare.
  • `request.security()` keeps benchmark data aligned with the chart timeframe.
  • A label reiterates the chosen ticker, reducing confusion when sharing screenshots.
  • Inputs require constant arguments. If you want dynamic defaults, compute them first, then pass the literal string.
  • Use the group argument to cluster related inputs (e.g., “Benchmark settings”).
  • When requesting intraday data on a higher-time-frame chart, specify a custom timeframe string inside request.security (e.g., "60").
  • Guard against na outputs if the benchmark lacks data for the requested period—wrap request.security in a conditional or use the ignore_invalid_symbol flag.

The input shows a different exchange than expected

Section titled “The input shows a different exchange than expected”

TradingView remembers the last exchange the user chose. Include the exchange prefix ("NYSE:IBM") in the default to force a specific listing.

request.security throws errors after changing the symbol

Section titled “request.security throws errors after changing the symbol”

Some instruments lack history at the sampled timeframe. Switch to a supported resolution or provide fallbacks (e.g., default to close if the request returns na).

Yes—create additional input.symbol() controls or accept comma-separated tickers and iterate through them in arrays.

  • input.symbol() adds a familiar instrument search box to Pine Script settings.
  • Store the returned ticker and feed it into request.security or display elements to leverage user selections.
  • Combine with other inputs (source, length) for flexible comparison or correlation tools.
  • Provide descriptive defaults and tooltips so users quickly understand what the picker controls.

Adapted from tradingcode.net, optimised for Algo Trade Analytics users.