Home Forums Trading view How to use request.security() in Pine Script?

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

  • Author
    Posts
    • 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!

    • 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.

    • This is exactly what I am looking for thanks for explaining this concept in detail with the example and with the code also.

Viewing 2 reply threads
×

Start a Discussion

Get help from the AlgoDelta community.

×

Welcome Back!

Enter your email to sign in or create an account. No passwords needed.

⚠️

Delete This?

Are you sure you want to delete this? This action is permanent and cannot be undone.

Scroll to Top