How can I create an ATR indicator in Pine Script?

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

I’m creating my own technical indicators in Pine Script and want to build an ATR indicator from scratch instead of using the built-in ATR.

I want to understand how ATR measures market volatility and how the ATR value is calculated using the selected period.

What is the correct way to create an ATR indicator in Pine Script?

Posted Aug 19
Reply

    1 Reply

    Tech Support AlgoDelta
    Tech Support AlgoDelta Automation Expert ·

    Yes sir, you can definitely create an ATR indicator in Pine Script.

    ATR, or Average True Range, is a volatility indicator that measures the average range of price movement over a selected period.

    The True Range considers the current High-Low range as well as the previous candle’s Close.

    You can create a basic ATR indicator using:

    //@version=6
    indicator("Custom ATR", overlay=false)
    atrLength = input.int(14, "ATR Length")
    trueRange = ta.tr(true)
    atrValue = ta.rma(trueRange, atrLength)
    plot(atrValue, "ATR", color = color.red)

    -> ta.tr(true) calculates the True Range.

    -> ta.rma() calculates the moving average of the True Range, which gives us the ATR.

    -> The default ATR length is 14, but users can change it from the indicator settings.

    => A higher ATR value generally indicates higher market volatility, while a lower ATR value indicates lower volatility.

    So that’s how you can create a basic ATR indicator from scratch in Pine Script.

    Verified Solution
      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.