βœ–

Home Forums Pine Script How can I create an ATR indicator in Pine Script?

How can I create an ATR indicator in Pine Script?

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

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

Viewing 1 reply thread
×

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