You have watched price poke above a prior high, grab the stops sitting there, and close back underneath. The chart looks obvious after the fact. Coding that behavior is less obvious, because a swing high is not known on the bar that prints it, a wick is not the same thing as a close, and a pool that gets run through and left behind is a different event from a pool that price actually accepts beyond. Liquidity Sweeps is the Pine Script v6 indicator in the PineScripter library that writes those distinctions down and draws them.
Short answer
A buy-side sweep is a wick above a pool built from swing highs, with the bar closing back below that pool. A sell-side sweep is the mirror image under swing lows. The library indicator confirms the swing with bars on both sides, merges nearby swings into one thicker pool, requires volume at least 1.5 times its average before it prints a grade, and marks the sweep as failed if price closes back beyond the level within five bars. Every test runs on a closed bar. The marks describe what price and volume did. They are not instructions.
Key facts
- Buy-side pools sit on swing highs. Sell-side pools sit on swing lows. The names refer to where resting orders tend to cluster, not to a trade.
- A sweep is high above the pool and close back below it, or low below the pool and close back above it. A close through the pool is a different event and turns the line grey.
- Swings use ta.pivothigh and ta.pivotlow, so a pool is only known after the right-hand bars have printed. The default presets are 5, 10, and 20 bars per side.
- Two swings closer than 0.1 ATR share one pool. That pool is drawn thicker. Grade A requires that thicker pool and confirmed volume.
- Grade B is confirmed volume without an equal-level pool. Grade C has no volume confirmation and is hidden unless you turn it on.
- Volume confirmation is volume at least 1.5 times a 50-bar average.
- A dashed line is a pool that was swept. A grey line was closed through, or it aged out after 300 bars.
- An x marks a failed sweep: within five bars, a later close goes back beyond the swept level.
- The script only evaluates sweeps on barstate.isconfirmed, so a developing bar cannot print a mark that the close then erases.
| What you see | Rule | Default |
|---|---|---|
| Red line above price | Pool on a swing high | Intraday swing of 10 bars |
| Green line below price | Pool on a swing low | Same swing length |
| Thicker line | A later swing landed within 0.1 ATR | Merged into the first level |
| Dashed line | A wick went through and the close came back | Pool is retired |
| Grey line | A close went through, or the pool turned 300 bars old | Not called a sweep |
| BSL or SSL label | Sweep on a closed bar | Hidden for grade C |
| x | Close back beyond the level inside the failure window | 5 bars |
A pool is a swing, and a swing is late on purpose
Stops and breakout orders tend to sit just beyond prices that lots of people can see. A prior swing high is one of those prices. The indicator treats each confirmed swing high as buy-side liquidity and each confirmed swing low as sell-side liquidity, and it draws a horizontal line from the swing forward until something happens to it. That is the whole premise. Nothing in the script claims those orders are really there, or that taking them out leads anywhere. It claims that this bar traded through a level built by a stated rule, and that the close came back.
The swing rule is ta.pivothigh and ta.pivotlow with the same number of bars on the left and the right. The left bars are already history. The right bars are the confirmation, and they do not exist yet when the swing prints. With the Intraday preset that number is 10, so a pool appears 10 bars after the high or low it marks. Scalp uses 5. Swing uses 20. A custom length from 1 to 50 replaces the preset when you set it above zero. There is no honest setting that removes the wait. A pool that shows up on the swing bar itself, on historical data, was allowed to see the future.
When the pivot finally confirms, the line is anchored at the swing bar, which is bar_index minus the swing length, not at the bar you are standing on. From then on the line is extended to the current bar until the pool is retired. It does not drift to a new price. If you need the level for a decision, the decision is available only after confirmation, which is the same constraint covered in the pivot high and low guide.
//@version=6
indicator("One pool, for the idea", overlay = true)
len = input.int(10, "Bars each side of the swing", minval = 1)
ph = ta.pivothigh(high, len, len)
pl = ta.pivotlow(low, len, len)
var float buySide = na
var float sellSide = na
if not na(ph)
buySide := ph
if not na(pl)
sellSide := pl
// Wick through, close back inside. The developing bar is ignored.
sweptHigh = barstate.isconfirmed and not na(buySide) and high > buySide and close < buySide
sweptLow = barstate.isconfirmed and not na(sellSide) and low < sellSide and close > sellSide
plot(buySide, "Buy-side pool", color.red)
plot(sellSide, "Sell-side pool", color.teal)
plotshape(sweptHigh, "Buy-side sweep", shape.triangledown, location.abovebar, color.red, size = size.tiny)
plotshape(sweptLow, "Sell-side sweep", shape.triangleup, location.belowbar, color.teal, size = size.tiny)This fragment keeps a single level per side so the test is easy to read. The library script keeps every live pool in parallel arrays, because a chart usually has more than one untouched swing at a time. The test itself is the same: a wick through, a close back inside, and a confirmed bar.
Equal highs share a pool instead of stacking lines
Two swings at almost the same price are usually the same idea seen twice. The indicator measures the distance in ATR. With the default tolerance of 0.1, a new swing within a tenth of the 14-bar ATR of an existing pool does not get its own line. The existing pool is marked as an equal high or equal low, and its line is drawn at width 2. The stored price stays where the first swing put it. The newer swing thickens the pool. It does not average the two prices.
That thickness is what grade A is made of. A sweep of a thickened pool, on a bar whose volume also confirms, is grade A. A sweep on confirmed volume of an ordinary pool is grade B. A sweep whose volume never reached the threshold is grade C, and grade C is off unless you enable "Show sweeps without volume confirmation". Turning it on does not change the test. It only lets the weak cases print a label.
Volume confirmation is relative volume against a 50-bar simple average, and the default multiple is 1.5. The label tooltip prints the multiple for that bar, so you can see whether a grade B was barely over the line or several times average. The average includes the current bar, which is the usual Pine behavior of ta.sma(volume, length) on the bar being tested. If you want the average to exclude the sweep bar, that is a one-line change in the editor. It will move some grades from B to C and back.
A close through the level is not a sweep
The interesting case is the wick. High trades above the pool, close finishes back below it. The pool was visited and not accepted. The line is set to dashed, painted in the pool color, and removed from the active set so it cannot be swept again. If several pools are swept on the same bar, one label is printed, and the grade is A if any of those pools was an equal-level pool on confirmed volume.
The other case is acceptance. If the bar closes beyond the pool, the line is extended to that bar, painted grey, and retired. The same grey treatment applies when a pool reaches the age limit, 300 bars by default, without being touched. Grey means the level is no longer a live pool. It does not mean a sweep happened. Mixing those two endings is how a sweep indicator turns into a picture of every broken high, which is a different script.
Dashed lines remain on the chart as history, up to the drawing budget. The indicator asks TradingView for 500 lines and 500 labels. Old pools are individual line objects, so a long chart can approach that cap. When you change the swing length or the age limit, watch the left side of the chart. If the oldest lines vanish, the budget is the reason, and the drawing-limits guide is the place that walks through the diagnosis.
Failed means price went back within a few bars
A sweep can look clean on its own bar and be undone immediately. The failure rule is deliberately small. After a marked sweep, the script remembers the level and the bar. If a later confirmed bar closes back beyond that level within the failure window, it prints an x and forgets the level. The default window is 5 bars. A close above a swept buy-side pool, or a close below a swept sell-side pool, is the failure. A wick back through, with the close still on the swept side, is not.
The window is checked only when the current bar is not itself a new sweep on that side, so a fresh sweep replaces the one being watched instead of failing it. If the window expires with no close back beyond the level, the memory is cleared and nothing is printed. Absence of an x is not a claim that the sweep "worked". It is the statement that price did not close back through inside the window you set.
Five bars is a choice, not a property of markets. On a 1-minute chart it is a few minutes. On a daily chart it is a week. If you widen it, more sweeps get an x, and the chart gets noisier. If you tighten it to 1, only the very next close can fail the sweep. Write the number down when you change it. The x on the chart will not tell you later which window produced it.
What the library script adds, and what you can change
Liquidity Sweeps is one of the two library indicators that open for any signed-in account. The other three in the library are included with every paid plan. There is no separate free plan. The script is Pine Script v6, it compiles on TradingView, and it runs on the chart inside PineScripter. That chart is crypto spot data, 308 markets from Binance public data, up to 5,000 bars, on the 14 timeframes the app supports. Paste the same script into TradingView when you want it on a market the in-app chart does not carry.
The alerts match the marks: buy-side swept, sell-side swept, grade A on either side, and any failed sweep. They are alertcondition calls, so they become TradingView alerts only after you attach them there. They fire from the same confirmed-bar booleans as the labels. They do not fire from a developing wick.
The useful way to learn the script is to change one input and watch which lines move. Swing length changes how late pools appear and how many of them you get. Equal tolerance changes which swings merge. The volume multiple changes the grade, not the geometry of the wick. The failure window changes only the x. Open it from the indicator library and edit it in place. A follow-up in the editor changes the lines you asked about instead of replacing the definition with a new one.
Frequently asked questions
What is a liquidity sweep in Pine Script?
In this indicator it is a closed bar that wicks through a pool built from a confirmed swing and finishes back inside that pool. Above swing highs that is a buy-side sweep. Below swing lows it is a sell-side sweep. A bar that closes beyond the pool is not counted as a sweep.
Why does the level appear several bars after the swing?
Because ta.pivothigh and ta.pivotlow need bars to the right of the swing before they will return a value. The Intraday preset uses 10 bars on each side, so the pool is known 10 bars late. That delay is the confirmation. Removing it means using data that was not available when the swing printed.
What do grades A, B, and C mean?
Grade A is a sweep of an equal-high or equal-low pool on volume at least 1.5 times its 50-bar average. Grade B is that volume test without the equal-level pool. Grade C is the wick pattern without the volume test, and it stays hidden unless you turn it on.
What is a failed sweep?
A later closed bar, within the failure window, that closes back beyond the swept level. The default window is five bars. An x marks that bar. If the window ends without such a close, no failure mark is printed.
Does the indicator tell me to buy or sell?
No. The labels name which side was swept and which grade the volume rule produced. They describe the closed bar. What you do with that information is outside the script.
The practical takeaway
Write the sweep down as a sentence before you trust the picture. A pool is a confirmed swing. A sweep is a wick through it and a close back inside, on volume you chose, on a bar that has closed. A close through the level is a different event. A failure is a later close back beyond the level inside a window you set. Once those clauses are explicit, the lines on the chart are something you can check instead of something you can only agree with.
Liquidity Sweeps is in the indicator library, and changing the swing, the volume multiple, or the failure window is a normal edit in PineScripter. Open it, read the inputs, and change one of them. The chart inside the app runs on crypto spot markets. Paste the script into TradingView to run the same rules on other markets.
Sources
- Pine Script v6 reference: ta.pivothigh
- Pine Script v6 reference: ta.pivotlow
- Pine Script v6 reference: barstate.isconfirmed
- TradingView: lines, labels, and drawing limits
Related reading: why pivots arrive late, anchored VWAP from the same swings, confirmed bars, line and label limits.
Disclaimer: PineScripter is a coding tool for Pine Script development. It does not provide financial advice and does not guarantee trading profits. Always backtest strategies thoroughly and understand the risks before live trading.