Indicator · Pine Script v5 · On the chart

Horizontal Line Bands

by g-moe· code credited to goodgains

This indicator plots horizontal line bands on the price chart using lower timeframe data.

View on GitHub

Repaints

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code143
Settings13inputs
LicenceNone statedfile: MPL-2.0
Last update5 months ago27 May 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

143 lines of Pine Script v5 from Tradingview/horizontal-line-bands.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

horizontal-line-bands.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © goodgains


//@version=5
indicator("Horizontal Line Bands", overlay = true, max_lines_count = 500)

// @keywords: horizontal-line-bands, minute-anchor, close-level-lines, tick-offset-bands, inner-band-pair, outer-band-pair, breach-recolor, dashed-lines, dotted-lines, extend-right-lines, lower-timeframe-feed, realtime-minute-close, line-arrays, keep-old-lines, switching-trigger, mintick-offset, bar-index-anchor, level-breach-detection, parallel-bands, debug-labels


line1_amount = input.int(2, minval = 1, title = 'Line One', group = 'Settings', inline ='1')
line1_color = input.color(color.new(color.yellow,0), title = '', group = 'Settings', inline ='1')
line1_style = input.string('Solid', title = '', options = ['Solid', 'Dotted', 'Dashed'], group = 'Settings', inline ='1')
line1_width = input.int(1, title = '', minval = 1, maxval = 5, group = 'Settings', inline ='1')

line2_amount = input.int(6, minval = 1, title = 'Line Two', group = 'Settings', inline ='2')
line2_color = input.color(color.new(color.green,0), title = '', group = 'Settings', inline ='2')
line2_style = input.string('Solid', title = '', options = ['Solid', 'Dotted', 'Dashed'], group = 'Settings', inline ='2')
line2_width = input.int(1, title = '', minval = 1, maxval = 5, group = 'Settings', inline ='2')

closeline_color = input.color(color.new(color.gray,0), title = 'Line Close', group = 'Settings', inline ='3')
closeline_style = input.string('Dashed', title = '', options = ['Solid', 'Dotted', 'Dashed'], group = 'Settings', inline ='3')
closeline_width = input.int(1, title = '', minval = 1, maxval = 5, group = 'Settings', inline ='3')

keep_old_lines = input.bool(true, title = 'Keep Old Lines', group = 'Settings', inline ='4')
color_to_switch = input.color(color.blue, title = 'Switching Color', group = 'Settings', inline ='5')


var float last_confirmed_bar_index = na
last_confirmed_bar_index := barstate.islastconfirmedhistory ? bar_index : last_confirmed_bar_index[1]
plotchar(bar_index == last_confirmed_bar_index ? true : false, title = 'Start Calculating', char = 'x', color = color.white)


var line_close = array.new_line(100,na)
var line1_upper = array.new_line(100,na)
var line1_lower = array.new_line(100,na)
var line2_upper = array.new_line(100,na)
var line2_lower = array.new_line(100,na)

varip float line1_upper_value = 0 
varip float line1_lower_value = 0
varip float line2_upper_value = 0 
varip float line2_lower_value = 0

varip float min_high = na
varip float min_low = na
varip float min_close = na
var bool min_confirm = na

// request minute data
min_highs =  request.security_lower_tf(syminfo.tickerid, '1', high)
min_lows =  request.security_lower_tf(syminfo.tickerid, '1', low)
min_closes =  request.security_lower_tf(syminfo.tickerid, '1', close)
min_confirms =  request.security_lower_tf(syminfo.tickerid, '1', barstate.isrealtime)

min_high := array.last(min_highs)
min_low := array.last(min_lows)
min_close := array.last(min_closes)
min_confirm := array.last(min_confirms)


// function to draw lines
f_drawlines(line_close, line1_upper, line1_lower, line2_upper, line2_lower, anchor) =>

    array.unshift(line_close, line.new(x1 = bar_index, y1 = anchor, x2 = bar_index+1, y2 = anchor, xloc = xloc.bar_index,
         extend = extend.right, color = closeline_color, width = closeline_width,
         style = (closeline_style == 'Solid' ? line.style_solid : closeline_style == 'Dashed' ? line.style_dashed : closeline_style == 'Dotted' ? line.style_dotted : line.style_solid)))

    array.unshift(line1_upper, line.new(x1 = bar_index, y1 = anchor + syminfo.mintick*line1_amount, x2 = bar_index+1, y2 = anchor + syminfo.mintick*line1_amount, xloc = xloc.bar_index,
         extend = extend.right, color = line1_color, width = line1_width,
         style = (line1_style == 'Solid' ? line.style_solid : line1_style == 'Dashed' ? line.style_dashed : line1_style == 'Dotted' ? line.style_dotted : line.style_solid)))

    array.unshift(line1_lower, line.new(x1 = bar_index, y1 = anchor - syminfo.mintick*line1_amount, x2 = bar_index+1, y2 = anchor - syminfo.mintick*line1_amount, xloc = xloc.bar_index,
         extend = extend.right, color = line1_color, width = line1_width,
         style = (line1_style == 'Solid' ? line.style_solid : line1_style == 'Dashed' ? line.style_dashed : line1_style == 'Dotted' ? line.style_dotted : line.style_solid)))

    array.unshift(line2_upper, line.new(x1 = bar_index, y1 = anchor + syminfo.mintick*line2_amount, x2 = bar_index+1, y2 = anchor + syminfo.mintick*line2_amount, xloc = xloc.bar_index,
         extend = extend.right, color = line2_color, width = line2_width,
         style = (line2_style == 'Solid' ? line.style_solid : line2_style == 'Dashed' ? line.style_dashed : line2_style == 'Dotted' ? line.style_dotted : line.style_solid)))

    array.unshift(line2_lower, line.new(x1 = bar_index, y1 = anchor - syminfo.mintick*line2_amount, x2 = bar_index+1, y2 = anchor - syminfo.mintick*line2_amount, xloc = xloc.bar_index,
         extend = extend.right, color = line2_color, width = line2_width,
         style = (line2_style == 'Solid' ? line.style_solid : line2_style == 'Dashed' ? line.style_dashed : line2_style == 'Dotted' ? line.style_dotted : line.style_solid)))


 // first bar_index line
if bar_index == last_confirmed_bar_index
    f_drawlines(line_close, line1_upper, line1_lower, line2_upper, line2_lower, array.last(min_closes)) 

// past confirmed bar_index
if bar_index > last_confirmed_bar_index

    // get line values
    line1_upper_value := line.get_y1(array.first(line1_upper))
    line1_lower_value := line.get_y1(array.first(line1_lower))

    line2_upper_value := line.get_y1(array.first(line2_upper))
    line2_lower_value := line.get_y1(array.first(line2_lower))

    // // extend x2 to current bar's bar_index
    line.set_x2(array.first(line_close), bar_index)
    line.set_x2(array.first(line1_upper), bar_index)
    line.set_x2(array.first(line1_lower), bar_index)
    line.set_x2(array.first(line2_upper), bar_index)
    line.set_x2(array.first(line2_lower), bar_index)

    // replace colors line 1
    if min_high >= line1_upper_value
        line.set_color(array.first(line1_upper), color_to_switch)
    if min_low <= line1_lower_value
        line.set_color(array.first(line1_lower), color_to_switch)

    // replace colors line 2 
    if min_high >= line2_upper_value or min_low <= line2_lower_value
        line.set_color(array.first(line_close), color_to_switch)
        line.set_color(array.first(line1_upper), color_to_switch)
        line.set_color(array.first(line1_lower), color_to_switch)
        line.set_color(array.first(line2_upper), color_to_switch)
        line.set_color(array.first(line2_lower), color_to_switch)

        // make new lines / delete old lines on the bars closing update
        if min_confirm
            if not keep_old_lines
                line.delete(array.first(line_close))
                line.delete(array.first(line1_upper))
                line.delete(array.first(line1_lower))
                line.delete(array.first(line2_upper))
                line.delete(array.first(line2_lower))

            // end extension since lines aren't being deleted
            line.set_extend(array.first(line_close), extend.none)
            line.set_extend(array.first(line1_upper), extend.none)
            line.set_extend(array.first(line1_lower), extend.none)
            line.set_extend(array.first(line2_upper), extend.none)
            line.set_extend(array.first(line2_lower), extend.none)
            
        // draw new lines
        f_drawlines(line_close, line1_upper, line1_lower, line2_upper, line2_lower, min_close)
        

// bgcolor(bar_index > last_confirmed_bar_index ? color.gray : na)
label.new(bar_index, 24150, str.tostring(min_confirm), color = color.white)
label.new(bar_index, min_close, text = str.tostring(min_close), color = color.white)

Overview

Horizontal Line Bands requests 1-minute high, low, and close values from security to calculate anchor points. Horizontal lines are drawn at specific levels with options for multiple lines in two groups, each customizable in color, style, and width. A closing line with dashed style is also drawn. The script stores lines in arrays and allows keeping old lines. It draws directly on the price chart. A notable limitation is that it repaints on the live bar.

Details

Published by

g-moe on GitHub

Code credit

goodgains, as written in the script's header

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Support & resistance

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)

Settings

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

SettingTypeDefaultVariable
Line Oneint2line1_amount
line1_colorcolorcolor.new(color.yellow,0)line1_color
line1_stylestringSolidline1_style
line1_widthint1line1_width
Line Twoint6line2_amount
line2_colorcolorcolor.new(color.green,0)line2_color
line2_stylestringSolidline2_style
line2_widthint1line2_width
Line Closecolorcolor.new(color.gray,0)closeline_color
closeline_stylestringDashedcloseline_style
closeline_widthint1closeline_width
Keep Old Linesbooltruekeep_old_lines
Show all 13 settings
SettingTypeDefaultVariable
Switching Colorcolorcolor.bluecolor_to_switch
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

948 stars

Moving Average Channel plots separate simple moving averages for upper and lower bands on the price chart. It fills the space between bands with semi-transparent color and colors bars green above the upper band, red below the lower band, or gray in between. Us

Indicator v4 Moving averagesSupport & resistance
Updated 10 days ago · GPL-3.0 GitHub repository of Moving Average Channel

ICT Equal Highs and Lows

by ArunKBhaskar
575 stars

This overlay indicator finds pivot highs and lows on the price chart and compares the last two highs and the last two lows. When the percentage difference between a pair is below the Equal HL threshold, it treats them as equal levels and draws a box. Left and

Indicator v5 SMC / ICT / price actionSupport & resistance
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Equal Highs and Lows
330 stars

This indicator monitors multiple cryptocurrency symbols for trading signals. It calculates and plots entry prices, take profit, and stop loss levels for each symbol including BTCUSDT, ETHUSDT, BNBUSDT and others. Price crossovers trigger buy, sell or close ale

Indicator v5 Support & resistanceScreeners & dashboards
Updated 2 months ago · None stated GitHub repository of Multi Alert Long/Short [Alorse]

This overlay indicator draws a fixed-range volume profile on the price chart, splitting traded activity into up and down volume at each price level. It also plots a sentiment profile, a developing point of control, and value-area high and low around a configur

Indicator v5 VolumeSupport & resistance
Updated 2 months ago · MIT GitHub repository of Volume Profile and Indicator by DGT

BZ-tracker

by Allen1212
303 stars

The BZ-tracker indicator marks ARK Invest buy and sell transactions on stock charts with labels. It plots green labels for purchases and red labels for sales, each annotated with a multiplier such as X1 or X2 to show the number of ARK ETFs trading the stock on

Indicator v4 Support & resistanceScreeners & dashboards
Updated 2 years ago · None stated GitHub repository of BZ-tracker

Function - Linear Regression

by ricardosantos79
261 stars

This indicator fits a linear regression through stored pivot highs and lows and draws the resulting channel on the price chart. A function returns predicted values, maximum and minimum deviations, and the average absolute deviation. Confirmed two-bar pivots up

Indicator v5 TrendSupport & resistance
Updated 4 years ago · None stated GitHub repository of Function - 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