OPEN-SOURCE SCRIPT
Apicode Institutional Liquidity Sweep v2

Apicode — Institutional Liquidity Sweep v2 is a price-action based indicator designed to detect potential institutional-style stop hunts and highlight possible entries after liquidity has been taken from retail traders.
The core idea is simple:
- retail traders often place stop losses around obvious swing highs and swing lows
- larger market participants know this
- price frequently sweeps those liquidity pools before moving in the intended direction
This indicator attempts to identify those moments by combining:
- higher timeframe trend
- premium / discount context
- liquidity sweep detection
- reclaim confirmation
- microstructure confirmation
- and automatic **Entry / SL / TP** projection
It is designed to be practical, visually clean, and limited to the last 5 active trade ideas on the chart.
How it works
1. Higher timeframe trend filter
The indicator first checks the broader market context using **higher timeframe EMA structure**.
It compares:
a fast EMA
a slow EMA
On the selected higher timeframe(s), the logic is:
bullish bias when fast EMA is above slow EMA and the slow EMA is rising
bearish bias when fast EMA is below slow EMA and the slow EMA is falling
This helps avoid taking signals against the dominant trend.
Why this matters
Liquidity sweeps are much more useful when they happen **in the direction of the main trend**.
For example:
- in an uptrend, a sweep below a swing low may become a high-probability long setup
- in a downtrend, a sweep above a swing high may become a high-probability short setup
2. Premium / Discount filter
The indicator builds a simple **higher timeframe dealing range** and calculates its midpoint.
Then it classifies the current price as:
- Discount → below the midpoint
- Premium → above the midpoint
This is used as an additional contextual filter:
Long setups are preferred in discount
Short setups are preferred in premium
Why this matters
Institutional-style entries tend to make more sense when:
- buying lower within the broader range
- selling higher within the broader range
This helps avoid chasing price after it has already moved too far.
3. Swing liquidity detection
The script identifies recent swing highs and swing lows using pivot logic.
These levels are treated as likely liquidity pools, because they often attract:
- breakout traders
- stop losses
- late entries
- forced liquidations
The indicator then looks for price sweeping beyond those levels.
4. Liquidity sweep logic
Long setup
A potential long setup appears when:
- the higher timeframe trend is bullish
- price is in discount
- price moves below the latest swing low
- the sweep size remains within a realistic range
- the candle shows meaningful lower wick behavior
Short setup
A potential short setup appears when:
- the higher timeframe trend is bearish
- price is in premium
- price moves above the latest swing high
- the sweep size remains within a realistic range
- the candle shows meaningful upper wick behavior
The indicator also uses a configurable approximation of the **retail stop-loss zone**, based on the idea that many small traders cluster their stops near obvious structure.
5. Reclaim confirmation
A sweep alone is not enough.
The script also requires price to reclaim the swept level with a small configurable buffer.
That means:
- after sweeping below a swing low, price must recover back above it for long bias
- after sweeping above a swing high, price must move back below it for short bias
Why this matters
A lot of sweeps fail.
The reclaim step is essential because it suggests the sweep may have been a **liquidity grab**, not a true breakout.
6. Microstructure confirmation
After the reclaim, the indicator waits for a quick confirmation candle.
That confirmation requires:
- a minimum candle body size
- directional candle confirmation
- a small break of recent local structure
This is meant to avoid entering too early while still keeping the signal relatively close to the swept level.
7. Entry, Stop Loss, and Take Profit
Once a setup is confirmed, the indicator plots:
- Entry
- SL
- TP
Entry
The entry is based on the confirmation candle close.
Stop Loss
The stop loss is placed beyond the sweep extreme, with an additional **ATR-based buffer**.
This is intentional:
- retail traders usually place stops too close
- institutional-style logic needs more breathing room
- the SL should sit beyond the area that was already used to collect liquidity
Take Profit
The take profit is calculated using:
1. the nearest reasonable opposing liquidity zone, if available
2. otherwise, a fallback risk-reward based target
This gives the script a more realistic institutional-style objective rather than using a fixed target only.
8. Active signal cleanup
The indicator keeps the chart clean by:
- displaying only the last 5 visible signals
- automatically removing a signal once price touches:
- SL
- or TP
This prevents the chart from becoming cluttered and ensures that only relevant setups remain visible.
What kind of trader is this for?
This indicator is best suited for traders who already understand:
- market structure
- liquidity concepts
- trend context
- stop hunts
- reversal entries near key levels
It is especially useful for traders who want to avoid:
- entering too late
- buying into local highs
- shorting into local lows
- trading directly into obvious retail traps
Best settings to start with
These are good starting values for **XRPUSDT on 15m** (and others), which is the market this logic was heavily tuned around:
Trend
- HTF main: 60
- HTF secondary: 240
- Fast EMA: 20
- Slow EMA: 50
Premium / Discount
Dealing Range HTF: 20
Swings / Liquidity
- Swing Length: 5
- Minimum Sweep %: 0.12
- Maximum Sweep %: 1.00 to 1.20
- Retail Stop Zone %: 1.00
Confirmation
- Confirm Bars: 2 to 3
- Minimum Confirmation Body: 0.30
- Microstructure Break Lookback: 2
- Max Distance From Swept Level: 0.50 to 0.60 ATR
Risk
- ATR Length: 14
- SL ATR Buffer: 0.15
- Minimum RR to Signal: 1.10
- Fallback RR: 2.00
Volume
- Start with Volume Filter OFF
- Enable it later only if you want fewer but stricter signals
Configuration advice
If you get too many signals
Try:
- increasing Minimum Sweep %
- increasing Minimum Confirmation Body
- increasing Minimum RR to Signal
- enabling the volume filter
- using both HTF 1 and HTF 2
If you get too few signals
Try:
- reducing Minimum Sweep %
- reducing Minimum Confirmation Body
- lowering Minimum RR to Signal
- disabling the second HTF confirmation
- reducing the reclaim buffer slightly
If signals feel too late
Try:
- reducing **Confirm Bars**
- reducing **Microstructure Break Lookback**
- lowering **Minimum Confirmation Body** slightly
If signals still go against the move too often
Try:
- making the trend filter stricter
- requiring both higher timeframes
- tightening premium / discount usage
- reducing the maximum allowed sweep size
Practical interpretation
This indicator is not trying to predict every reversal.
Instead, it focuses on a specific scenario:
1. price moves into an obvious liquidity pool
2. stops are triggered
3. price reclaims the level
4. structure starts to shift back with the dominant trend
5. a trade idea is projected with defined risk and objective
That is the edge this script is built around.
Important notes
- This is **not** an order book tool.
- It does **not** see real liquidity, delta, footprint data, or exchange-level positioning.
- It is a **price-action approximation** of institutional behavior.
- Like any trading tool, it should not be used in isolation.
It works best when combined with:
- higher timeframe market structure
- strong support/resistance zones
- session context
- discretionary chart reading
Suggested usage
A practical workflow could be:
1. determine the higher timeframe directional bias
2. wait for price to reach a meaningful area
3. let the indicator detect the sweep and reclaim
4. evaluate the Entry / SL / TP visually
5. ignore setups that run directly into major nearby obstacles
6. focus only on the cleanest signals aligned with broader context
Final note
This indicator was built with a practical mindset:
* think like a larger participant
* understand where retail traders are trapped
* avoid emotional entries
* wait for liquidity to be taken first
* then act with defined risk
The core idea is simple:
- retail traders often place stop losses around obvious swing highs and swing lows
- larger market participants know this
- price frequently sweeps those liquidity pools before moving in the intended direction
This indicator attempts to identify those moments by combining:
- higher timeframe trend
- premium / discount context
- liquidity sweep detection
- reclaim confirmation
- microstructure confirmation
- and automatic **Entry / SL / TP** projection
It is designed to be practical, visually clean, and limited to the last 5 active trade ideas on the chart.
How it works
1. Higher timeframe trend filter
The indicator first checks the broader market context using **higher timeframe EMA structure**.
It compares:
a fast EMA
a slow EMA
On the selected higher timeframe(s), the logic is:
bullish bias when fast EMA is above slow EMA and the slow EMA is rising
bearish bias when fast EMA is below slow EMA and the slow EMA is falling
This helps avoid taking signals against the dominant trend.
Why this matters
Liquidity sweeps are much more useful when they happen **in the direction of the main trend**.
For example:
- in an uptrend, a sweep below a swing low may become a high-probability long setup
- in a downtrend, a sweep above a swing high may become a high-probability short setup
2. Premium / Discount filter
The indicator builds a simple **higher timeframe dealing range** and calculates its midpoint.
Then it classifies the current price as:
- Discount → below the midpoint
- Premium → above the midpoint
This is used as an additional contextual filter:
Long setups are preferred in discount
Short setups are preferred in premium
Why this matters
Institutional-style entries tend to make more sense when:
- buying lower within the broader range
- selling higher within the broader range
This helps avoid chasing price after it has already moved too far.
3. Swing liquidity detection
The script identifies recent swing highs and swing lows using pivot logic.
These levels are treated as likely liquidity pools, because they often attract:
- breakout traders
- stop losses
- late entries
- forced liquidations
The indicator then looks for price sweeping beyond those levels.
4. Liquidity sweep logic
Long setup
A potential long setup appears when:
- the higher timeframe trend is bullish
- price is in discount
- price moves below the latest swing low
- the sweep size remains within a realistic range
- the candle shows meaningful lower wick behavior
Short setup
A potential short setup appears when:
- the higher timeframe trend is bearish
- price is in premium
- price moves above the latest swing high
- the sweep size remains within a realistic range
- the candle shows meaningful upper wick behavior
The indicator also uses a configurable approximation of the **retail stop-loss zone**, based on the idea that many small traders cluster their stops near obvious structure.
5. Reclaim confirmation
A sweep alone is not enough.
The script also requires price to reclaim the swept level with a small configurable buffer.
That means:
- after sweeping below a swing low, price must recover back above it for long bias
- after sweeping above a swing high, price must move back below it for short bias
Why this matters
A lot of sweeps fail.
The reclaim step is essential because it suggests the sweep may have been a **liquidity grab**, not a true breakout.
6. Microstructure confirmation
After the reclaim, the indicator waits for a quick confirmation candle.
That confirmation requires:
- a minimum candle body size
- directional candle confirmation
- a small break of recent local structure
This is meant to avoid entering too early while still keeping the signal relatively close to the swept level.
7. Entry, Stop Loss, and Take Profit
Once a setup is confirmed, the indicator plots:
- Entry
- SL
- TP
Entry
The entry is based on the confirmation candle close.
Stop Loss
The stop loss is placed beyond the sweep extreme, with an additional **ATR-based buffer**.
This is intentional:
- retail traders usually place stops too close
- institutional-style logic needs more breathing room
- the SL should sit beyond the area that was already used to collect liquidity
Take Profit
The take profit is calculated using:
1. the nearest reasonable opposing liquidity zone, if available
2. otherwise, a fallback risk-reward based target
This gives the script a more realistic institutional-style objective rather than using a fixed target only.
8. Active signal cleanup
The indicator keeps the chart clean by:
- displaying only the last 5 visible signals
- automatically removing a signal once price touches:
- SL
- or TP
This prevents the chart from becoming cluttered and ensures that only relevant setups remain visible.
What kind of trader is this for?
This indicator is best suited for traders who already understand:
- market structure
- liquidity concepts
- trend context
- stop hunts
- reversal entries near key levels
It is especially useful for traders who want to avoid:
- entering too late
- buying into local highs
- shorting into local lows
- trading directly into obvious retail traps
Best settings to start with
These are good starting values for **XRPUSDT on 15m** (and others), which is the market this logic was heavily tuned around:
Trend
- HTF main: 60
- HTF secondary: 240
- Fast EMA: 20
- Slow EMA: 50
Premium / Discount
Dealing Range HTF: 20
Swings / Liquidity
- Swing Length: 5
- Minimum Sweep %: 0.12
- Maximum Sweep %: 1.00 to 1.20
- Retail Stop Zone %: 1.00
Confirmation
- Confirm Bars: 2 to 3
- Minimum Confirmation Body: 0.30
- Microstructure Break Lookback: 2
- Max Distance From Swept Level: 0.50 to 0.60 ATR
Risk
- ATR Length: 14
- SL ATR Buffer: 0.15
- Minimum RR to Signal: 1.10
- Fallback RR: 2.00
Volume
- Start with Volume Filter OFF
- Enable it later only if you want fewer but stricter signals
Configuration advice
If you get too many signals
Try:
- increasing Minimum Sweep %
- increasing Minimum Confirmation Body
- increasing Minimum RR to Signal
- enabling the volume filter
- using both HTF 1 and HTF 2
If you get too few signals
Try:
- reducing Minimum Sweep %
- reducing Minimum Confirmation Body
- lowering Minimum RR to Signal
- disabling the second HTF confirmation
- reducing the reclaim buffer slightly
If signals feel too late
Try:
- reducing **Confirm Bars**
- reducing **Microstructure Break Lookback**
- lowering **Minimum Confirmation Body** slightly
If signals still go against the move too often
Try:
- making the trend filter stricter
- requiring both higher timeframes
- tightening premium / discount usage
- reducing the maximum allowed sweep size
Practical interpretation
This indicator is not trying to predict every reversal.
Instead, it focuses on a specific scenario:
1. price moves into an obvious liquidity pool
2. stops are triggered
3. price reclaims the level
4. structure starts to shift back with the dominant trend
5. a trade idea is projected with defined risk and objective
That is the edge this script is built around.
Important notes
- This is **not** an order book tool.
- It does **not** see real liquidity, delta, footprint data, or exchange-level positioning.
- It is a **price-action approximation** of institutional behavior.
- Like any trading tool, it should not be used in isolation.
It works best when combined with:
- higher timeframe market structure
- strong support/resistance zones
- session context
- discretionary chart reading
Suggested usage
A practical workflow could be:
1. determine the higher timeframe directional bias
2. wait for price to reach a meaningful area
3. let the indicator detect the sweep and reclaim
4. evaluate the Entry / SL / TP visually
5. ignore setups that run directly into major nearby obstacles
6. focus only on the cleanest signals aligned with broader context
Final note
This indicator was built with a practical mindset:
* think like a larger participant
* understand where retail traders are trapped
* avoid emotional entries
* wait for liquidity to be taken first
* then act with defined risk
Skrip open-source
Dengan semangat TradingView yang sesungguhnya, pembuat skrip ini telah menjadikannya sebagai sumber terbuka, sehingga para trader dapat meninjau dan memverifikasi fungsinya. Salut untuk penulisnya! Meskipun Anda dapat menggunakannya secara gratis, perlu diingat bahwa penerbitan ulang kode ini tunduk pada Tata Tertib kami.
Pernyataan Penyangkalan
Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.
Skrip open-source
Dengan semangat TradingView yang sesungguhnya, pembuat skrip ini telah menjadikannya sebagai sumber terbuka, sehingga para trader dapat meninjau dan memverifikasi fungsinya. Salut untuk penulisnya! Meskipun Anda dapat menggunakannya secara gratis, perlu diingat bahwa penerbitan ulang kode ini tunduk pada Tata Tertib kami.
Pernyataan Penyangkalan
Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.