OPEN-SOURCE SCRIPT
Swing High/Low with Liquidity Sweeps

🧠 Overview
This indicator identifies swing highs and swing lows based on user-defined candle lengths and checks for liquidity sweeps—situations where the price breaks a previous swing level but then closes back inside, indicating a potential false breakout or stop hunt. It also supports visual labeling and alerts for these events.
⚙️ Inputs
Swing Length (must be odd number ≥ 3):
Determines how many candles are used to identify swing highs/lows. The central candle must be higher or lower than all neighbors within the range.
Example: If swingLength = 5, the central candle must be higher/lower than the 2 candles on both sides.
Sweep Lookback (bars):
Defines how many bars to look back for possible liquidity sweeps.
Show Swing Labels (checkbox):
Optionally display labels on the chart when a swing high or low is detected.
Show Sweep Labels (checkbox):
Optionally display labels on the chart when a liquidity sweep occurs.
🕯️ Swing Detection Logic
A Swing High is detected when the high of the central candle is greater than the highs of all candles around it (as per the defined length).
A Swing Low is detected when the low of the central candle is lower than the lows of surrounding candles.
Swing labels are placed slightly above (for highs) or below (for lows) the candle.
💧 Liquidity Sweep Logic
A Sweep High is triggered if:
The current high breaks above a previously detected swing high,
And then the candle closes below that swing high,
Within the configured lookback window.
A Sweep Low is triggered if:
The current low breaks below a previous swing low,
And then closes above it,
Within the lookback window.
These are often seen as stop hunts or fake breakouts.
🔔 Alerts
Sweep High Alert: Triggered when a sweep above a swing high occurs.
Sweep Low Alert: Triggered when a sweep below a swing low occurs.
You can use these to set up TradingView alerts to notify you of potential liquidity grabs.
📊 Use Cases
Identifying market structure shifts.
Spotting fake breakouts and potential reversals.
Assisting in smart money concepts and liquidity-based trading.
Supporting entry timing in trend continuation or reversal strategies.
This indicator identifies swing highs and swing lows based on user-defined candle lengths and checks for liquidity sweeps—situations where the price breaks a previous swing level but then closes back inside, indicating a potential false breakout or stop hunt. It also supports visual labeling and alerts for these events.
⚙️ Inputs
Swing Length (must be odd number ≥ 3):
Determines how many candles are used to identify swing highs/lows. The central candle must be higher or lower than all neighbors within the range.
Example: If swingLength = 5, the central candle must be higher/lower than the 2 candles on both sides.
Sweep Lookback (bars):
Defines how many bars to look back for possible liquidity sweeps.
Show Swing Labels (checkbox):
Optionally display labels on the chart when a swing high or low is detected.
Show Sweep Labels (checkbox):
Optionally display labels on the chart when a liquidity sweep occurs.
🕯️ Swing Detection Logic
A Swing High is detected when the high of the central candle is greater than the highs of all candles around it (as per the defined length).
A Swing Low is detected when the low of the central candle is lower than the lows of surrounding candles.
Swing labels are placed slightly above (for highs) or below (for lows) the candle.
💧 Liquidity Sweep Logic
A Sweep High is triggered if:
The current high breaks above a previously detected swing high,
And then the candle closes below that swing high,
Within the configured lookback window.
A Sweep Low is triggered if:
The current low breaks below a previous swing low,
And then closes above it,
Within the lookback window.
These are often seen as stop hunts or fake breakouts.
🔔 Alerts
Sweep High Alert: Triggered when a sweep above a swing high occurs.
Sweep Low Alert: Triggered when a sweep below a swing low occurs.
You can use these to set up TradingView alerts to notify you of potential liquidity grabs.
📊 Use Cases
Identifying market structure shifts.
Spotting fake breakouts and potential reversals.
Assisting in smart money concepts and liquidity-based trading.
Supporting entry timing in trend continuation or reversal strategies.
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.