Indicator · Pine Script v6 · On the chart

Zen Bar Range Projections

by Zen-Tim

Zen Bar Range Projections draws two independent higher-timeframe projections on the price chart.

View on GitHub

GitHub stars29on the repository
Pine versionv6current
Lines of code155
Settings30inputs
LicenceMIT
Last update2 weeks ago14 Oct 2026

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

155 lines of Pine Script v6 from indicators/Zen-Bar-Range-Projections/Zen_Bar_Range_Projections_v2.1_20260509.txt, published under MIT. Keep the author's credit and licence lines when you reuse it.

Zen_Bar_Range_Projections_v2.1_20260509.txt
//@version=6
indicator('Zen Bar Range Projections v2.1', shorttitle='ZBR Proj v2.1', overlay=true, max_lines_count=200)
// ============================================================================
//  Zen Bar Range Projections v2.1 · 20260509
//  Dual independent HTF projections of 0.5x / 1x / 2x ABR from HTF close.
//  Pattern: [close[1], (high-low)[1]] inside request.security with lookahead_on
//           gives the closed HTF bar's close and range directly. Snapshot on
//           rollover, anchor at bar_index - 1 (last chart bar of closed HTF).
// ============================================================================

int max_sets = 12

// ============================================================================
//  HTF 1
// ============================================================================
bool    h1_on        = input.bool(true,  "Enable HTF 1",                                                group="HTF 1")
string  h1_tf        = input.timeframe("15", "Timeframe",                                                group="HTF 1")
int     h1_lookback  = input.int(8,  "ABR Lookback",  minval=1, maxval=50,                               group="HTF 1")
int     h1_bars_back = input.int(10, "Bars Back (0 = last only, 11 = twelve sets)", minval=0, maxval=11, group="HTF 1")
int     h1_length    = input.int(2,  "Line Length (bars)",      minval=1, maxval=50,                     group="HTF 1")
int     h1_thickness = input.int(1,  "Line Thickness",          minval=1, maxval=4,                      group="HTF 1")
bool    h1_show_05   = input.bool(true,  "Show 0.5x",                                                    group="HTF 1")
bool    h1_show_1    = input.bool(true,  "Show 1x",                                                      group="HTF 1")
bool    h1_show_2    = input.bool(false, "Show 2x",                                                      group="HTF 1")
color   h1_c_05_up   = input.color(color.new(#2196F3, 50), "0.5x up",                                    group="HTF 1 Colours")
color   h1_c_05_dn   = input.color(color.new(#FF0000, 50), "0.5x down",                                  group="HTF 1 Colours")
color   h1_c_1_up    = input.color(color.new(#2196F3, 0),  "1x up",                                      group="HTF 1 Colours")
color   h1_c_1_dn    = input.color(color.new(#FF0000, 0),  "1x down",                                    group="HTF 1 Colours")
color   h1_c_2_up    = input.color(color.new(#2196F3, 0),  "2x up",                                      group="HTF 1 Colours")
color   h1_c_2_dn    = input.color(color.new(#FF0000, 0),  "2x down",                                    group="HTF 1 Colours")

// ============================================================================
//  HTF 2 — green up, orange down for visual distinction from HTF 1
// ============================================================================
bool    h2_on        = input.bool(true,  "Enable HTF 2",                                                group="HTF 2")
string  h2_tf        = input.timeframe("60", "Timeframe",                                                group="HTF 2")
int     h2_lookback  = input.int(8,  "ABR Lookback",  minval=1, maxval=50,                               group="HTF 2")
int     h2_bars_back = input.int(5,  "Bars Back (0 = last only, 11 = twelve sets)", minval=0, maxval=11, group="HTF 2")
int     h2_length    = input.int(4,  "Line Length (bars)",      minval=1, maxval=50,                     group="HTF 2")
int     h2_thickness = input.int(2,  "Line Thickness",          minval=1, maxval=4,                      group="HTF 2")
bool    h2_show_05   = input.bool(true,  "Show 0.5x",                                                    group="HTF 2")
bool    h2_show_1    = input.bool(true,  "Show 1x",                                                      group="HTF 2")
bool    h2_show_2    = input.bool(false, "Show 2x",                                                      group="HTF 2")
color   h2_c_05_up   = input.color(color.new(#26A69A, 50), "0.5x up",                                    group="HTF 2 Colours")
color   h2_c_05_dn   = input.color(color.new(#FF9800, 50), "0.5x down",                                  group="HTF 2 Colours")
color   h2_c_1_up    = input.color(color.new(#26A69A, 0),  "1x up",                                      group="HTF 2 Colours")
color   h2_c_1_dn    = input.color(color.new(#FF9800, 0),  "1x down",                                    group="HTF 2 Colours")
color   h2_c_2_up    = input.color(color.new(#26A69A, 0),  "2x up",                                      group="HTF 2 Colours")
color   h2_c_2_dn    = input.color(color.new(#FF9800, 0),  "2x down",                                    group="HTF 2 Colours")

// ============================================================================
//  HTF DATA — closed HTF bar's close and range, every chart bar
// ============================================================================
[h1_close, h1_range] = request.security(syminfo.tickerid, h1_tf, [close[1], (high - low)[1]], lookahead=barmerge.lookahead_on)
[h2_close, h2_range] = request.security(syminfo.tickerid, h2_tf, [close[1], (high - low)[1]], lookahead=barmerge.lookahead_on)

// ============================================================================
//  HISTORY ARRAYS — snapshot when HTF rolls over
// ============================================================================
var array<int>   h1_anchors = array.new_int(0)
var array<float> h1_closes  = array.new_float(0)
var array<float> h1_ranges  = array.new_float(0)
var array<float> h1_abrs    = array.new_float(0)

var array<int>   h2_anchors = array.new_int(0)
var array<float> h2_closes  = array.new_float(0)
var array<float> h2_ranges  = array.new_float(0)
var array<float> h2_abrs    = array.new_float(0)

bool h1_roll = ta.change(time(h1_tf)) != 0
bool h2_roll = ta.change(time(h2_tf)) != 0

if h1_roll
    array.unshift(h1_anchors, bar_index - 1)
    array.unshift(h1_closes,  h1_close)
    array.unshift(h1_ranges,  h1_range)
    float abr_now = na
    if array.size(h1_ranges) >= h1_lookback
        float sum = 0.0
        for i = 0 to h1_lookback - 1
            sum += array.get(h1_ranges, i)
        abr_now := sum / h1_lookback
    array.unshift(h1_abrs, abr_now)
    if array.size(h1_anchors) > max_sets
        array.pop(h1_anchors)
        array.pop(h1_closes)
        array.pop(h1_ranges)
        array.pop(h1_abrs)

if h2_roll
    array.unshift(h2_anchors, bar_index - 1)
    array.unshift(h2_closes,  h2_close)
    array.unshift(h2_ranges,  h2_range)
    float abr_now = na
    if array.size(h2_ranges) >= h2_lookback
        float sum = 0.0
        for i = 0 to h2_lookback - 1
            sum += array.get(h2_ranges, i)
        abr_now := sum / h2_lookback
    array.unshift(h2_abrs, abr_now)
    if array.size(h2_anchors) > max_sets
        array.pop(h2_anchors)
        array.pop(h2_closes)
        array.pop(h2_ranges)
        array.pop(h2_abrs)

// ============================================================================
//  DRAW HELPER
// ============================================================================
draw_set(array<line> store, int slot_base, int x1, int x2, float c, float a, bool s_05, bool s_1, bool s_2, color c_05u, color c_05d, color c_1u, color c_1d, color c_2u, color c_2d, int thick) =>
    if s_05
        array.set(store, slot_base,     line.new(x1, c + 0.5 * a, x2, c + 0.5 * a, xloc=xloc.bar_index, color=c_05u, width=thick, style=line.style_dashed))
        array.set(store, slot_base + 1, line.new(x1, c - 0.5 * a, x2, c - 0.5 * a, xloc=xloc.bar_index, color=c_05d, width=thick, style=line.style_dashed))
    if s_1
        array.set(store, slot_base + 2, line.new(x1, c + 1.0 * a, x2, c + 1.0 * a, xloc=xloc.bar_index, color=c_1u,  width=thick, style=line.style_solid))
        array.set(store, slot_base + 3, line.new(x1, c - 1.0 * a, x2, c - 1.0 * a, xloc=xloc.bar_index, color=c_1d,  width=thick, style=line.style_solid))
    if s_2
        array.set(store, slot_base + 4, line.new(x1, c + 2.0 * a, x2, c + 2.0 * a, xloc=xloc.bar_index, color=c_2u,  width=thick, style=line.style_dotted))
        array.set(store, slot_base + 5, line.new(x1, c - 2.0 * a, x2, c - 2.0 * a, xloc=xloc.bar_index, color=c_2d,  width=thick, style=line.style_dotted))

// ============================================================================
//  DRAW
// ============================================================================
var array<line> h1_lines = array.new_line(max_sets * 6, na)
var array<line> h2_lines = array.new_line(max_sets * 6, na)

if barstate.islast
    for i = 0 to array.size(h1_lines) - 1
        line.delete(array.get(h1_lines, i))
        array.set(h1_lines, i, na)
    for i = 0 to array.size(h2_lines) - 1
        line.delete(array.get(h2_lines, i))
        array.set(h2_lines, i, na)

    if h1_on
        int sets = h1_bars_back + 1
        for s = 0 to sets - 1
            if s < array.size(h1_anchors)
                int   x1  = array.get(h1_anchors, s)
                float c   = array.get(h1_closes,  s)
                float abr = array.get(h1_abrs,    s)
                if not na(x1) and not na(c) and not na(abr)
                    int x2 = x1 + h1_length
                    draw_set(h1_lines, s * 6, x1, x2, c, abr, h1_show_05, h1_show_1, h1_show_2, h1_c_05_up, h1_c_05_dn, h1_c_1_up, h1_c_1_dn, h1_c_2_up, h1_c_2_dn, h1_thickness)

    if h2_on
        int sets = h2_bars_back + 1
        for s = 0 to sets - 1
            if s < array.size(h2_anchors)
                int   x1  = array.get(h2_anchors, s)
                float c   = array.get(h2_closes,  s)
                float abr = array.get(h2_abrs,    s)
                if not na(x1) and not na(c) and not na(abr)
                    int x2 = x1 + h2_length
                    draw_set(h2_lines, s * 6, x1, x2, c, abr, h2_show_05, h2_show_1, h2_show_2, h2_c_05_up, h2_c_05_dn, h2_c_1_up, h2_c_1_dn, h2_c_2_up, h2_c_2_dn, h2_thickness)

Overview

For each enabled timeframe it measures the average bar range over a chosen lookback, then places horizontal lines at 0.5, 1 and 2 times that range above and below the last closed higher-timeframe close. Users can show or hide each multiple, set line length and thickness, and keep up to twelve historical sets. Colours distinguish up and down projections and the two timeframes. It snapshots closed bars rather than the live bar.

Details

Published by

Zen-Tim on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Support & resistance, Volatility & bands

Markets

Any symbol

Timeframes

Any timeframe

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.

Settings

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

SettingTypeDefaultVariable
Enable HTF 1booltrueh1_on
Timeframetimeframe15h1_tf
ABR Lookbackint8h1_lookback
Bars Back (0 = last only, 11 = twelve sets)int10h1_bars_back
Line Length (bars)int2h1_length
Line Thicknessint1h1_thickness
Show 0.5xbooltrueh1_show_05
Show 1xbooltrueh1_show_1
Show 2xboolfalseh1_show_2
0.5x upcolorcolor.new(#2196F3, 50)h1_c_05_up
0.5x downcolorcolor.new(#FF0000, 50)h1_c_05_dn
1x upcolorcolor.new(#2196F3, 0)h1_c_1_up
Show all 30 settings
SettingTypeDefaultVariable
1x downcolorcolor.new(#FF0000, 0)h1_c_1_dn
2x upcolorcolor.new(#2196F3, 0)h1_c_2_up
2x downcolorcolor.new(#FF0000, 0)h1_c_2_dn
Enable HTF 2booltrueh2_on
Timeframetimeframe60h2_tf
ABR Lookbackint8h2_lookback
Bars Back (0 = last only, 11 = twelve sets)int5h2_bars_back
Line Length (bars)int4h2_length
Line Thicknessint2h2_thickness
Show 0.5xbooltrueh2_show_05
Show 1xbooltrueh2_show_1
Show 2xboolfalseh2_show_2
0.5x upcolorcolor.new(#26A69A, 50)h2_c_05_up
0.5x downcolorcolor.new(#FF9800, 50)h2_c_05_dn
1x upcolorcolor.new(#26A69A, 0)h2_c_1_up
1x downcolorcolor.new(#FF9800, 0)h2_c_1_dn
2x upcolorcolor.new(#26A69A, 0)h2_c_2_up
2x downcolorcolor.new(#FF9800, 0)h2_c_2_dn
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