Home » Ticker Functions » Understanding the request.security() Function in Pine Script

Understanding the request.security() Function in Pine Script

Photo of author
Published on

The request.security() function plays a pivotal role in this analysis. This article will delve into the intricacies of this function, providing a comprehensive understanding of its usage and applications.

What is request.security()?

Overview

The request.security() function in Pine Script is designed to fetch price data or other information from a different symbol, timeframe, or context than the one currently being analyzed. This function allows script writers to incorporate data from various markets or instruments into their analysis, enabling more complex and informed decision-making.

Syntax

modifiedData = request.security(symbol, timeframe, expression, gaps, lookahead)
  • symbol: Refers to the ticker of the market you want to access (e.g., “NASDAQ:AAPL” for Apple on NASDAQ).
  • timeframe: Specifies the timeframe for the data (e.g., “60” for 60-minute bars).
  • expression: The calculation or data to fetch from the specified symbol and timeframe.
  • gaps: Controls how to handle gaps in the data (optional).
  • lookahead: Determines if future data should be accessible in historical bars (optional).

Basic Example: Plotting Another Symbol’s Closing Price

Simplified Script

//@version=5
indicator("Other Symbol Close Price", overlay=true)

// Defining the symbol
otherSymbol = "NASDAQ:MSFT"

// Fetching the closing price of the other symbol
msftClose = request.security(otherSymbol, "D", close)

// Plotting the fetched close price
plot(msftClose, color=color.red, title="MSFT Daily Close")
Example

Script Breakdown

  1. Indicator Setup: The script begins with setting up the indicator properties.
  2. Defining the Other Symbol: otherSymbol is set to Microsoft’s NASDAQ symbol.
  3. Fetching Data with request.security(): The msftClose variable uses request.security() to fetch the daily closing price of Microsoft.
  4. Plotting the Data: The fetched closing price (msftClose) is plotted on the chart .

Key Points in This Example

  • Simplicity: The example is simplified to focus solely on fetching and plotting another symbol’s closing price.
  • Direct Application: This script directly illustrates the primary use of request.security() – accessing data from a different symbol.
  • Clear Visualization: Plotting the data with a distinct color helps in easy comparison and analysis.

Takeaways

  • request.security() is highly effective for accessing and comparing data across different symbols.
  • Simplified examples can provide a clearer understanding of a function’s basic usage.
  • Pine Script’s versatility allows for straightforward implementation of such functionalities.

2 thoughts on “Understanding the request.security() Function in Pine Script”

  1. Hi, I am trying to use NQ1! from CME as the request security, but it is saying that the ticker is invalid. Are you aware of this issue and any work arounds?

    Reply

Leave a Comment