Indicator · Pine Script v4 · On the chart

Consolidation Zones - Live

by theonetrade· code credited to LonesomeTheBlue

The Consolidation Zones - Live indicator identifies price consolidation areas and plots high and low boundary levels directly on the price chart.

View on GitHub

GitHub stars34on the repository
Pine versionv4older, still runs
Lines of code79
Settings4inputs
LicenceMIT
Last update2 weeks ago8 Nov 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

79 lines of Pine Script v4 from assets/indicator/bit-exact/consolidation_zones_live_xKSqR6P4.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

consolidation_zones_live_xKSqR6P4.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © LonesomeTheBlue

//@version=4
study("Consolidation Zones - Live", overlay = true, max_bars_back = 1100)
prd = input(defval = 10, title="Loopback Period", minval = 2, maxval = 50)
conslen = input(defval = 5, title="Min Consolidation Length", minval = 2, maxval = 20)
paintcons = input(defval = true, title = "Paint Consolidation Area ")
zonecol = input(defval = color.new(color.blue, 70), title = "Zone Color")

float hb_ = highestbars(prd) == 0 ? high : na
float lb_ = lowestbars(prd) == 0 ? low : na
var int dir = 0
float zz = na
float pp = na

dir := iff(hb_ and na(lb_), 1, iff(lb_ and na(hb_), -1, dir))
if hb_ and lb_
    if dir == 1
        zz := hb_
    else
        zz := lb_
else
    zz := iff(hb_, hb_, iff(lb_, lb_, na))

for x = 0 to 1000
    if na(close) or dir != dir[x]
        break
    if zz[x]
        if na(pp)
            pp := zz[x]
        else
            if dir[x] == 1 and zz[x] > pp
                pp := zz[x]
            if dir[x] == -1 and zz[x] < pp
                pp := zz[x]

var int conscnt = 0
var float condhigh = na
var float condlow = na
float H_ = highest(conslen)
float L_ = lowest(conslen)
var line upline = na
var line dnline = na
bool breakoutup = false
bool breakoutdown = false

if change(pp)
    if conscnt > conslen
        if pp > condhigh
            breakoutup := true
        if pp < condlow
            breakoutdown := true
    if conscnt > 0 and pp <= condhigh and pp >= condlow
        conscnt := conscnt + 1
    else
        conscnt := 0
else
    conscnt := conscnt + 1

if conscnt >= conslen
    if conscnt == conslen
        condhigh := H_
        condlow  := L_
    else
        line.delete(upline)
        line.delete(dnline)
        condhigh := max(condhigh, high)
        condlow := min(condlow, low)
    
    upline := line.new(bar_index, condhigh, bar_index - conscnt, condhigh, color = color.red, style = line.style_dashed)
    dnline := line.new(bar_index, condlow , bar_index - conscnt, condlow, color = color.lime, style = line.style_dashed)

fill(plot(condhigh, color = na, style = plot.style_stepline),
   plot(condlow, color = na, style = plot.style_stepline),
   color = paintcons and conscnt > conslen ? zonecol : color.new(color.white, 100))

alertcondition(breakoutup, title='Breakout Up', message='Breakout Up')
alertcondition(breakoutdown, title='Breakout Down', message='Breakout Down')

Overview

Consolidation Zones - Live tracks pivot highs and lows over a configurable loopback period to monitor whether price remains bound within a range for a set minimum consolidation length. When a consolidation zone forms, the script draws dashed upper and lower boundary lines along with optional background shading. It also triggers built-in alerts on bullish or bearish breakouts.

Details

Published by

theonetrade on GitHub

Code credit

LonesomeTheBlue, as written in the script's header

Type

Indicator, Pine Script v4

Draws

On the price chart

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.

Topics

algorithmic-tradingbacktestingbitcoinccxtcrypto-tradingllm-agentoffline-backtestingopen-source-tradingpine-scriptpine-to-pythonpinescriptpynecorepythonquantquantitative-financestrategy-backtestingtechnical-analysistrading-indicatorstrading-strategiestradingview

Settings

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

SettingTypeDefaultVariable
Loopback Periodint10prd
Min Consolidation Lengthint5conslen
Paint Consolidation Area booltruepaintcons
Zone Colorcolorcolor.new(color.blue, 70)zonecol
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

Sideway Zones Live

by dearvn
257 stars

Sideway Zones Live is an overlay indicator that estimates inner and outer sideways bands from recent highs and lows with a rational quadratic kernel. It tracks swing pivots over a loopback period and counts bars that remain between the outer high and low. Afte

Indicator v5 TrendSupport & resistance
Updated 2 months ago · None stated GitHub repository of Sideway Zones Live
228 stars

This indicator plots dynamic support and resistance levels on the price chart. It detects pivot highs and lows using the pivot length and tracks touches to build strength-based levels. Support and resistance zones appear as colored boxes while lines mark key l

Indicator v6 Support & resistanceBreakout
Updated 4 months ago · None stated GitHub repository of Dynamic Support & Resistance
220 stars

This indicator identifies High Of Low Price (HOLP) and Low Of High Price (LOHP) candlestick setups based on price extremes over a specified lookback period. A HOLP signal triggers when the current bar closes above the high of a recent session low, whereas a LO

Indicator v5 Candlestick patternsBreakout
Updated 1 year ago · None stated GitHub repository of Candlestick Patterns - HOLP-LOHP

Donchian Channels (DC)

by mihakralj
99 stars

This indicator calculates and plots Donchian Channels directly on the price chart. It determines the highest high and lowest low over a user-selected lookback period using an optimized monotonic deque algorithm, as well as a middle basis line computed as their

Indicator v6 Volatility & bandsSupport & resistance
Updated 8 weeks ago · Apache-2.0 GitHub repository of Donchian Channels (DC)

Lows from New Highs

by be-thomas
65 stars

This indicator tracks bar lows during consecutive rising highs using Pine Script arrays. When at least four lows accumulate or the price breaches the minimum low in the stack, the script sorts the recorded lows in ascending order and flushes them. It plots up

Indicator v4 Support & resistanceBreakout
Updated 4 weeks ago · GPL-3.0 GitHub repository of Lows from New Highs

This indicator tracks smart money market structure directly on the price chart. It calculates dual-period swing highs and swing lows to detect Changes of Character (CHoCH), Breaks of Structure (BOS), inducements, and liquidity sweeps. When structural levels ar

Indicator v5 SMC / ICT / price actionSupport & resistance
Updated 1 year ago · Apache-2.0 GitHub repository of Market Structure with Inducements & Sweeps [LuxAlgo]

More Support & resistance scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers