Yes, request.security() is one of the most useful functions in Pine Script. It allows you to fetch data from a different symbol or timeframe while your script is running on the current chart.
The basic syntax is:
request.security(symbol, timeframe, expression)
Where:
–symbol is the symbol you want to get data from.
–timeframe is the timeframe of that data.
–expression is the value you want to retrieve, such as close, high, low, or even another indicator.
For example, suppose you’re on a 5-minute chart, but you want to use the 1-hour closing price in your indicator. You can do that like this:
//@version=6
indicator("Higher Timeframe Close", overlay = true)
htfClose = request.security(syminfo.tickerid, "60", close)
plot(htfClose, color = color.orange, linewidth = 2)
In this example:
–syminfo.tickerid tells Pine Script to use the current chart’s symbol.
–"60" represents the 1-hour timeframe.
–close returns the closing price from that timeframe.
The script then plots the 1-hour closing price directly on your current chart.
You can also use request.security() to retrieve values from other timeframes, calculate indicators on higher timeframes, or even fetch data from different symbols.
I hope this helps! If you have any questions about request.security() or want to explore more advanced use cases, feel free to ask again.