Auto Range / Lateral Consolidation Box DetectorAuto Range / Lateral Consolidation Box Detector
Overview
The Auto Range / Lateral Consolidation Box Detector is designed to automatically identify and draw price ranges where a stock is moving sideways after a prior advance.
Instead of manually drawing rectangle boxes around consolidation areas, this indicator detects them objectively using price containment, range width, prior trend movement, ADR, moving-average structure, and optional volume/RSI filters.
The purpose is to help traders identify:
lateral consolidations
tight launch shelves
continuation bases
range breakouts
failed ranges
breakout/retest zones
early momentum continuation structures
This tool is especially useful for traders who look for stocks that have already shown strength, pause in a controlled range, and then attempt to continue higher.
Core Concept
Many strong momentum moves do not happen randomly. They often follow a repeatable structure:
Prior advance → sideways range → breakout → continuation
This indicator attempts to locate that sideways range automatically.
The blue dashed boxes show detected consolidation zones. When price breaks above a completed range, the indicator can mark the breakout and preserve the prior box so the trader can review the structure historically.
The goal is not to predict breakouts blindly. The goal is to make range structure easier to detect, measure, and trade with defined risk.
What the Indicator Detects
The indicator identifies two main types of structures:
1. Standard Rectangle Range
This is a broader lateral consolidation that usually forms over a larger number of candles.
It is useful for detecting:
multi-week consolidations
continuation bases
sideways digestion after an advance
breakout/retest setups
controlled pullbacks above moving averages
A standard rectangle is best used when price has already advanced and then begins moving sideways in a defined box.
2. Tight Launch Shelf
This is a shorter, tighter range that often forms just before a momentum expansion.
It is useful for detecting:
short pauses near highs
high-tight continuation shelves
pre-breakout compression
momentum names that do not build long bases
stocks that pause briefly before expanding again
This feature was added because some of the strongest stocks do not consolidate for weeks. They may only pause for several sessions before breaking out.
How the Boxes Work
The indicator measures the range using completed prior candles only.
This is important because the breakout candle itself should not distort the range.
For example, if a stock breaks out above a tight rectangle, the breakout candle may be much larger than the range. If the script included that candle in the box calculation, it would make the range look wider than it actually was.
This script avoids that issue by asking:
“Before the current breakout candle, was there a valid sideways range?”
That allows the indicator to draw the actual consolidation area more accurately.
Visual Guide
Visual ElementMeaningBlue dashed boxDetected standard rectangle rangePurple dashed boxDetected tight launch shelfUpper box lineRange resistance / breakout levelLower box lineRange support / invalidation referenceMidlineInternal range midpointBO markerBreakout above range with volumeBO? markerPrice breakout without volume confirmationFAIL markerBreakdown below rangeScore labelShows range quality, width, ADR, prior move, and containment
How I Use It in My Strategy
This indicator fits into a continuation-style trading strategy built around strength, structure, and timing.
The process is:
1. Find a stock with prior strength
I want to see that the stock has already proven demand.
That may include:
strong prior advance
relative strength versus the market
rising moving averages
reclaim or hold above the 200 SMA
improving volume profile
strong sector or theme participation
recent earnings, catalyst, or institutional attention
The indicator is not used to find random sideways stocks. It is used to find sideways ranges after strength has already appeared.
2. Let the stock build a range
Once a stock has moved, I want to see whether it can hold gains.
A clean range tells me:
buyers are defending higher prices
sellers are not fully taking control
price is digesting instead of collapsing
moving averages may be catching up
risk can be defined around the box
This is where the auto box becomes useful.
Instead of manually drawing every range, the indicator highlights areas where price is compressing or consolidating.
3. Use the box for trade planning
The box gives me three major trade locations:
Trade LocationUse CaseRange lowSupport-defense entryRange highBreakout triggerBreakout retestPreferred continuation entry
I generally do not want to enter randomly in the middle of the box unless I have another strong reason.
The best trades usually come from:
range-low defense,
breakout through range high,
or breakout followed by a retest that holds.
4. Confirm with other tools
This indicator identifies structure, but it is not a standalone buy signal.
Before taking a trade, I still want confirmation from:
relative strength
catalyst/news/earnings context
sector/theme strength
ADR/movement potential
volume expansion
VWAP/AVWAP location
volume profile levels
option-chain liquidity if using options
broader market regime
The box tells me where the trade may be forming.
The rest of the process tells me whether it deserves capital.
How Other Traders Can Use It
This indicator can be adapted to several trading styles.
Momentum Traders
Momentum traders can use it to identify stocks that are pausing after a strong move and preparing for another push.
Best use:
breakout above range high
breakout with volume
tight launch shelf breakouts
high-relative-volume names
strong sector/theme participation
Swing Traders
Swing traders can use it to locate multi-day or multi-week continuation bases.
Best use:
buy breakout/retest
enter near range support with defined risk
use the box low as invalidation
use the box height for measured-move targets
combine with daily/weekly trend structure
Breakout Traders
Breakout traders can use the box high as an objective breakout level.
Best use:
price closes above the range high
volume expands above average
range is not too wide
stock is above key moving averages
market regime supports continuation
Mean-Reversion Traders
Mean-reversion traders can use the range boundaries in the opposite way.
Best use:
fade weak breakouts back into the range
buy range low if buyers defend
sell/avoid failed range highs
use the midpoint as a decision level
Position Traders
Position traders can use detected boxes as add zones during a larger trend.
Best use:
add after a valid base forms above rising moving averages
trail risk below higher base lows
identify where trend continuation is being accepted
avoid adding after emotional vertical moves without digestion
Input Settings Explained
Standard Rectangle Bars
Controls how many prior candles are used to detect a normal consolidation box.
Higher values detect longer bases.
Lower values detect shorter ranges.
Suggested use:
StyleSettingFast momentum8–12Swing trading12–20Longer bases20–40
Tight Launch Shelf Bars
Controls how many prior candles are used to detect short, tight shelves near highs.
This is designed for stocks that pause briefly before breaking out.
Suggested use:
StyleSettingVery fast momentum4–6Normal launch shelf6–10Slower swing shelf10–15
Prior Move Lookback Bars
Determines how far back the script looks to measure whether the stock had a prior advance before the range.
Higher values allow the script to detect bases after larger, older moves.
Suggested use:
StyleSettingShort-term momentum20–35Swing continuation35–60Longer trend bases60–100
Minimum Prior Advance %
Defines how much price must have advanced before the range qualifies.
This helps prevent the script from highlighting random sideways chop.
Suggested use:
Market TypeSettingLarge caps8%–15%Mid caps15%–25%Small caps / high ADR20%–40%
A higher setting makes the script more selective.
Minimum Close Containment %
Controls how many closes must remain inside the box.
A higher value requires cleaner sideways behavior.
Suggested use:
Range QualitySettingLoose ranges60%–70%Normal ranges70%–80%Very tight clean bases80%–90%
Max Standard Range Width x ADR
Controls how wide a normal range can be compared with the stock’s average daily range.
Lower values require tighter bases.
Higher values allow wider, looser consolidations.
Suggested use:
PreferenceSettingTight clean bases only1.5–2.25Balanced2.5–3.0Loose momentum names3.0–4.0
Max Tight Shelf Width x ADR
Controls how wide a tight launch shelf can be.
Because launch shelves should be tighter than standard ranges, this number is usually lower.
Suggested use:
PreferenceSettingVery tight shelves1.0–1.3Balanced1.4–1.8Volatile small caps1.8–2.5
ADR Length
Controls the lookback period for average daily range.
Default is 20, which approximates one trading month.
Suggested use:
PurposeSettingShort-term sensitivity10Standard20Smoother ADR30–50
Volume Average Length
Controls the average volume lookback used for breakout and volume comparison.
Suggested use:
StyleSettingFast momentum10Standard swing20Smoother volume filter30–50
Max Range Volume vs Avg
This controls how much volume is allowed during the range if the volume filter is enabled.
Lower values require quieter consolidation.
Higher values allow more active ranges.
Suggested use:
Range TypeSettingQuiet base0.8–1.0Normal base1.0–1.25Active momentum range1.25–1.75
RSI Settings
RSI filters can be used to avoid ranges that are either too weak or too extended.
Suggested use:
PurposeSettingAvoid weak rangesMinimum RSI 40Allow momentum leadersMaximum RSI 80–85Stricter resetMax RSI 70–75
For strong momentum stocks, I prefer leaving RSI control flexible because strong names can remain elevated before breaking out.
Require Price Above 200 SMA
When enabled, the script only accepts ranges where price is above the 200 SMA.
This is useful for trend-following and continuation strategies.
Turn this off if you want to scan:
bottoming structures
early reversals
200 SMA reclaim attempts
accumulation ranges below the 200 SMA
Require Prior Advance
When enabled, the script requires price to have moved up before forming the range.
This is best for continuation traders.
Turn this off if you want to study:
accumulation bases
bottoming ranges
reversal setups
sideways structures before a first move
Require Volume Control
When enabled, the range must have controlled volume relative to average volume.
This helps filter out chaotic ranges.
However, for volatile small caps or active momentum names, I often leave this off because strong stocks can consolidate with active volume.
Require RSI Control
When enabled, RSI must remain within the selected range.
This can help avoid weak or overextended setups.
However, momentum leaders can remain strong for longer than expected, so this setting is optional depending on the strategy.
Setup Score
The label displays an Auto Range Score out of 10.
The score considers:
prior move
price above 200 SMA
containment inside the range
range width versus ADR
volume behavior
OBV behavior
RSI condition
ADR level
The score is not a buy signal. It is a structure-quality score.
General interpretation:
ScoreInterpretation9–10Very clean structure7–8Good watchlist candidate5–6Needs more confirmationBelow 5Low-quality or incomplete structure
Trading Notes
A detected box is only a location tool.
It does not replace:
market regime analysis
risk management
catalyst research
relative strength checks
liquidity checks
options-chain review
trade planning
The highest-quality setups usually combine:
strong prior move + clean box + range containment + volume expansion on breakout + supportive market conditions.
Risk Management
The box can help define risk.
Common invalidation methods:
stop below range low
stop below breakout candle low
stop below retest low
stop below rising 20 EMA or 50 SMA
exit if breakout fails back into range
avoid if price breaks below the box with volume
The cleanest setups are usually those where the box gives a tight, logical invalidation level.
Important Disclaimer
This indicator is for educational and research purposes only.
It does not provide financial advice, investment advice, or guaranteed trade signals. All trading involves risk. Traders should use their own research, risk management, and judgment before entering any position.
Pine Script® indicator











