OPEN-SOURCE SCRIPT

Liquidity Raids [UAlgo]

4 885
Liquidity Raids is a market structure overlay designed to highlight classic liquidity sweep events around recent swing levels. The script continuously maps swing highs and swing lows using pivot detection, projects those levels forward as active lines, and then monitors price behavior around each level to detect a raid.

A raid is defined here as a sweep through a prior level followed by rejection back across it within the same bar. This behavior often represents stop runs, liquidity grabs, or failed break attempts. The script separates these events into:

BSL sweeps, where buy side liquidity above prior highs is taken and price closes back below the level
SSL sweeps, where sell side liquidity below prior lows is taken and price closes back above the level

To improve signal quality, an optional relative volume confirmation filter can be enabled. When active, a sweep is only valid if the sweep bar’s volume exceeds a multiple of the recent average, and the script prints the relative volume percentage on the chart for additional context.

The indicator also includes practical object management to keep charts clean by limiting the number of active levels and removing invalidated lines automatically.

🔹 Features

1) Automatic Swing Level Mapping via Pivot Highs and Lows
The script uses pivot detection to identify meaningful swing highs and swing lows. Each confirmed pivot becomes a projected liquidity level that extends forward in time. These levels represent areas where stops and breakout orders tend to cluster.

Pivot Length controls how sensitive the swing detection is. Higher values produce fewer but more significant levels. Lower values react faster and produce more frequent levels.

2) Active Level Projection and Management
Each pivot level is drawn as a horizontal line and stored in an internal array. On every new bar, the script updates each active line so it extends to the current bar. A Maximum Active Levels setting prevents chart clutter and controls the number of stored objects. When the limit is exceeded, the oldest level is removed.

3) Clear Sweep Definitions for BSL and SSL
Each level is monitored for two outcomes:

Sweep and reject
Broken and accepted

For resistance levels, a BSL sweep requires the bar high to trade above the level while the close finishes at or below the level. A break requires the close to finish above the level.

For support levels, an SSL sweep requires the bar low to trade below the level while the close finishes at or above the level. A break requires the close to finish below the level.

When a sweep is detected, the level is removed after the event is confirmed. When a level is broken, it is removed to prevent outdated levels from remaining on the chart.

4) Optional Volume Confirmation Using Relative Volume
When enabled, sweeps are filtered using Relative Volume (RVOL). The script compares the current bar’s volume to the 20 bar average volume and requires it to exceed a user defined multiplier.

This is useful for separating meaningful stop runs from thin market spikes. The script also prints the RVOL percentage near the swept level for quick evaluation.

5) Sweep Highlighting and Labels
On a valid sweep, the script highlights the swept level with a bright confirmation line and optionally prints labels:

▼ BSL for buy side liquidity sweeps
▲ SSL for sell side liquidity sweeps

Volume information is also displayed as a percentage at the midpoint of the swept segment, positioned above for BSL and below for SSL to reduce overlap.

6) Configurable Visual Styling
You can control resistance and support colors independently, choose line style (solid, dotted, dashed), and toggle labels. This makes the overlay adaptable to both clean minimalist charts and more information dense layouts.

7) Alerts for Automation and Monitoring
Alert conditions are included for both sweep types. In addition, the script triggers immediate alerts with the close price when a sweep is detected on bar close. This supports both discretionary monitoring and automated notification workflows.

🔹 Calculations

1) Pivot Based Level Detection
Swing highs and lows are detected using symmetric pivot logic:

Pine Script®


Interpretation:

A pivot high is confirmed only after pivotPeriodInput bars to the right
A pivot low is confirmed only after pivotPeriodInput bars to the right
Confirmed pivot values become new resistance or support liquidity levels

2) Level Storage and Line Creation
When a pivot is confirmed, the script creates a line starting at the pivot bar and stores it as a LiquidityLevel object:

Pine Script®


The same logic applies to pivot lows for support levels.

To prevent excessive object growth, levels are capped:

Pine Script®


3) Relative Volume and Volume Filter
The script computes average volume over the last 20 bars and converts current volume into a percentage:

Pine Script®


The volume filter is satisfied when either the filter is disabled or the current volume exceeds the average multiplied by the chosen multiplier:

Pine Script®


4) Sweep and Break Conditions
Each active resistance level is checked for a sweep or a break:

Pine Script®


Each active support level is checked similarly:

Pine Script®


Interpretation:

A sweep requires a wick through the level and a close back across it
A break requires acceptance beyond the level on close

5) Sweep Confirmation Handling and Cleanup
When a sweep occurs with strong volume, the script sets a flag for alerts, draws highlight objects, prints labels, and removes the level from active tracking:

Resistance sweep flow:

Pine Script®


Support sweep flow:

Pine Script®


If a level is broken, it is removed as invalid:

Pine Script®


6) Volume Annotation Placement
On a sweep, the script computes the midpoint of the level segment in bar index space and prints RVOL percent:

Pine Script®


Placement is above for BSL sweeps and below for SSL sweeps to align with the direction of the liquidity being taken.

7) Alerts
Alert conditions and direct alerts are provided:

Pine Script®


The script also triggers runtime alerts including the close price once per bar close when a sweep occurs.

Aviso legal

As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.