Home » Ticker Functions » Understanding the ticker.inherit() Function in Pine Script

Understanding the ticker.inherit() Function in Pine Script

Photo of author
Published on

This tutorial delves into the ticker.inherit() function, showcasing its syntax, usage, and practical applications through a detailed example.


The ticker.inherit() function is designed to create a new ticker ID for a specified symbol, inheriting additional parameters from another ticker ID. The syntax is as follows:

ticker.inherit(from_tickerID, symbol) → simple string


  • from_tickerID (simple string): The ticker ID whose modifiers are to be inherited.
  • symbol (simple string): The symbol for which the new ticker ID is constructed.



// Extended Hours ticker ID for AAPL.
extendedTickerAAPL = ticker.new("NASDAQ", "AAPL", session.extended)
// Heikin Ashi ticker ID for AAPL with Extended Hours.
heikinAshiTickerAAPL = ticker.heikinashi(extendedTickerAAPL)

// Test Symbol MSFT without modifiers.
plainSymbolMSFT = "NASDAQ:MSFT"
// Inherited Heikin Ashi and Extended Hours ticker ID for MSFT.
inheritedTickerMSFT = ticker.inherit(heikinAshiTickerAAPL, plainSymbolMSFT)

// Close price for MSFT with inherited modifiers.
modifiedClosePrice = request.security(inheritedTickerMSFT, "60", close, ignore_invalid_symbol = true)
// Close price for MSFT without modifiers.
basicClosePrice = request.security(plainSymbolMSFT, "60", close, ignore_invalid_symbol = true)

plot(modifiedClosePrice, color = color.green)

Detailed Code Walkthrough

  • Line-by-Line Explanation:
    • Indicator Declaration: The script starts with //@version=5 to specify it uses version 5 of Pine Script, followed by indicator("ticker.inherit") to declare a new indicator named “ticker.inherit”.
    • Creating Extended Hours Ticker ID for AAPL:
      • extendedTickerAAPL is defined using ticker.new("NASDAQ", "AAPL", session.extended). This line creates a ticker ID for Apple Inc. (AAPL) traded on NASDAQ with Extended Hours trading session enabled.
    • Creating Heikin Ashi Ticker ID for AAPL with Extended Hours:
      • heikinAshiTickerAAPL utilizes ticker.heikinashi(extendedTickerAAPL) to transform the previously defined AAPL ticker into a Heikin Ashi ticker while retaining the Extended Hours session modifier.
    • Defining Test Symbol MSFT without Modifiers:
      • plainSymbolMSFT is simply set to "NASDAQ:MSFT", representing Microsoft Corp. (MSFT) on NASDAQ without any session or other modifiers.
    • Inheriting Modifiers for MSFT Ticker ID:
      • inheritedTickerMSFT uses ticker.inherit(heikinAshiTickerAAPL, plainSymbolMSFT) to create a new ticker ID for MSFT, inheriting the Heikin Ashi and Extended Hours modifiers from the AAPL ticker.
    • Requesting Modified Close Price for MSFT:
      • modifiedClosePrice is obtained via request.security(inheritedTickerMSFT, "60", close, ignore_invalid_symbol = true), which requests the close price of MSFT on a 60-minute timeframe, using the inherited Heikin Ashi and Extended Hours modifiers.
    • Requesting Basic Close Price for MSFT:
      • basicClosePrice calls request.security(plainSymbolMSFT, "60", close, ignore_invalid_symbol = true) to fetch the close price for MSFT on a 60-minute timeframe without any modifiers.
    • Plotting the Data:
      • The script plots both the modified and basic close prices of MSFT on the chart. modifiedClosePrice is plotted in green to differentiate it from basicClosePrice, which uses the default color. This visual representation helps compare the impact of the inherited modifiers (Heikin Ashi and Extended Hours) on MSFT’s price data.

Key Features and Takeaways

  • Function Usability: ticker.inherit() enables seamless transition of modifiers (like Extended Hours, Heikin Ashi transformation) between different symbols, facilitating comparative analysis or strategy testing across multiple assets under similar conditions.
  • Syntax and Application: The function requires two simple string arguments: the source ticker ID and the symbol for the new ticker ID, making it straightforward to use within scripts.
  • Practical Implication: Inherited modifiers allow for more consistent and comparative analysis, especially when dealing with symbols across different markets or conditions.

Understanding and utilizing the ticker.inherit() function can significantly enhance the flexibility and depth of financial analysis and strategy development in Pine Script.

Leave a Comment