OPEN-SOURCE SCRIPT
Sweep + BOS (Lines + First Confirmed Only)

🔍 Indicator: Sweep + BOS (Break of Structure with Visual Lines)
🧠 Overview
This indicator combines Swing detection, Liquidity Sweeps, and Break of Structure (BOS) logic, with:
Customizable swing length,
BOS signals only after confirmed sweeps,
BOS shown only once per sweep,
Visual labels and connecting lines to highlight structure breaks clearly.
⚙️ Inputs
Swing Length:
Defines how many candles to use to identify a swing high/low. Must be an odd number (e.g., 3, 5, 7...).
Sweep Lookback Window:
Sets how far back the script checks for a sweep (false breakout over a swing).
BOS Validity After Sweep:
Number of bars within which a BOS can be considered valid after a sweep.
Toggle Options:
Show/hide:
Swing Labels
Sweep Labels
BOS Labels
BOS Connecting Lines
📌 Logic Breakdown
✅ Swings
Swing High: A candle’s high is greater than the highs of all N candles on both sides.
Swing Low: A candle’s low is lower than the lows of all N candles on both sides.
💧 Liquidity Sweeps
Sweep High:
Price spikes above a previous Swing High,
Then closes back below it (false breakout).
Sweep Low:
Price drops below a previous Swing Low,
Then closes back above it.
🔁 Break of Structure (BOS)
A BOS is only shown if:
It occurs after a valid sweep (within X bars),
It hasn’t been already plotted for that sweep,
BOS ↑ is only possible after Sweep Low,
BOS ↓ is only possible after Sweep High,
Opposite BOS type resets the last BOS state.
BOS ↑ (Bullish):
Confirmed when price closes above previous Swing High after Sweep Low.
Label appears at the candle low.
A line is drawn from the Swing Low to the BOS candle.
BOS ↓ (Bearish):
Confirmed when price closes below previous Swing Low after Sweep High.
Label appears at the candle high.
A line is drawn from the Swing High to the BOS candle.
🧠 Overview
This indicator combines Swing detection, Liquidity Sweeps, and Break of Structure (BOS) logic, with:
Customizable swing length,
BOS signals only after confirmed sweeps,
BOS shown only once per sweep,
Visual labels and connecting lines to highlight structure breaks clearly.
⚙️ Inputs
Swing Length:
Defines how many candles to use to identify a swing high/low. Must be an odd number (e.g., 3, 5, 7...).
Sweep Lookback Window:
Sets how far back the script checks for a sweep (false breakout over a swing).
BOS Validity After Sweep:
Number of bars within which a BOS can be considered valid after a sweep.
Toggle Options:
Show/hide:
Swing Labels
Sweep Labels
BOS Labels
BOS Connecting Lines
📌 Logic Breakdown
✅ Swings
Swing High: A candle’s high is greater than the highs of all N candles on both sides.
Swing Low: A candle’s low is lower than the lows of all N candles on both sides.
💧 Liquidity Sweeps
Sweep High:
Price spikes above a previous Swing High,
Then closes back below it (false breakout).
Sweep Low:
Price drops below a previous Swing Low,
Then closes back above it.
🔁 Break of Structure (BOS)
A BOS is only shown if:
It occurs after a valid sweep (within X bars),
It hasn’t been already plotted for that sweep,
BOS ↑ is only possible after Sweep Low,
BOS ↓ is only possible after Sweep High,
Opposite BOS type resets the last BOS state.
BOS ↑ (Bullish):
Confirmed when price closes above previous Swing High after Sweep Low.
Label appears at the candle low.
A line is drawn from the Swing Low to the BOS candle.
BOS ↓ (Bearish):
Confirmed when price closes below previous Swing Low after Sweep High.
Label appears at the candle high.
A line is drawn from the Swing High to the BOS candle.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.