Home » Symbol Information Functions » syminfo.ticker Function in Pine Script

syminfo.ticker Function in Pine Script

Photo of author
Published on

Pine Script plays a pivotal role. Being the coding language of the widely used trading platform TradingView, it offers a variety of built-in functions that are tremendously useful to traders and developers alike. Among them, the syminfo.ticker function has its unique application. This tutorial aims to explore the depths of the syminfo.ticker function, unravel its functionality, syntax, and its practical use cases.

Decoding the syminfo.ticker Function

The syminfo.ticker function is a built-in function in Pine Script that returns the ticker symbol of a security without the exchange prefix. For example, for a security symbol “NASDAQ:AAPL”, the syminfo.ticker function will return “AAPL”.

Its syntax looks like this:

pinescriptCopy code
syminfo.ticker(symbol) → simple string
syminfo.ticker(symbol) → series string

Here, the ‘symbol’ is a string input that represents a particular security on a trading platform. This symbol should be passed with a prefix like “NASDAQ:AAPL” instead of just “AAPL”.

Illustrating with an Example

Consider the following script, which depicts the practical usage of the syminfo.ticker function.

//@version=5
indicator("syminfo.ticker fun", overlay=true)
i_sym = input.symbol("NASDAQ:AAPL")
pref = syminfo.prefix(i_sym)
tick = syminfo.ticker(i_sym)
t = ticker.new(pref, tick, session.extended)
s = request.security(t, "1D", close)
plot(s)
syminfo.ticker function

Here’s the line-by-line explanation:

  • indicator("syminfo.ticker fun", overlay=true) : This line sets the indicator’s name and states that the plot should be displayed in the price chart’s overlay.
  • i_sym = input.symbol("NASDAQ:AAPL") : The input.symbol function is used to take a symbol as an input from the user. Here, we’re providing “NASDAQ:AAPL” as the default symbol.
  • pref = syminfo.prefix(i_sym) : This line fetches the exchange prefix for the input symbol using the syminfo.prefix function.
  • tick = syminfo.ticker(i_sym) : We’re using the syminfo.ticker function to extract the ticker symbol (“AAPL”) from the input symbol (“NASDAQ:AAPL”).
  • t = ticker.new(pref, tick, session.extended) : The ticker.new function is used to construct a new ticker ID using the prefix, ticker, and the session type.
  • s = request.security(t, "1D", close) : The request.security function fetches the daily closing price for the ticker ID created in the previous line.
  • plot(s) : Finally, the plot function is used to plot the closing prices on the chart.

Key Takeaway

Understanding the syminfo.ticker function is crucial for any developer working with Pine Script. Its ability to extract the symbol name allows you to manipulate ticker information more flexibly, which is essential when handling multiple securities or changing symbols dynamically.

Conclusion

In conclusion, syminfo.ticker is a valuable function in Pine Script for extracting and manipulating symbol information. The possibilities are endless once you understand its working, as demonstrated in the example above. As you continue your journey in Pine Script, harness the power of syminfo.ticker and other functions to make the most of your coding and trading experience.

Leave a Comment