Indicator · Pine Script v5 · On the chart

ATRLevels

by stupenkov· code credited to stupean

Calculates horizontal price levels anchored to the session open using the daily Average True Range (ATR).

View on GitHub

GitHub stars14on the repository
Pine versionv5runs as is
Lines of code76
Settings4inputs
LicenceNone statedfile: MPL-2.0
Last update3 years ago31 Aug 2023

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

76 lines of Pine Script v5 from Indicator/ATRLevels.pinescript, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

ATRLevels.pinescript
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © stupean

//@version=5
indicator("ATRLevels 1.0.0", overlay = true)

int atrLength = input.int(defval = 5, title = "Daily ATR length", minval = 1)
color defaultColor100 = input.color(defval = color.new(color.gray, 20), title = "100% lines")
color defaultColor50 = input.color(defval = color.new(color.gray, 50), title = "50% lines")
color defaultColor25 = input.color(defval = color.new(color.gray, 80), title = "25% and 75% lines")

type LevelOption
    float ratio
    color lvlColor
    string style = line.style_solid
    int width = 1 

type Options
    array<LevelOption> levelOptions

type Level
    line ln
    label lb

type ATRLevels
    array<Level> levels
    Options options

createDefaultLevelsOptions() =>
    array.from(
      LevelOption.new(1, defaultColor100),
      LevelOption.new(0.75, defaultColor25),
      LevelOption.new(0.5, defaultColor50),
      LevelOption.new(0.25, defaultColor25),
      LevelOption.new(0, defaultColor100),
      LevelOption.new(-0.25, defaultColor25),
      LevelOption.new(-0.5, defaultColor50),
      LevelOption.new(-0.75, defaultColor25),
      LevelOption.new(-1, defaultColor100))

enrichOptions(Options options) =>
    options.levelOptions := na(options.levelOptions) ? createDefaultLevelsOptions() : options.levelOptions

newInstance(Options options = na) =>
    Options _options = na(options) ? Options.new() : options
    enrichOptions(_options)
    array<Level> levels = array.new<Level>()
    for i = 0 to _options.levelOptions.size() - 1
        LevelOption lvlOption = _options.levelOptions.get(i)
        line ln = line.new(bar_index, open, bar_index, open, color = lvlOption.lvlColor)
        label lb = label.new(bar_index, open, str.format("{0,number,percent}", lvlOption.ratio), style = label.style_none, textcolor = lvlOption.lvlColor)
        Level lvl = Level.new(ln, lb)
        levels.push(lvl)
    ATRLevels.new(levels = levels, options = _options)

method update(ATRLevels this, float atr) =>
    float priceStep = atr / 4
    for i = 0 to this.levels.size() - 1
        Level lvl = this.levels.get(i)
        LevelOption lvlOption = this.options.levelOptions.get(i)
        line ln = lvl.ln
        label lb = lvl.lb
        ln.set_x2(bar_index + 300)
        if session.isfirstbar_regular
            float price = open + (lvlOption.ratio * atr)
            ln.set_x1(bar_index)
            ln.set_y1(price)
            ln.set_y2(price)
            lb.set_x(bar_index)
            lb.set_y(price)

// main
var Options options = Options.new(levelOptions = createDefaultLevelsOptions())
var ATRLevels atrLevels = newInstance(options)
float atr = request.security(syminfo.tickerid, "D", ta.atr(atrLength))[1]
atrLevels.update(atr)

Overview

ATRLevels retrieves the previous day ATR through a security call to project symmetrical upper and lower boundary bands across fractional ratios of the ATR range. Lines and percentage labels are plotted directly on the price chart and update at the beginning of each regular session. Key inputs allow adjusting the ATR lookback period and visual line styling. The script provides levels without built-in trading signals or execution rules.

Details

Published by

stupenkov on GitHub

Code credit

stupean, as written in the script's header

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Support & resistance, Volatility & bands

Markets

Crypto

Timeframes

M1-M5, M15-H1

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

cryptocurrencycrytocsharppinescripttradingview

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Daily ATR lengthint5atrLength
100% linescolorcolor.new(color.gray, 20)defaultColor100
50% linescolorcolor.new(color.gray, 50)defaultColor50
25% and 75% linescolorcolor.new(color.gray, 80)defaultColor25
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

ICT Liquidity Void Fill

by ArunKBhaskar
575 stars

This overlay indicator marks ICT liquidity void fills on the price chart and can show long and short signals. It places a Fibonacci level inside a displacement candle, defaulting to the midpoint, and draws lines in a chosen style. Optional filters limit the fi

Indicator v6 SMC / ICT / price actionSupport & resistance
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Liquidity Void Fill

[RS]Donchian Fans

by ricardosantos79
261 stars

This indicator plots Donchian Channel boundary lines along with dynamic fan projections directly on the price chart. It calculates the highest high, lowest low, and median price over a customizable lookback period. Whenever price establishes a new channel high

Indicator v4 Support & resistanceTrend
Updated 4 years ago · None stated GitHub repository of [RS]Donchian Fans

Snag - VWAP

by dearvn
257 stars

This indicator plots a custom Anchored Volume-Weighted Average Price (VWAP) directly on the price chart along with optional standard deviation bands. Users can anchor the VWAP to standard time periods like sessions, weeks, or months, or to corporate events suc

Indicator v5 Moving averagesVolatility & bands Repaints
Updated 6 weeks ago · None stated GitHub repository of Snag - VWAP

Candlestick Patterns

by harryguiacorn
219 stars

This indicator plots optional candlestick pattern signals on the price chart. It detects engulfing bars, inside bars, HOLP and LOHP, kicker patterns, body-mass extremes, higher highs and lower lows, ATR warnings, and four-bar fractals. Optional pivot marks use

Indicator v5 Candlestick patternsVolatility & bands
Updated 1 year ago · None stated GitHub repository of Candlestick Patterns

Dynamic Linear Regression

by TradersPost
218 stars

Dynamic Linear Regression calculates and plots linear regression trendlines and standard deviation channels directly on the price chart over a user-selected time period. Traders can configure static channels locked at the end time, dynamic channels that contin

Indicator v6 TrendSupport & resistance
Updated 3 months ago · None stated GitHub repository of Dynamic Linear Regression

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers