How to use request.security() in Pine Script?

Asked by Radhesh Joshi · SOLVED
1 reply 369 views Jump to solution Reply
Radhesh Joshi Original Post
Strategy Builder

Hi everyone,

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.

Can someone explain what request.security()  ?

Thanks in advance!

Posted Jul 26
Reply

    1 Reply

    Tech Support AlgoDelta
    Tech Support AlgoDelta Automation Expert ·

    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.

    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 Joshi Jul 28
    Markdown supported · ```json for code blocks · paste or drop screenshots

    Be specific and kind. Never share API keys, passwords or personal account details.

    Welcome to the community

    Log in or create your account in under a minute.

    1. 1Mobile
    2. 2E-mail
    3. 3Password
    +91

    Have a password?

    By continuing you agree to the community guidelines. We’ll send a one-time code by SMS.