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

Understanding the ticker.modify() Function in Pine Script

Photo of author
Published on

The ticker.modify() function in Pine Script is a versatile tool used to create a modified ticker identifier, which is essential for requesting additional data within a script. This functionality is particularly useful when working with financial market data, allowing scripts to adapt to different trading sessions and data adjustments dynamically. Let’s dive into the details of how this function works, its syntax, and how to effectively utilize it in your Pine Script projects.


The syntax of the ticker.modify() function is as follows:

ticker.modify(tickerid, session, adjustment) → simple string
  • tickerid (simple string): This is the symbol name including the exchange prefix, like ‘BATS:MSFT’ or ‘NASDAQ:MSFT’, or a ticker ID that has already been modified using the ticker.new function with session and adjustment parameters.
  • session (simple string, optional): Defines the session type with possible values being session.regular or session.extended. The default value is syminfo.session, which corresponds to the session type of the current chart.
  • adjustment (simple string, optional): Specifies the adjustment type with options including adjustment.none, adjustment.splits, and adjustment.dividends. The default value depends on the instrument and might vary.

Example Explained

Let’s examine a practical example to understand how to implement the ticker.modify() function in a script.

indicator("ticker_modify_example", overlay=true)
t1 = ticker.new(syminfo.prefix, syminfo.ticker, session.regular, adjustment.splits)
c1 = request.security(t1, "D", close)
t2 = ticker.modify(t1, session.extended)
c2 = request.security(t2, "2D", close)

Walkthrough of Code 

In this example, the script begins by declaring its version and setting overlay=true to display the indicator directly on the chart. The script then:

  1. Creates a new ticker ID (t1) using ticker.new(), specifying the current symbol’s prefix and ticker, and setting the session to regular and adjustment to splits. This ticker ID is used to request the daily closing price (c1).
  2. Modifies the original ticker ID (t2) using ticker.modify(), changing the session to extended but keeping the adjustment type the same. This modified ticker ID is then used to request the closing price for a 2-day period (c2).
  3. Plots both closing prices (c1 and c2) on the chart, allowing comparison between regular session data with splits adjustment and extended session data with the same adjustment.

Key Features and Takeaways

  • Functionality: The ticker.modify() function enables dynamic modification of ticker IDs to adapt to different trading sessions and data adjustments.
  • Flexibility: Optional arguments for session and adjustment types allow for flexible data requests tailored to specific analysis needs.
  • Application: This function is particularly useful in multi-timeframe analysis or when comparing data across different trading sessions.
  • Syntax: Understanding the syntax and the optional parameters is crucial for effectively utilizing this function in your scripts.

By incorporating the ticker.modify() function into your Pine Script projects, you can enhance your financial market analyses with dynamic data requests, accommodating various trading sessions and data adjustment needs.

Leave a Comment