OPEN-SOURCE SCRIPT
Range Detector

range detector is built to identify real consolidation zones directly on the chart.
instead of marking every small pause as a range, the tool waits for price to remain contained between two boundaries for a minimum number of bars. the range must stay compact compared to volatility, avoid strong directional expansion, and remain valid until a confirmed breakout or structural widening occurs.
the goal is simple: help traders separate true sideways compression from normal market noise.
what the indicator detects
range detector searches for market areas where price is moving inside a controlled box instead of trending aggressively. a valid range is built from three main conditions:
price must stay contained between a top and bottom boundary
the height of the box must remain reasonable compared to atr
the structure must last long enough to confirm consolidation
once a range is active, the indicator displays:
top of the range
bottom of the range
midline equilibrium
range size classification
breakout markers
dashboard status
range size classification
each range is classified by height using atr units.
small range
medium range
large range
this helps understand whether the market is compressing tightly or building a wider consolidation structure. a tight range can be useful for breakout preparation, while a wider range can be useful for mean reversion, liquidity sweeps, and boundary reactions.
multi-timeframe detection
one of the most important features is the detection timeframe input.
by default, the detection timeframe is empty. this means the indicator uses the current chart timeframe.
for stronger structure, you can select a higher timeframe.
examples:
on a 5 minute chart, set detection timeframe to 1h to see larger intraday ranges
on a 15 minute chart, set detection timeframe to 4h to track stronger session structures
on a 1h chart, set detection timeframe to 1d to follow major daily compression zones
this is useful because a range detected on a higher timeframe is generally more important than a small range detected only on the chart timeframe.
when using mtf, the range engine runs directly on the selected detection timeframe. this means the boxes are not simply visual approximations from the lower timeframe. the range logic is calculated from the chosen timeframe structure.
how to use mtf correctly
for scalping, use a chart timeframe such as 1m, 3m, or 5m, then set the detection timeframe to 15m, 30m, or 1h.
for intraday trading, use a chart timeframe such as 5m, 15m, or 30m, then set the detection timeframe to 1h or 4h.
for swing trading, use a chart timeframe such as 1h or 4h, then set the detection timeframe to daily or weekly.
the higher the detection timeframe, the fewer ranges will appear, but the zones usually become more meaningful.
basic trading workflow
1. choose the chart timeframe
start with the timeframe you trade most often.
scalpers may use 1m to 5m.
intraday traders may use 15m to 1h.
swing traders may use 4h to daily.
2. set the detection timeframe
leave it empty for chart timeframe detection.
select a higher timeframe when you want cleaner and more structural ranges.
3. wait for an active range
when a range appears, price is currently moving inside a consolidation box. the top acts as upper range resistance, the bottom acts as lower range support, and the midline represents equilibrium.
4. study price behavior inside the box
near the top of the range, traders often watch for rejection, failed breakouts, or liquidity sweeps.
near the bottom of the range, traders often watch for absorption, failed breakdowns, or reversal behavior.
near the midline, price is usually less attractive because it is balanced between both sides.
5. wait for breakout confirmation
breakout markers appear only when price closes beyond the range boundary with the selected atr buffer.
a break above the range suggests upside expansion.
a break below the range suggests downside expansion.
the breakout buffer helps reduce false breaks by requiring extra distance beyond the range boundary.
main inputs explained
detection timeframe
selects the timeframe used to detect ranges. leave empty to use the current chart timeframe. use higher timeframes for cleaner structural ranges.
min consolidation bars
sets the minimum number of bars required before a range can be confirmed. higher values create fewer but stronger ranges. lower values make the tool more reactive.
reference atr length
controls the volatility reference used to evaluate range height and breakout buffer. a longer atr length gives a smoother volatility base.
max range height
defines the maximum allowed range height in atr units. if the box becomes too wide, the structure is no longer treated as a clean range.
breakout buffer
adds confirmation beyond the range boundary before a breakout is validated. increasing this value makes breakouts stricter.
small range threshold
defines the maximum atr height for a small range.
medium range threshold
defines the maximum atr height for a medium range. anything above this level is classified as large.
show small, medium, large
allows each range category to be shown or hidden independently.
show midline
displays the equilibrium level of the range.
show range labels
displays the range class and range height directly on the chart.
show breakout markers
displays breakout markers when price confirms an upside or downside break.
show dashboard
shows the live range dashboard.
dashboard position
moves the dashboard to any side or corner of the chart.
dashboard size
changes the text size of the dashboard.
range colors and opacity
each range category can be customized with its own color. fill opacity, border opacity, midline opacity, and label opacity can also be adjusted to match any chart style.
dashboard
the dashboard gives a fast reading of the current market state.
it shows:
active timeframe
current state
range height
top level
midline
bottom level
when no valid range is active, the dashboard shows that the market is trending or that no range is currently detected.
alerts
the indicator includes alerts for:
range started
range break up
range break down
these alerts can be used to monitor new compression zones and confirmed exits from consolidation.
example setups
scalping setup
chart timeframe: 5m
detection timeframe: 1h
min consolidation: 10 to 20 bars
breakout buffer: 0.20 to 0.35 atr
this setup keeps the chart reactive while using stronger higher timeframe structure.
intraday setup
chart timeframe: 15m
detection timeframe: 4h
min consolidation: 10 to 30 bars
breakout buffer: 0.25 to 0.50 atr
this setup is useful for session ranges and larger intraday breakouts.
swing setup
chart timeframe: 1h or 4h
detection timeframe: daily
min consolidation: 10 to 50 bars
breakout buffer: 0.35 to 0.75 atr
this setup focuses on major compression zones before larger directional moves.
practical interpretation
inside the range, the market is balanced.
above the range, buyers are attempting expansion.
below the range, sellers are attempting expansion.
the midline is the equilibrium zone. reactions near the top and bottom are usually more meaningful than signals in the middle.
range detector is not designed to predict direction by itself. it is designed to map consolidation, structure, compression, and breakout conditions so traders can build cleaner decisions around price behavior.
best used with:
market structure
volume analysis
session timing
liquidity sweeps
support and resistance
trend filters
risk management
risk note
no indicator guarantees a winning trade. always use risk management, wait for confirmation, and avoid trading during unclear market conditions.
instead of marking every small pause as a range, the tool waits for price to remain contained between two boundaries for a minimum number of bars. the range must stay compact compared to volatility, avoid strong directional expansion, and remain valid until a confirmed breakout or structural widening occurs.
the goal is simple: help traders separate true sideways compression from normal market noise.
what the indicator detects
range detector searches for market areas where price is moving inside a controlled box instead of trending aggressively. a valid range is built from three main conditions:
price must stay contained between a top and bottom boundary
the height of the box must remain reasonable compared to atr
the structure must last long enough to confirm consolidation
once a range is active, the indicator displays:
top of the range
bottom of the range
midline equilibrium
range size classification
breakout markers
dashboard status
range size classification
each range is classified by height using atr units.
small range
medium range
large range
this helps understand whether the market is compressing tightly or building a wider consolidation structure. a tight range can be useful for breakout preparation, while a wider range can be useful for mean reversion, liquidity sweeps, and boundary reactions.
multi-timeframe detection
one of the most important features is the detection timeframe input.
by default, the detection timeframe is empty. this means the indicator uses the current chart timeframe.
for stronger structure, you can select a higher timeframe.
examples:
on a 5 minute chart, set detection timeframe to 1h to see larger intraday ranges
on a 15 minute chart, set detection timeframe to 4h to track stronger session structures
on a 1h chart, set detection timeframe to 1d to follow major daily compression zones
this is useful because a range detected on a higher timeframe is generally more important than a small range detected only on the chart timeframe.
when using mtf, the range engine runs directly on the selected detection timeframe. this means the boxes are not simply visual approximations from the lower timeframe. the range logic is calculated from the chosen timeframe structure.
how to use mtf correctly
for scalping, use a chart timeframe such as 1m, 3m, or 5m, then set the detection timeframe to 15m, 30m, or 1h.
for intraday trading, use a chart timeframe such as 5m, 15m, or 30m, then set the detection timeframe to 1h or 4h.
for swing trading, use a chart timeframe such as 1h or 4h, then set the detection timeframe to daily or weekly.
the higher the detection timeframe, the fewer ranges will appear, but the zones usually become more meaningful.
basic trading workflow
1. choose the chart timeframe
start with the timeframe you trade most often.
scalpers may use 1m to 5m.
intraday traders may use 15m to 1h.
swing traders may use 4h to daily.
2. set the detection timeframe
leave it empty for chart timeframe detection.
select a higher timeframe when you want cleaner and more structural ranges.
3. wait for an active range
when a range appears, price is currently moving inside a consolidation box. the top acts as upper range resistance, the bottom acts as lower range support, and the midline represents equilibrium.
4. study price behavior inside the box
near the top of the range, traders often watch for rejection, failed breakouts, or liquidity sweeps.
near the bottom of the range, traders often watch for absorption, failed breakdowns, or reversal behavior.
near the midline, price is usually less attractive because it is balanced between both sides.
5. wait for breakout confirmation
breakout markers appear only when price closes beyond the range boundary with the selected atr buffer.
a break above the range suggests upside expansion.
a break below the range suggests downside expansion.
the breakout buffer helps reduce false breaks by requiring extra distance beyond the range boundary.
main inputs explained
detection timeframe
selects the timeframe used to detect ranges. leave empty to use the current chart timeframe. use higher timeframes for cleaner structural ranges.
min consolidation bars
sets the minimum number of bars required before a range can be confirmed. higher values create fewer but stronger ranges. lower values make the tool more reactive.
reference atr length
controls the volatility reference used to evaluate range height and breakout buffer. a longer atr length gives a smoother volatility base.
max range height
defines the maximum allowed range height in atr units. if the box becomes too wide, the structure is no longer treated as a clean range.
breakout buffer
adds confirmation beyond the range boundary before a breakout is validated. increasing this value makes breakouts stricter.
small range threshold
defines the maximum atr height for a small range.
medium range threshold
defines the maximum atr height for a medium range. anything above this level is classified as large.
show small, medium, large
allows each range category to be shown or hidden independently.
show midline
displays the equilibrium level of the range.
show range labels
displays the range class and range height directly on the chart.
show breakout markers
displays breakout markers when price confirms an upside or downside break.
show dashboard
shows the live range dashboard.
dashboard position
moves the dashboard to any side or corner of the chart.
dashboard size
changes the text size of the dashboard.
range colors and opacity
each range category can be customized with its own color. fill opacity, border opacity, midline opacity, and label opacity can also be adjusted to match any chart style.
dashboard
the dashboard gives a fast reading of the current market state.
it shows:
active timeframe
current state
range height
top level
midline
bottom level
when no valid range is active, the dashboard shows that the market is trending or that no range is currently detected.
alerts
the indicator includes alerts for:
range started
range break up
range break down
these alerts can be used to monitor new compression zones and confirmed exits from consolidation.
example setups
scalping setup
chart timeframe: 5m
detection timeframe: 1h
min consolidation: 10 to 20 bars
breakout buffer: 0.20 to 0.35 atr
this setup keeps the chart reactive while using stronger higher timeframe structure.
intraday setup
chart timeframe: 15m
detection timeframe: 4h
min consolidation: 10 to 30 bars
breakout buffer: 0.25 to 0.50 atr
this setup is useful for session ranges and larger intraday breakouts.
swing setup
chart timeframe: 1h or 4h
detection timeframe: daily
min consolidation: 10 to 50 bars
breakout buffer: 0.35 to 0.75 atr
this setup focuses on major compression zones before larger directional moves.
practical interpretation
inside the range, the market is balanced.
above the range, buyers are attempting expansion.
below the range, sellers are attempting expansion.
the midline is the equilibrium zone. reactions near the top and bottom are usually more meaningful than signals in the middle.
range detector is not designed to predict direction by itself. it is designed to map consolidation, structure, compression, and breakout conditions so traders can build cleaner decisions around price behavior.
best used with:
market structure
volume analysis
session timing
liquidity sweeps
support and resistance
trend filters
risk management
risk note
no indicator guarantees a winning trade. always use risk management, wait for confirmation, and avoid trading during unclear market conditions.
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
Light the candle that sleeps within you.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
Light the candle that sleeps within you.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.