OPEN-SOURCE SCRIPT

Rejection Blocks [UAlgo]

7 966
Rejection Blocks is a market structure and supply demand overlay built to detect and manage rejection based zones that form after liquidity sweeps and structure shifts. The script tracks recent swing highs and swing lows, monitors for sweep style rejection candles around those swing levels, and then requires a confirmation break before registering a Rejection Block as an active zone.

Each Rejection Block is visualized as an outer zone plus internal buy and sell strength segments that act like a compact sentiment map. The blocks extend forward over time, respond to mitigation and invalidation rules, and can optionally stop extending or be deleted after mitigation. The script also optionally draws structure annotations such as sweep markers and BOS or CHOCH lines to provide context for why a block formed.

This indicator is designed as a complete zone lifecycle engine. It focuses on repeatable rule based detection, strict candle shape filtering for rejection quality, and robust object management so you can keep a clean chart while tracking the most relevant zones.

🔹 Features

1) Pivot Based Market Structure Tracking
The engine uses pivot highs and pivot lows to identify the most recent swing high and swing low levels. These levels act as the structure references for:

Sweep detection
Break of structure detection
Change of character detection

Swing left bars and swing right bars control how strict the swing confirmation is.

2) Rejection Candle Validation with Sweep Logic
A candidate Rejection Block begins with a sweep style candle at a swing level:

Bullish rejection candle sweeps below the last swing low and closes back above it
Bearish rejection candle sweeps above the last swing high and closes back below it

Two sweep modes are available:

Wick sweep (open and close inside)
Any sweep (close inside)

Min sweep distance in ticks can be required to avoid tiny micro sweeps.

3) Optional Candle Shape Filter for Quality Control
When enabled, the script enforces a strict rejection candle profile using:

Minimum wick to body ratio
Minimum dominant wick percent of candle range
Maximum opposite wick percent of candle range
Maximum body percent of candle range

This helps filter out candles that technically sweep but do not display rejection characteristics.

4) Close Location Filters
Additional close filters can be applied:

None
Close in favorable half of the candle range
Close beyond open

This improves selectivity and allows you to tailor the definition of rejection strength.

5) Flexible Rejection Block Zone Models
The zone that is stored and drawn for a Rejection Block can be defined in multiple ways:

Wick to Body
Open to Extreme
Full Candle
Body

This allows alignment with different trading methodologies, from wick based reaction zones to body based execution zones.

6) Confirmation Window and Pending Candidates
Rejection candles do not become active zones immediately. They enter a pending list and require confirmation within a defined window. Confirmation is achieved when price breaks the opposite structure level:

Bullish candidate confirms when price breaks above the last swing high
Bearish candidate confirms when price breaks below the last swing low

If confirmation does not occur within the confirm window, the candidate expires. This prevents old sweeps from creating late zones.

7) Strength Segmentation Inside the Block
Each active block contains:

An outer zone box representing the full block range
An inner buy strength box
An inner sell strength box
A cap line that marks the maximum inner width boundary

Strength is estimated at formation time using one of two models:

Close location
Close plus wick

Inner widths scale based on the computed buy and sell strengths, giving a quick visual of where pressure likely dominated inside the rejection candle.

8) Lifecycle Management: Extension, Mitigation, Invalidation, Aging
Blocks are actively managed through their lifecycle:

Extension
Blocks extend to the right as time progresses.

Mitigation
Blocks can be marked mitigated by touch or by close inside. After mitigation, the block can optionally stop extending or be deleted.

Invalidation
Blocks can be invalidated by wick or by close beyond the block boundary, with optional deletion on invalidation.

Aging
Blocks can be removed after a maximum age in bars to keep the chart focused.

9) Structure Annotations: Sweep, BOS, CHOCH
When enabled, the script draws contextual structure lines and labels:

SW lines indicating swing sweep context
BOS lines for continuation breaks
CH lines for change of character

A maximum line budget is enforced to respect object limits.

10) Robust Object Budgeting and Cleanup
The engine enforces limits for:

Maximum blocks
Maximum pending candidates
Maximum structure lines

Old objects are deleted in a controlled way to avoid exceeding TradingView limits and to keep the most relevant zones visible.

🔹 Calculations

1) Candle Parts and Rejection Shape Metrics
The script breaks each candle into components:

Range
Body size
Upper wick
Lower wick

It then normalizes values by range and uses them for shape validation:

Dominant wick is lower wick for bullish direction and upper wick for bearish direction
Opposite wick is the other side
Body percent is body divided by range

A rejection candle passes shape checks when dominant wick is large enough relative to body, dominant wick percent exceeds a threshold, opposite wick percent stays below a threshold, and body percent stays below a threshold.

2) Sweep Validation Against Structure Level
For bullish direction, sweep requires low to trade below the swing level by a tick margin and close to finish back above the level. For bearish direction, sweep requires high to trade above the swing level by a tick margin and close to finish back below the level.

Min sweep ticks sets the margin:

sweepMargin equals minSweepTicks multiplied by mintick

The wick sweep mode further requires open to remain inside the level on the correct side.

3) Zone Derivation Models
Zone bounds are determined from candle anatomy based on the selected RB zone model.

Wick to Body:

Bullish zone from body bottom to low
Bearish zone from high to body top

Open to Extreme:

Bullish zone from open to low
Bearish zone from high to open

Full candle:

High to low

Body:

Body top to body bottom

These bounds become the candidate block top and bottom.

4) Strength Estimation
Base strength uses close location within the candle range:

closeLoc equals clamp of (close minus low) divided by range

Buy strength equals closeLoc
Sell strength equals 1 minus buy strength

If Close plus wick is selected, dominant wick contribution is blended into the buy strength calculation using fixed weights. Strength is an approximation and is fixed at formation time.

5) Market Structure Break Detection and Trend State
The engine tracks last swing high and last swing low timestamps and prices. It then detects breaks using cross style conditions:

Bull break when close crosses above last swing high
Bear break when close crosses below last swing low

Trend direction is updated on confirmed bars after a break is detected. The engine also tracks the last broken swing timestamp to avoid duplicate structure events on the same swing.

BOS and CHOCH are derived by comparing the new break direction to the previous trend direction.

6) Candidate Creation and Pending Queue
On confirmed bars, if a rejection candle occurs at the relevant swing level, a Candidate is created with:

Formation time
Zone top and bottom
Direction
Buy and sell strength
Confirmation level which is the opposite swing level

Candidates are pushed into a pending array which is capped by max pending.

7) Candidate Confirmation Within a Window
Each pending candidate is evaluated until it either expires or confirms:

Expired when time since candidate leftT reaches confirmWindow in bars
Confirmed when price breaks the candidate confirmLevel in the direction required for structure confirmation

Confirmed candidates are converted into Blocks and added to the active blocks array.

8) Block Construction and Visual Geometry
When a block is created, the script draws:

Outer box covering the full block range
Inner buy and sell boxes split at the zone midpoint
Cap line placed at a maximum percentage of the outer width

Inner widths are scaled using the block strengths and innerMaxPctOfOuter. A minimum inner width in bars is enforced.

9) Mitigation Detection
Mitigation is detected using one of two modes:

Touch mode: high low intersects the block range
Close Inside mode: close is inside the block range

After mitigation, the block can change visual styling, optionally stop extending, and optionally be deleted.

10) Invalidation Detection
Invalidation is evaluated when enabled:

For bullish blocks, invalidation occurs if price goes below the bottom
For bearish blocks, invalidation occurs if price goes above the top

This can be evaluated by wick or close depending on invalidation mode. Invalidated blocks can be visually marked and optionally deleted.

11) Aging and Cleanup
If max age bars is set, blocks older than that age are removed. Limits on blocks and structure lines are enforced with controlled deletion to respect platform constraints.

12) Visibility Filters
Blocks are shown or hidden based on direction toggles:

Show bullish blocks
Show bearish blocks

Structure lines are also gated by a separate toggle and a maximum line budget.

כתב ויתור

המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.