Home » Ticker Functions » ticker.new Function in Pine Script

ticker.new Function in Pine Script

Photo of author
Published on

In this tutorial, we will deep dive into the ticker.new function of Pine Script, a powerful feature that allows users to request additional data for their scripts. Whether you’re designing a custom indicator or strategy in TradingView, this function can significantly enhance your ability to pull and process data.

What is ticker.new Function?

ticker.new is a Pine Script function that creates a ticker identifier for requesting additional data. This function is especially useful when you need to access data of a different ticker or a modified version of the current ticker in your script.

Syntax

ticker.new(prefix, ticker, session, adjustment) → simple string

Arguments

  • prefix (simple string): The exchange prefix. Examples include ‘BATS’, ‘NYSE’, ‘NASDAQ’. To get the exchange prefix of the main series, use syminfo.prefix.
  • ticker (simple string): The ticker name. Examples are ‘AAPL’, ‘MSFT’, ‘EURUSD’. To get the ticker name of the main series, utilize syminfo.ticker.
  • session (simple string, optional): Defines the session type. Possible values include session.regular and session.extended. If not specified, syminfo.session value is used.
  • adjustment (simple string, optional): Type of adjustment. Potential values are adjustment.none, adjustment.splits, and adjustment.dividends. If not provided, the default adjustment value (which may vary) is utilized.

Use-Case Example

Let’s dissect an example to understand the function’s practical application:

//@version=5
indicator("ticker.new", overlay=true)
t = ticker.new(syminfo.prefix, syminfo.ticker, session.regular, adjustment.splits)
t2 = ticker.heikinashi(t)
c = request.security(t2, timeframe.period, low, barmerge.gaps_on)
plot(c, style=plot.style_linebr)
ticker.new Function in Pine Script

Code Explanation

  1. //@version=5: Specifies the Pine Script version.
  2. indicator("ticker.new", overlay=true): Defines an indicator with a name “ticker.new” and overlays it on the main price chart.
  3. t = ticker.new(syminfo.prefix, syminfo.ticker, session.regular, adjustment.splits): Creates a ticker identifier for the current instrument’s regular session with split adjustments.
  4. t2 = ticker.heikinashi(t): Converts the ticker data to a Heikin Ashi representation.
  5. c = request.security(t2, timeframe.period, low, barmerge.gaps_on): Requests the low of the Heikin Ashi ticker for the current timeframe, considering gaps in data.
  6. plot(c, style=plot.style_linebr): Plots the requested data using the line break style.

Returns

The function returns a string value of a ticker ID, which can then be supplied to the request.security function.

Remarks

It’s worth noting that you can utilize the return value of the ticker.new function as an input argument for various other functions like ticker.heikinashi, ticker.renko, ticker.linebreak, ticker.kagi, and ticker.pointfigure.

Key Takeaway

The ticker.new function in Pine Script is a versatile tool that aids in creating custom ticker identifiers to request additional data or modified versions of current tickers. By understanding its arguments and how to effectively utilize them, traders and developers can build more dynamic and data-rich scripts on TradingView.

Conclusion

Understanding the ticker.new function is crucial for any Pine Script developer looking to leverage additional data streams or modify existing ones. Whether you’re pulling data from a different exchange, a distinct ticker, or applying adjustments, this function provides the flexibility needed for robust script development. Happy coding!

Leave a Comment