OPEN-SOURCE SCRIPT
Consolidation zones + Breakout

This Pine Script v6 indicator is designed to detect consolidation zones and mark breakout entries (long or short) when price exits those zones.
Indicator purpose
Identify periods where price moves in a tight range for several consecutive bars (consolidation).
Highlight those zones on the chart with a yellow shaded area between the local high and low.
Mark potential LONG and SHORT entries when price breaks out of a consolidation zone.
Core consolidation logic
The indicator measures whether the market is “compressed” by comparing the price range of recent bars with volatility measured via ATR:
It computes the highest high and lowest low of the last lookback bars:
rangeHigh = ta.highest(high, lookback)
rangeLow = ta.lowest(low, lookback)
It calculates the current range:
rng = rangeHigh - rangeLow
It calculates ATR over atrLen bars as a volatility benchmark:
atrVal = ta.atr(atrLen)
It defines a compressed range (base consolidation) when the range is smaller than a multiple of ATR:
baseConso = rng < atrVal * atrMult
Here, atrMult controls how tight the range must be. Lower values (0.8–1.0) require strong compression; higher values (1.5–2.0) are more permissive.
Minimum bars in consolidation
To avoid calling a very short pause a consolidation, the script enforces a minimum duration:
It uses ta.barssince(not baseConso) to count how many bars have passed since the last time the consolidation condition was false.
If that count is greater than or equal to minBars, the market is considered to be in consolidation:
text
isConsolidating = ta.barssince(not baseConso) >= minBars
This prevents 2–3 sideways bars from being treated as a full consolidation zone. The minBars input lets you adapt the duration to your timeframe and trading style.
Plotting the consolidation zone
When isConsolidating is true, the script shades the consolidation area:
It plots two invisible series for the zone’s high and low:
text
pHigh = plot(rangeHigh, display = display.none)
pLow = plot(rangeLow, display = display.none)
It creates a yellow semi‑transparent fill between those lines only while in consolidation:
text
fillColor = isConsolidating ? color.new(#ffeb3b, 80) : color.new(#ffeb3b, 100)
fill(pHigh, pLow, color = fillColor, title = "Consolidation Zone")
Outside consolidation, the color becomes almost fully transparent so the shaded zone disappears. This keeps the chart clean and focuses attention on the actual ranges.
Breakout detection (LONG / SHORT)
The script then looks for breakouts when price leaves a consolidation zone:
It checks if the previous bar was inside consolidation:
wasConso = isConsolidating[1]
A bullish breakout (LONG) occurs when:
The current bar is no longer in consolidation (not isConsolidating).
The previous bar was in consolidation (wasConso).
The close breaks above the previous consolidation high (close > rangeHigh[1]):
text
breakLong = not isConsolidating and wasConso and close > rangeHigh[1]
A bearish breakout (SHORT) occurs when:
The current bar is no longer in consolidation.
The previous bar was in consolidation.
The close breaks below the previous consolidation low (close < rangeLow[1]):
text
breakShort = not isConsolidating and wasConso and close < rangeLow[1]
On each breakout, a label is drawn at the breakout bar:
text
if breakLong
label.new(bar_index, low, "LONG",
style = label.style_label_up,
textcolor = color.white,
color = color.new(color.teal, 0),
size = size.tiny)
if breakShort
label.new(bar_index, high, "SHORT",
style = label.style_label_down,
textcolor = color.white,
color = color.new(color.red, 0),
size = size.tiny)
These labels highlight where price transitions from sideways action to a potential directional move.
User inputs and tuning
lookback (Bars for range)
Number of bars used to compute the consolidation high/low. Higher values produce wider, less frequent zones; lower values detect shorter consolidations.
minBars (Minimum bars in consolidation)
Minimum number of consecutive bars that must meet the compression condition. On 15‑minute charts, values between 6 and 12 often work, but this depends on the asset.
atrLen and atrMult
Control how strict the compression rule is.
atrLen: ATR period.
atrMult: maximum allowed range as a multiple of ATR.
Increasing atrMult finds more zones; decreasing it makes the filter stricter.
showText
Optional helper label with a short description, useful when sharing the script with other users on the TradingView community.
Practical usage
Apply the indicator to your preferred timeframe (for example, 15‑minute crypto charts).
Tweak lookback, minBars, and atrMult until the yellow zones match the consolidations you would mark manually.
Use the LONG and SHORT labels as areas of interest for studying range breakouts and building your own entry/exit rules, always combining them with risk management and a complete trading strategy.
This way, the script turns a visual concept—sideways consolidation followed by breakout—into a systematic, testable signal in Pine Script v6.
Indicator purpose
Identify periods where price moves in a tight range for several consecutive bars (consolidation).
Highlight those zones on the chart with a yellow shaded area between the local high and low.
Mark potential LONG and SHORT entries when price breaks out of a consolidation zone.
Core consolidation logic
The indicator measures whether the market is “compressed” by comparing the price range of recent bars with volatility measured via ATR:
It computes the highest high and lowest low of the last lookback bars:
rangeHigh = ta.highest(high, lookback)
rangeLow = ta.lowest(low, lookback)
It calculates the current range:
rng = rangeHigh - rangeLow
It calculates ATR over atrLen bars as a volatility benchmark:
atrVal = ta.atr(atrLen)
It defines a compressed range (base consolidation) when the range is smaller than a multiple of ATR:
baseConso = rng < atrVal * atrMult
Here, atrMult controls how tight the range must be. Lower values (0.8–1.0) require strong compression; higher values (1.5–2.0) are more permissive.
Minimum bars in consolidation
To avoid calling a very short pause a consolidation, the script enforces a minimum duration:
It uses ta.barssince(not baseConso) to count how many bars have passed since the last time the consolidation condition was false.
If that count is greater than or equal to minBars, the market is considered to be in consolidation:
text
isConsolidating = ta.barssince(not baseConso) >= minBars
This prevents 2–3 sideways bars from being treated as a full consolidation zone. The minBars input lets you adapt the duration to your timeframe and trading style.
Plotting the consolidation zone
When isConsolidating is true, the script shades the consolidation area:
It plots two invisible series for the zone’s high and low:
text
pHigh = plot(rangeHigh, display = display.none)
pLow = plot(rangeLow, display = display.none)
It creates a yellow semi‑transparent fill between those lines only while in consolidation:
text
fillColor = isConsolidating ? color.new(#ffeb3b, 80) : color.new(#ffeb3b, 100)
fill(pHigh, pLow, color = fillColor, title = "Consolidation Zone")
Outside consolidation, the color becomes almost fully transparent so the shaded zone disappears. This keeps the chart clean and focuses attention on the actual ranges.
Breakout detection (LONG / SHORT)
The script then looks for breakouts when price leaves a consolidation zone:
It checks if the previous bar was inside consolidation:
wasConso = isConsolidating[1]
A bullish breakout (LONG) occurs when:
The current bar is no longer in consolidation (not isConsolidating).
The previous bar was in consolidation (wasConso).
The close breaks above the previous consolidation high (close > rangeHigh[1]):
text
breakLong = not isConsolidating and wasConso and close > rangeHigh[1]
A bearish breakout (SHORT) occurs when:
The current bar is no longer in consolidation.
The previous bar was in consolidation.
The close breaks below the previous consolidation low (close < rangeLow[1]):
text
breakShort = not isConsolidating and wasConso and close < rangeLow[1]
On each breakout, a label is drawn at the breakout bar:
text
if breakLong
label.new(bar_index, low, "LONG",
style = label.style_label_up,
textcolor = color.white,
color = color.new(color.teal, 0),
size = size.tiny)
if breakShort
label.new(bar_index, high, "SHORT",
style = label.style_label_down,
textcolor = color.white,
color = color.new(color.red, 0),
size = size.tiny)
These labels highlight where price transitions from sideways action to a potential directional move.
User inputs and tuning
lookback (Bars for range)
Number of bars used to compute the consolidation high/low. Higher values produce wider, less frequent zones; lower values detect shorter consolidations.
minBars (Minimum bars in consolidation)
Minimum number of consecutive bars that must meet the compression condition. On 15‑minute charts, values between 6 and 12 often work, but this depends on the asset.
atrLen and atrMult
Control how strict the compression rule is.
atrLen: ATR period.
atrMult: maximum allowed range as a multiple of ATR.
Increasing atrMult finds more zones; decreasing it makes the filter stricter.
showText
Optional helper label with a short description, useful when sharing the script with other users on the TradingView community.
Practical usage
Apply the indicator to your preferred timeframe (for example, 15‑minute crypto charts).
Tweak lookback, minBars, and atrMult until the yellow zones match the consolidations you would mark manually.
Use the LONG and SHORT labels as areas of interest for studying range breakouts and building your own entry/exit rules, always combining them with risk management and a complete trading strategy.
This way, the script turns a visual concept—sideways consolidation followed by breakout—into a systematic, testable signal in Pine Script v6.
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.