I’m learning Pine Script and recently came across the request.security() function. I understand that it’s used to get data from another timeframe or symbol, but I’m not sure how to use it correctly.
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:
–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.
Verified Solution
This is exactly what I am looking for thanks for explaining this concept in detail with the example and with the code also.– Radhesh JoshiJul 28