OPEN-SOURCE SCRIPT
Time-Based Range Sweep (DTR)

SUGGESTED TITLE
Time-Based Range Sweep (TBRS)
SHORT TITLE
TBRS
---
OVERVIEW
Time-Based Range Sweep builds a price range from two user-defined intraday time windows, waits for price to sweep one side of that range after the window closes, and then looks for a specific reversal confirmation before marking an entry, a stop area, and a target area.
The idea behind it is simple: a fixed block of time produces a high and a low. Once that block is finished, those two levels sit on the chart as reference liquidity. Price often runs one side of them before moving in the opposite direction. This script automates the bookkeeping around that sequence — drawing the range, flagging which side was swept, waiting for a confirmation you select, and projecting the resulting levels forward so you are not measuring them by hand.
Each range is independent and each range produces at most one signal per day.
---
HOW IT WORKS
1. RANGE CONSTRUCTION
Two session windows can be enabled independently. Both are interpreted in a timezone you choose (default America/New_York), so the ranges stay anchored to the same clock time regardless of your chart's display timezone.
While a window is open, the script tracks the running highest high and lowest low of every bar inside it, drawing a live box and two solid boundary lines that expand as the window develops. When the window closes, the box is finalized, and dotted or dashed projection lines carry the high and the low forward for a configurable number of bars. Optional labels mark the range title, TBR RANGE HIGH, and TBR RANGE LOW.
Defaults are 01:12–02:12 and 08:12–09:12 New York time, but both windows are fully editable — any two intraday blocks can be used.
2. SWEEP DETECTION
Sweep logic only becomes active after the window has closed. The first bar that trades beyond either boundary is registered as the sweep for that range:
- A bar trading below the range low is a low sweep, which sets a long bias.
- A bar trading above the range high is a high sweep, which sets a short bias.
"Sweep must reclaim range" is on by default. With it enabled, a wick through the level is not enough — the bar must also close back inside the range for the sweep to count, which filters out bars that simply break the level and keep going. Turning it off accepts any penetration of the boundary.
Only the first sweep after each window is used. Once a side has been taken, the range stops looking for further sweeps until the next session.
3. CONFIRMATION MODELS
After a sweep is registered, the script waits for one of three confirmations. You pick which one is active, or choose Any Confirmation and take whichever appears first.
3 Candle Reversal — After the sweep, the script counts consecutive bars closing against the anticipated direction (down closes following a low sweep, up closes following a high sweep) and records the high and low of that sequence. The counter resets if the run is broken before it reaches three. Once at least three have accumulated, the signal fires on a close beyond the sequence extreme — above the sequence high for longs, below the sequence low for shorts.
CISD — A close through the three-bar structural extreme: above the highest high of the previous three bars for longs, below the lowest low of the previous three bars for shorts.
IFVG — A displacement gap in the direction of the bias. For longs, the current bar's low prints above the high from two bars back; for shorts, the current bar's high prints below the low from two bars back.
All confirmations are evaluated on confirmed bar closes, so signals do not appear and disappear intrabar.
4. STOP PLACEMENT
When a signal fires, the stop reference is the most recent confirmed swing pivot that formed at or after the sweep bar — a pivot low for longs, a pivot high for shorts. Pivot strictness is set by the left and right bar inputs.
Because a confirmed pivot requires a fixed number of bars on both sides, fast setups can trigger before one exists. In that case the script falls back to the lowest low or highest high over a configurable lookback. A tick buffer is then applied beyond whichever reference was used.
5. PROJECTION
Three objects are drawn forward from the confirmation bar for a set number of bars:
- Entry level — a horizontal line at the confirmation close, labeled with which confirmation produced it.
- Stop zone — a shaded area between the entry and the calculated stop.
- Target zone — a shaded area between the entry and the opposite side of the range. A long that came from a low sweep targets the range high; a short that came from a high sweep targets the range low.
The target zone is a reference for the measured objective of the setup, not a projection of where price will go.
---
SETTINGS
SESSIONS
- Show London range / Show New York range — enable each window independently.
- Range time — the time window for each range.
- Range label — text shown in the center of each finished box.
- Session timezone — IANA timezone used to interpret both windows.
- Projection bars — how far entry, stop, and target objects extend.
- Extended range line bars — how far the dotted or dashed boundary lines extend past the window.
SWEEP AND CONFIRMATION
- Confirmation mode — 3 Candle Reversal, IFVG, CISD, or Any Confirmation.
- Sweep must reclaim range — require a close back inside the range for a valid sweep.
- Pivot left bars / Pivot right bars — swing strictness for stop placement.
- Stop fallback lookback — used when no confirmed pivot exists between sweep and entry.
- Stop buffer ticks — additional distance beyond the stop reference.
VISUALS
- Entry markers with independent long and short colors and five size options.
- Toggles for target and stop zones, range labels, entry level, and entry type text.
- Label vertical offset and label size.
STYLE
- Colors for range fill, range border, target zone, stop zone, and entry level.
- Extended line style: dotted or dashed.
---
HOW TO USE IT
Set both windows to the time blocks you actually trade and confirm the session timezone matches how you think about those times. The defaults are New York time, so a window entered as 01:12–02:12 is 01:12 New York regardless of where your chart is set.
Intraday timeframes are required, and the timeframe should divide cleanly into the window length so the range is built from a sensible number of bars. A 60-minute window on a 1, 3, 5, or 15 minute chart works; the same window on a 4-hour chart does not.
Start with a single confirmation mode rather than Any Confirmation. The three models have different characteristics: 3 Candle Reversal is the slowest and requires a developed base, CISD is the most immediate, and IFVG requires visible displacement. Any Confirmation takes whichever fires first, which will usually be the fastest of the three.
Tune the pivot inputs to your timeframe. Wider pivot settings produce more meaningful swing stops but increase how often the fallback lookback is used instead.
---
ALERTS
Five alert conditions are available:
- London range confirmation long
- London range confirmation short
- New York range confirmation long
- New York range confirmation short
- Any range confirmation signal
Each fires on the close of the confirmation bar and includes ticker and interval placeholders.
---
NOTES AND LIMITATIONS
- One signal maximum per range per day. Once a range has produced a confirmation, it stops evaluating until the next session.
- Range boxes and boundary lines update live while a window is open. Signals, zones, and entry levels are drawn on confirmed closes only.
- Drawing objects are capped at 500 boxes, lines, and labels. On very long chart histories the oldest objects will be removed by TradingView automatically.
- Sessions are evaluated with the chart's own bars, so illiquid symbols with gaps inside a window may produce ranges built from very few bars.
- Stop and target areas are geometric references derived from the range and recent structure. They are not orders, not backtested results, and carry no assumption about outcome.
---
ORIGINALITY
This is an original implementation written from scratch in Pine Script v6. The individual concepts it draws on — session ranges, liquidity sweeps, change in state of delivery, and inverse fair value gaps — are widely discussed public trading concepts, and no claim of ownership is made over them. What this script contributes is the specific pipeline that links them: an arbitrary time-defined range, an optional reclaim-filtered first sweep, a selectable confirmation stage, a pivot-based stop with a lookback fallback, and a target anchored to the opposite range boundary — all handled per-session with independent state for two windows.
---
DISCLAIMER
This indicator is provided for educational and informational purposes. It does not produce financial advice, and nothing it draws should be treated as a recommendation to buy or sell. Signals are historical observations of price behavior and do not predict future movement. Test any tool thoroughly on your own instruments and timeframes before risking capital, and manage your own risk.
Time-Based Range Sweep (TBRS)
SHORT TITLE
TBRS
---
OVERVIEW
Time-Based Range Sweep builds a price range from two user-defined intraday time windows, waits for price to sweep one side of that range after the window closes, and then looks for a specific reversal confirmation before marking an entry, a stop area, and a target area.
The idea behind it is simple: a fixed block of time produces a high and a low. Once that block is finished, those two levels sit on the chart as reference liquidity. Price often runs one side of them before moving in the opposite direction. This script automates the bookkeeping around that sequence — drawing the range, flagging which side was swept, waiting for a confirmation you select, and projecting the resulting levels forward so you are not measuring them by hand.
Each range is independent and each range produces at most one signal per day.
---
HOW IT WORKS
1. RANGE CONSTRUCTION
Two session windows can be enabled independently. Both are interpreted in a timezone you choose (default America/New_York), so the ranges stay anchored to the same clock time regardless of your chart's display timezone.
While a window is open, the script tracks the running highest high and lowest low of every bar inside it, drawing a live box and two solid boundary lines that expand as the window develops. When the window closes, the box is finalized, and dotted or dashed projection lines carry the high and the low forward for a configurable number of bars. Optional labels mark the range title, TBR RANGE HIGH, and TBR RANGE LOW.
Defaults are 01:12–02:12 and 08:12–09:12 New York time, but both windows are fully editable — any two intraday blocks can be used.
2. SWEEP DETECTION
Sweep logic only becomes active after the window has closed. The first bar that trades beyond either boundary is registered as the sweep for that range:
- A bar trading below the range low is a low sweep, which sets a long bias.
- A bar trading above the range high is a high sweep, which sets a short bias.
"Sweep must reclaim range" is on by default. With it enabled, a wick through the level is not enough — the bar must also close back inside the range for the sweep to count, which filters out bars that simply break the level and keep going. Turning it off accepts any penetration of the boundary.
Only the first sweep after each window is used. Once a side has been taken, the range stops looking for further sweeps until the next session.
3. CONFIRMATION MODELS
After a sweep is registered, the script waits for one of three confirmations. You pick which one is active, or choose Any Confirmation and take whichever appears first.
3 Candle Reversal — After the sweep, the script counts consecutive bars closing against the anticipated direction (down closes following a low sweep, up closes following a high sweep) and records the high and low of that sequence. The counter resets if the run is broken before it reaches three. Once at least three have accumulated, the signal fires on a close beyond the sequence extreme — above the sequence high for longs, below the sequence low for shorts.
CISD — A close through the three-bar structural extreme: above the highest high of the previous three bars for longs, below the lowest low of the previous three bars for shorts.
IFVG — A displacement gap in the direction of the bias. For longs, the current bar's low prints above the high from two bars back; for shorts, the current bar's high prints below the low from two bars back.
All confirmations are evaluated on confirmed bar closes, so signals do not appear and disappear intrabar.
4. STOP PLACEMENT
When a signal fires, the stop reference is the most recent confirmed swing pivot that formed at or after the sweep bar — a pivot low for longs, a pivot high for shorts. Pivot strictness is set by the left and right bar inputs.
Because a confirmed pivot requires a fixed number of bars on both sides, fast setups can trigger before one exists. In that case the script falls back to the lowest low or highest high over a configurable lookback. A tick buffer is then applied beyond whichever reference was used.
5. PROJECTION
Three objects are drawn forward from the confirmation bar for a set number of bars:
- Entry level — a horizontal line at the confirmation close, labeled with which confirmation produced it.
- Stop zone — a shaded area between the entry and the calculated stop.
- Target zone — a shaded area between the entry and the opposite side of the range. A long that came from a low sweep targets the range high; a short that came from a high sweep targets the range low.
The target zone is a reference for the measured objective of the setup, not a projection of where price will go.
---
SETTINGS
SESSIONS
- Show London range / Show New York range — enable each window independently.
- Range time — the time window for each range.
- Range label — text shown in the center of each finished box.
- Session timezone — IANA timezone used to interpret both windows.
- Projection bars — how far entry, stop, and target objects extend.
- Extended range line bars — how far the dotted or dashed boundary lines extend past the window.
SWEEP AND CONFIRMATION
- Confirmation mode — 3 Candle Reversal, IFVG, CISD, or Any Confirmation.
- Sweep must reclaim range — require a close back inside the range for a valid sweep.
- Pivot left bars / Pivot right bars — swing strictness for stop placement.
- Stop fallback lookback — used when no confirmed pivot exists between sweep and entry.
- Stop buffer ticks — additional distance beyond the stop reference.
VISUALS
- Entry markers with independent long and short colors and five size options.
- Toggles for target and stop zones, range labels, entry level, and entry type text.
- Label vertical offset and label size.
STYLE
- Colors for range fill, range border, target zone, stop zone, and entry level.
- Extended line style: dotted or dashed.
---
HOW TO USE IT
Set both windows to the time blocks you actually trade and confirm the session timezone matches how you think about those times. The defaults are New York time, so a window entered as 01:12–02:12 is 01:12 New York regardless of where your chart is set.
Intraday timeframes are required, and the timeframe should divide cleanly into the window length so the range is built from a sensible number of bars. A 60-minute window on a 1, 3, 5, or 15 minute chart works; the same window on a 4-hour chart does not.
Start with a single confirmation mode rather than Any Confirmation. The three models have different characteristics: 3 Candle Reversal is the slowest and requires a developed base, CISD is the most immediate, and IFVG requires visible displacement. Any Confirmation takes whichever fires first, which will usually be the fastest of the three.
Tune the pivot inputs to your timeframe. Wider pivot settings produce more meaningful swing stops but increase how often the fallback lookback is used instead.
---
ALERTS
Five alert conditions are available:
- London range confirmation long
- London range confirmation short
- New York range confirmation long
- New York range confirmation short
- Any range confirmation signal
Each fires on the close of the confirmation bar and includes ticker and interval placeholders.
---
NOTES AND LIMITATIONS
- One signal maximum per range per day. Once a range has produced a confirmation, it stops evaluating until the next session.
- Range boxes and boundary lines update live while a window is open. Signals, zones, and entry levels are drawn on confirmed closes only.
- Drawing objects are capped at 500 boxes, lines, and labels. On very long chart histories the oldest objects will be removed by TradingView automatically.
- Sessions are evaluated with the chart's own bars, so illiquid symbols with gaps inside a window may produce ranges built from very few bars.
- Stop and target areas are geometric references derived from the range and recent structure. They are not orders, not backtested results, and carry no assumption about outcome.
---
ORIGINALITY
This is an original implementation written from scratch in Pine Script v6. The individual concepts it draws on — session ranges, liquidity sweeps, change in state of delivery, and inverse fair value gaps — are widely discussed public trading concepts, and no claim of ownership is made over them. What this script contributes is the specific pipeline that links them: an arbitrary time-defined range, an optional reclaim-filtered first sweep, a selectable confirmation stage, a pivot-based stop with a lookback fallback, and a target anchored to the opposite range boundary — all handled per-session with independent state for two windows.
---
DISCLAIMER
This indicator is provided for educational and informational purposes. It does not produce financial advice, and nothing it draws should be treated as a recommendation to buy or sell. Signals are historical observations of price behavior and do not predict future movement. Test any tool thoroughly on your own instruments and timeframes before risking capital, and manage your own risk.
Скрипт с открытым кодом
В истинном духе TradingView, создатель этого скрипта сделал его открытым исходным кодом, чтобы трейдеры могли проверить и убедиться в его функциональности. Браво автору! Вы можете использовать его бесплатно, но помните, что перепубликация кода подчиняется нашим Правилам поведения.
Отказ от ответственности
Информация и публикации не предназначены для предоставления и не являются финансовыми, инвестиционными, торговыми или другими видами советов или рекомендаций, предоставленных или одобренных TradingView. Подробнее читайте в Условиях использования.
Скрипт с открытым кодом
В истинном духе TradingView, создатель этого скрипта сделал его открытым исходным кодом, чтобы трейдеры могли проверить и убедиться в его функциональности. Браво автору! Вы можете использовать его бесплатно, но помните, что перепубликация кода подчиняется нашим Правилам поведения.
Отказ от ответственности
Информация и публикации не предназначены для предоставления и не являются финансовыми, инвестиционными, торговыми или другими видами советов или рекомендаций, предоставленных или одобренных TradingView. Подробнее читайте в Условиях использования.