Indicator · Pine Script v6 · On the chart

Consolidation Range with Signals (Zeiierman)

by theonetrade· code credited to Zeiierman {

Consolidation Range with Signals identifies sideways price action and non-trending periods directly on the main price chart.

View on GitHub

GitHub stars34on the repository
Pine versionv6current
Lines of code228
Settings26inputs
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

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

consolidation_range_with_signals_zeiierman_CrFfQD8L.pine
// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/

// © Zeiierman {
//@version=6
indicator('Consolidation Range with Signals (Zeiierman)', overlay=true, max_labels_count = 500, max_lines_count = 500)
//~~}

// ~~ Tooltips {
var string t1 = "Select the method used for detecting ranging market conditions.\n\n
 ADX: Uses the Average Directional Index to identify non-trending periods when ADX is below a set threshold.\n\n
 Volatility: Detects ranges by identifying periods of compression in volatility using standard deviation, variance, and ATR filters.\n\n
 Price Action: Confirms range by measuring the high-low percentage contraction and requiring a minimum number of DMI crosses, suggesting indecision or balance in price action."
var string t2 = "Length or period used for detecting the range."
var string t3 = "Multiplier applied to the calculated band distance."
var string t4 = "Toggle to display Take Profit and Stop Loss levels on the chart."
var string t5 = "Minimum number of bars between two consecutive SL/TP entries."
var string t6 = "Stop Loss multiplier from the filtered base value."
var string t7 = "Take Profit 1 multiplier from the filtered base value."
var string t8 = "Take Profit 2 multiplier from the filtered base value."
var string t9 = "Take Profit 3 multiplier from the filtered base value."
var string t10 = "ADX threshold under which the market is considered ranging."
var string t11 = "Smoothing period used for the ADX calculation."
var string t12 = "Standard deviation compression threshold used to detect low volatility."
var string t13 = "Variance compression threshold used to detect low volatility."
var string t14 = "ATR compression threshold used to detect low volatility."
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

// ~~ Inputs {
// ~~ Range {
method    = input.string("ADX", options=["ADX", "Volatility"], title="Range Detection Method", group="Range Detection", tooltip=t1)
len       = input.int(10, minval=2, title="Range Period", group="Range Detection", tooltip=t2)
band_mult = input.float(1.8, step=0.1, minval=0.01,title="Range Multiplier", group="Range Detection", tooltip=t3)
upper_col = input.color(#0060e6, title="Range", group="Range Detection", inline="bandcol")
lower_col = input.color(#29fafa, title="", group="Range Detection", inline="bandcol")
pos_col = input.color(#0060e6, title="Trend", group="Range Detection", inline="trendcol")
neg_col = input.color(#29fafa, title="", group="Range Detection", inline="trendcol")
//~~}
// ~~ SL/TP {
showTP    = input.bool(true, title="Show SL/TP Levels", group="Targets", tooltip=t4)
cooldown  = input.int(20, title="SL/TP Cooldown (Bars)", group="Targets", tooltip=t5)
sl_mult   = input.float(0.4, step=0.1, minval=0.01,title="SL", group="Targets", inline="sl", tooltip=t6)
showsl    = input.bool(true, title="", group="Targets", inline="sl", tooltip=t6)
tp1_mult  = input.float(0.5, step=0.1, minval=0.01,title="TP1", group="Targets", inline="tp1", tooltip=t7)
showtp1   = input.bool(true, title="", group="Targets", inline="tp1", tooltip=t7)
tp2_mult  = input.float(1.0, step=0.1, minval=0.01,title="TP2", group="Targets", inline="tp2", tooltip=t8)
showtp2   = input.bool(false, title="", group="Targets", inline="tp2", tooltip=t8)
tp3_mult  = input.float(2.0, step=0.1, minval=0.01,title="TP3", group="Targets", inline="tp3", tooltip=t9)
showtp3   = input.bool(false, title="", group="Targets", inline="tp3", tooltip=t9)

entry_col = input.color(color.blue, title="Entry", group="Targets", inline="tpcol")
sl_col    = input.color(#ff0000, title="SL", group="Targets", inline="tpcol")
bullColor = input.color(#09c10f, title="TP", group="Targets", inline="tpcol")
bearColor = input.color(#ff69cb, title="", group="Targets", inline="tpcol")
//~~}
// ~~ ADX {
adx_thresh = input.int(17, step=1, minval=0,title="ADX Threshold", group="ADX", tooltip=t10)
adx_smooth = input.int(10, step=1, minval=0,title="ADX Smoothing", group="ADX", tooltip=t11)
//~~}
// ~~ Volatility {
vol_mult_std = input.float(0.8, step=0.1, minval=0.001, title="StdDev Multiplier", group="Volatility", tooltip=t12)
vol_mult_var = input.float(0.8, step=0.1, minval=0.001,title="Variance Multiplier", group="Volatility", tooltip=t13)
vol_mult_atr = input.float(0.9, step=0.1, minval=0.001,title="ATR Multiplier", group="Volatility", tooltip=t14)
//~~}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

// ~~ ADX {
[_, _, adx] = ta.dmi(len, adx_smooth)
isADX       = adx < adx_thresh
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

// ~~ Volatility Compression {
logret  = math.log(close / close[1])
std_now = ta.stdev(logret, len)
std_avg = ta.sma(std_now, len)
atr_now = ta.atr(len)
atr_avg = ta.sma(atr_now, len)
var_now = ta.variance(logret, len)
var_avg = ta.sma(var_now, len)
isVolatility = std_now < std_avg * vol_mult_std and var_now < var_avg * vol_mult_var and atr_now < atr_avg * vol_mult_atr
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

// ~~ Switch {
methodDetected = (method == "ADX" and isADX) or
                 (method == "Volatility" and isVolatility)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

// ~~ Var {
var float rngfilt       = close
var color trendColor    = na
var bool rangeVisible   = false
var float prev_hi       = na
var float prev_lo       = na
var int rangeStartBar   = na
var int rangeBarsActive = 0
var int lastBreakoutBar = na

if methodDetected and na(rangeStartBar)
    rangeStartBar := bar_index
else if not methodDetected
    rangeStartBar := na

if methodDetected
    rangeVisible := true
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

// ~~ Range Calculation {
diff = math.abs(high - low[1])
r    = ta.sma(2.618 * diff, 2000) * band_mult
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

// ~~ Range Calculation Functions {
pricejump(prev) =>
    highJump = prev + math.abs(close - prev) / r * r
    lowJump  = prev - math.abs(close - prev) / r * r
    [highJump, lowJump]

rangefilter(hhjump, lljump, prev) =>
    hhBreak    = close > prev
    hhTooClose = close - r < prev
    hhShift    = close - r
    llTooClose = close + r > prev
    llShift    = close + r
    step1      = hhBreak ? (hhTooClose ? prev : hhShift) : (llTooClose ? prev : llShift)
    hhAbove = close >= prev + r
    llBelow = close <= prev - r
    hhAbove ? hhjump : llBelow ? lljump : step1

bands(filt) => [filt + r, filt - r]
trenddir(filt) => [filt > nz(filt[1]), filt < nz(filt[1])]
trendcomp(filt) => [filt, ta.sma(filt, 2), ta.sma(filt, 4)]

prev = nz(rngfilt[1])
[hhJ, llJ] = pricejump(prev)
rngfilt    := rangefilter(hhJ, llJ, prev)
prev_rngfilt      = nz(rngfilt[1])
rngfilt_step_up   = rngfilt > prev_rngfilt
rngfilt_step_down = rngfilt < prev_rngfilt

[hiband, loband] = bands(rngfilt)
[up, down]       = trenddir(rngfilt)
[TrendFast, TrendMed, TrendLong] = trendcomp(rngfilt)

if methodDetected
    prev_hi := hiband
    prev_lo := loband

if not methodDetected and (close[1] > prev_hi or close[1] < prev_lo)
    rangeVisible := false

MIDX1 = (hiband - rngfilt) / 3
MID1  = rngfilt + MIDX1
MID2  = MID1 + MIDX1
MIDX2 = (rngfilt - loband) / 3
MID3  = rngfilt - MIDX2
MID4  = MID3 - MIDX2
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

// ~~ Plot {
trendColor := up ? pos_col : down ? neg_col : trendColor[1]
plotTrend = plot(rangeVisible ? TrendFast : close, "Trend", rangeVisible ? trendColor:color.new(trendColor,100), 1)

plotMid1 = plot(rangeVisible ? MID1 : close, "MID1", rangeVisible ?color.new(upper_col, 50):color.new(upper_col, 100), style= plot.style_stepline)   
plotMid2 = plot(rangeVisible ? MID2 : close, "MID2", rangeVisible ?color.new(upper_col, 50):color.new(upper_col, 100), style= plot.style_stepline)   
plotMid3 = plot(rangeVisible ? MID3 : close, "MID3", rangeVisible ?color.new(lower_col, 50):color.new(lower_col, 100), style= plot.style_stepline)   
plotMid4 = plot(rangeVisible ? MID4 : close, "MID4", rangeVisible ?color.new(lower_col, 50):color.new(lower_col, 100), style= plot.style_stepline)   

fill(plotMid2, plotTrend, MID2, TrendFast, color.new(upper_col, 60),na)
fill(plotMid4, plotTrend, MID4, TrendFast, color.new(lower_col, 60),na)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

// ~~ TP and SL {
rangeBarsActive    := na(rangeStartBar) ? 0 : bar_index - rangeStartBar
canTriggerBreakout =  (na(lastBreakoutBar) or bar_index - lastBreakoutBar >= cooldown)
enterLong  = rangeVisible and rngfilt_step_up and canTriggerBreakout
enterShort = rangeVisible and rngfilt_step_down and canTriggerBreakout

calcSLTP(isLong) =>
    base = rngfilt
    offset = r * sl_mult
    tp1off = r * tp1_mult
    tp2off = r * tp2_mult
    tp3off = r * tp3_mult

    stop_ = isLong ? base - offset : base + offset
    tp1_ = isLong ? base + tp1off : base - tp1off
    tp2_ = isLong ? base + tp2off : base - tp2off
    tp3_ = isLong ? base + tp3off : base - tp3off
    [stop_, tp1_, tp2_, tp3_]

drawLevels(entry, sl, tp1, tp2, tp3, col) =>
    if showTP
        line.new(bar_index, entry, bar_index + 20, entry, color=entry_col, width=2)
        if showsl
            line.new(bar_index, sl, bar_index + 20, sl, color=color.new(sl_col, 0), width=2)
        if showtp1
            line.new(bar_index, tp1, bar_index + 20, tp1, color=color.new(col, 0), width=2)
        if showtp2
            line.new(bar_index, tp2, bar_index + 20, tp2, color=color.new(col, 0), width=2)
        if showtp3
            line.new(bar_index, tp3, bar_index + 20, tp3, color=color.new(col, 0), width=2)
    if showTP
        label.new(bar_index+ 20, entry, "Entry", style=label.style_label_left, color=entry_col, textcolor=color.white, size = size.tiny)
        if showsl
            label.new(bar_index+ 20, sl,    "SL", style=label.style_label_left, color=color.new(sl_col, 0), textcolor=color.white, size = size.tiny)
        if showtp1
            label.new(bar_index+ 20, tp1,   "TP 1", style=label.style_label_left, color=color.new(col, 0), textcolor=color.white, size = size.tiny)
        if showtp2    
            label.new(bar_index+ 20, tp2,   "TP 2", style=label.style_label_left, color=color.new(col, 0), textcolor=color.white, size = size.tiny)
        if showtp3
            label.new(bar_index+ 20, tp3,   "TP 3", style=label.style_label_left, color=color.new(col, 0), textcolor=color.white, size = size.tiny)

var float SL  = na
var float TP1 = na
var float TP2 = na
var float TP3 = na

if enterLong and showTP and (na(lastBreakoutBar) or bar_index - lastBreakoutBar >= cooldown)
    [s, t1_, t2_, t3_] = calcSLTP(true)
    SL := s, TP1 := t1_, TP2 := t2_, TP3 := t3_
    drawLevels(close, SL, TP1, TP2, TP3, bullColor)
    lastBreakoutBar := bar_index

if enterShort and showTP and (na(lastBreakoutBar) or bar_index - lastBreakoutBar >= cooldown)
    [s, t1_, t2_, t3_] = calcSLTP(false)
    SL := s, TP1 := t1_, TP2 := t2_, TP3 := t3_
    drawLevels(close, SL, TP1, TP2, TP3, bearColor)
    lastBreakoutBar := bar_index
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

Overview

Consolidation Range with Signals (Zeiierman) detects range bound conditions using either ADX thresholds or multi-factor volatility compression filters based on Standard Deviation, Variance, and ATR. The indicator draws dynamic range bands and projects optional Stop Loss and multiple Take Profit target levels with customizable multipliers and a bar cooldown filter between setups. Users can adjust detection periods, compression parameters, and signal display toggles.

Details

Published by

theonetrade on GitHub

Code credit

Zeiierman {, as written in the script's header

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
Range Detection MethodstringADXmethod
Range Periodint10len
Range Multiplierfloat1.8band_mult
Rangecolor#0060e6upper_col
lower_colcolor#29fafalower_col
Trendcolor#0060e6pos_col
neg_colcolor#29fafaneg_col
Show SL/TP LevelsbooltrueshowTP
SL/TP Cooldown (Bars)int20cooldown
SLfloat0.4sl_mult
showslbooltrueshowsl
TP1float0.5tp1_mult
Show all 26 settings
SettingTypeDefaultVariable
showtp1booltrueshowtp1
TP2float1.0tp2_mult
showtp2boolfalseshowtp2
TP3float2.0tp3_mult
showtp3boolfalseshowtp3
Entrycolorcolor.blueentry_col
SLcolor#ff0000sl_col
TPcolor#09c10fbullColor
bearColorcolor#ff69cbbearColor
ADX Thresholdint17adx_thresh
ADX Smoothingint10adx_smooth
StdDev Multiplierfloat0.8vol_mult_std
Variance Multiplierfloat0.8vol_mult_var
ATR Multiplierfloat0.9vol_mult_atr
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

[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 5 years ago · None stated GitHub repository of [RS]Donchian Fans

Dynamic Linear Regression

by TradersPost
228 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 4 months ago · None stated GitHub repository of Dynamic Linear Regression

ATR Trailing Stop

by mihakralj
99 stars

Calculates an ATR-based trailing stop overlaid on the price chart to assist with trend identification and stop placement. Using a specified ATR period and multiplier, it projects upper and lower bounds around the closing price. The stop line ratchets up during

Indicator v5 TrendVolatility & bands
Updated 8 weeks ago · Apache-2.0 GitHub repository of ATR Trailing Stop

Moon Dev Lunar Sniper

by moondevonyt
98 stars

Moon Dev Lunar Sniper is a multi-indicator overlay that scores confluence across fast and slow EMAs, RSI, MACD, DMI, and BB width to fire signals only when score meets the minimum threshold. It plots buy and sell signals on the price chart, highlights cosmic b

Indicator v6 TrendOscillators & momentum Repaints
Updated 2 months ago · Custom licence GitHub repository of Moon Dev Lunar Sniper

SuperTrend & Pivots

by dcaoyuan
55 stars

This overlay indicator plots a SuperTrend line on the price chart using a fixed ATR length of 10 and a factor of 3. When the trend direction is up it draws a green line and a light green fill toward the candle midpoint; when down it draws a red line and a ligh

Indicator v6 TrendVolatility & bands
Updated 7 months ago · Apache-2.0 GitHub repository of SuperTrend & Pivots

More Trend 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