Indicator · Pine Script v6 · On the chart

Consolidation Zones

by MarcosACH· code credited to ActiveQuants

Consolidation Zones draws boxes over periods when price stays inside a band around a simple moving average.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code57
Settings4inputs
LicenceNone statedfile: MPL-2.0
Last update1 year ago8 Jul 2025

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

57 lines of Pine Script v6 from consolidation_zones.pinescript, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

consolidation_zones.pinescript
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ActiveQuants
// Created by ActiveQuants
// Last updated: March 13, 2025

//@version=6
indicator(title = "Consolidation Zones [ActiveQuants]", overlay = true, max_boxes_count = 500)

//#region ------ USER INPUTS
int minZoneLength = input.int(defval = 20, title = "Minimum Zone Length", minval = 1, tooltip = "This value represents the SMA Length but it is also used to represent the minimum number of consecutive bars that have to fulfill the condition to be part of a consolidation zone.")
color zoneColor = input.color(defval = color.new(color.gray, 50), title = "Range Color")
int atrLength = input.int(defval = 200, title = "ATR Length", minval = 1)
int showLast = input.int(defval = 500, title = "Show Last", minval = 10, step = 10, tooltip = "Number of bars back the indicator can plot.")
//#endregion

//#region ----- VARIABLES
var box bx = na
var array<box> boxes = array.new_box()

var float max = na
var float min = na

float atr = ta.atr(atrLength)
float sma = ta.sma(close, minZoneLength)
//#endregion

//#region ----- PLOTTING
int count = 0
for i = 0 to minZoneLength - 1
    count += math.abs(close[i] - sma) > atr ? 1 : 0

if count == 0 and count[1] != count
    if bar_index[minZoneLength] <= bx.get_right()
        max := math.max(sma + atr, bx.get_top())
        min := math.min(sma - atr, bx.get_bottom())
        
        bx.set_top(max)
        bx.set_rightbottom(bar_index, min)
        bx.set_bgcolor(zoneColor)

    else
        max := sma + atr
        min := sma - atr

        bx := box.new(left = bar_index[minZoneLength], top = max, right = bar_index, bottom = min, border_color = na, bgcolor = zoneColor)
        boxes.push(bx)

else if count == 0
    bx.set_right(bar_index)

if array.size(boxes) > 0
    for i = array.size(boxes) - 1 to 0
        currentBox = array.get(boxes, i)
        if box.get_left(currentBox) < bar_index - showLast
            box.delete(currentBox)
            array.remove(boxes, i)
//#endregion

Overview

A zone forms when every close in the last minimum-zone-length bars sits within one ATR of the average. Overlapping zones are extended and merged, and zones older than the show-last limit are deleted. Settings are minimum zone length, ATR length, zone color and how many recent bars are shown. It draws on the price chart.

Details

Published by

MarcosACH on GitHub

Code credit

ActiveQuants, as written in the script's header

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Volatility & bands, Support & resistance, Breakout

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

pinescriptpinescript-indicatorstradingviewtechnical-analysistechnical-analysis-indicatorstradingvewpinescript-algorithmstrading-indicatorstrading-algorithms

Settings

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

SettingTypeDefaultVariable
Minimum Zone Lengthint20minZoneLength
Range Colorcolorcolor.new(color.gray, 50)zoneColor
ATR Lengthint200atrLength
Show Lastint500showLast
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

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 4 weeks ago · Apache-2.0 GitHub repository of Donchian Channels (DC)
47 stars

The Donchian Channels indicator plots the middle basis line as the average of the high and low over the user-defined period. It also draws the upper band as the highest high and the lower band as the lowest low across the same period on the price chart. The ma

Indicator v6 Volatility & bandsSupport & resistance
Updated 8 months ago · MIT GitHub repository of Donchian Channels (DCHANNEL)
43 stars

This indicator plots Donchian channel bands and a midline on the price chart. It finds the highest and lowest values over a user-set length, then draws the upper band, lower band, and their average as the basis. The source setting chooses high and low, or the

Indicator v4 Volatility & bandsBreakout
Updated 1 year ago · None stated GitHub repository of Donchian Channels Experiment

Zen ABR Against

by Zen-Tim
29 stars

This overlay indicator measures average bar range as a simple moving average of high minus low, then draws short horizontal ticks at one to four times that range above and below the close. The user chooses which multipliers appear, their colors, and the line w

Indicator v6 Volatility & bandsSupport & resistance
Updated 2 weeks ago · MIT GitHub repository of Zen ABR Against

This indicator identifies and plots price compression zones directly on the price chart using multi-module scoring. It measures ATR compression, ADX chop levels, boundary touches, volume dry-up, and historical pivot levels to identify consolidation areas and s

Indicator v6 BreakoutSupport & resistance
Updated 2 days ago · MIT GitHub repository of CoilForge Zones [WavesUnchained]

Dereköy-Darvas

by Kalumur
4 stars

The Dereköy-Darvas indicator combines Darvas Box boundary levels with dual Bollinger Bands plotted directly on the main price chart. It calculates top and bottom box lines based on recent high and low extremes to outline price consolidation zones. Simultaneous

Indicator v5 Volatility & bandsSupport & resistance
Updated 2 years ago · None stated GitHub repository of Dereköy-Darvas

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