OPEN-SOURCE SCRIPT

SMC Flip Zone Engine Viprasol

4 457
Overview

The original detects a break of structure, walks back to find the reaction leg that preceded it, and draws a colored zone box, with optional Liquidity Sweep, Fair Value Gap, HTF EMA alignment, and OTE (discount/premium) filters that can be toggled on to reduce noise. This version keeps that zone-detection engine intact and adds a Viprasol confluence and lifecycle layer: a 0-4 confluence score with A/B/C grading, a minimum-score gate, zone mitigation (retest) and invalidation tracking, a per-side cooldown, and an ATR-free risk overlay that projects Entry/SL/TP from a zone when price returns to it.

It is built for traders who work with break-of-structure flip zones and want each zone graded by how much SMC confluence actually backs it, plus automatic tracking of when zones are retested or broken.

How It Works

Structure Break & Reaction Leg (from original):
A bullish flip is triggered when close crosses over the prior highest-high of the lookback window (supply broken); a bearish flip when close crosses under the prior lowest-low (demand broken). On a break, the script walks back over the reaction-leg length to find the extreme of the trap leg — for a bull flip, the lowest low in that window and its bar's high define the zone's bottom and top. A box is drawn from that reaction bar forward.

SMC Filters (from original, toggle-gated):
Four optional filters can each be required before a zone is drawn:
- Liquidity Sweep — the reaction leg must have exceeded the prior structural extreme (taken liquidity).
- FVG / Displacement — a fair value gap must be present around the break (e.g. low > high[2]).
- HTF Alignment — bull zones only above, bear zones only below, the 50 EMA of a higher timeframe.
- OTE (Discount/Premium) — the zone midpoint must sit in the discount half (bull) or premium half (bear) of the leg, where equilibrium = leg low + (leg high − leg low) × 0.5.

Confluence Score & Grade (new):
Independently of which filters are toggled on, the script evaluates all four confluence conditions as raw booleans on every new zone and sums them into a 0-4 score:
score = sweep? + fvg? + ote? + htfAligned?
The score is mapped to a grade — A (>= 3), B (= 2), C (<= 1) — and printed on the zone box. This means even with all filters off (so every break draws a zone), you can still see which zones are backed by genuine confluence. A "Minimum Confluence Score" input then lets you suppress any zone below a chosen score without having to hard-require specific filters.

Zone Mitigation & Invalidation (new):
Every existing zone is tracked across bars. A zone is mitigated the first time price trades back into its range (low <= top and high >= bot) — this fires a mitigation alert (a potential entry as the flip zone is retested). A zone is invalidated when price closes through it (close < bot for a bull zone, close > top for a bear zone); invalidated zones are recolored gray (or can be left as-is) and fire an invalidation alert. Each transition fires once per zone.

Risk Overlay on Mitigation (new):
When "Show SL/TP on Mitigation" is enabled, the first retest of a zone projects three lines: Entry at the near edge of the zone, Stop-Loss at the far edge (so the zone height is the risk), and Take-Profit at Entry ± zone-height × the Risk:Reward ratio. Colored ENTRY/SL/TP price labels mark the line ends. Only the most recent mitigation's projection is kept, to avoid clutter.

Per-Side Cooldown (new):
An optional cooldown enforces a minimum number of bars between new zones on the same side (tracked as bar_index − lastSideBar >= cooldown), preventing a burst of overlapping zones during a single fast move.

What Is Original (Viprasol Additions)

1. Confluence score (0-4) and A/B/C grade printed on each zone, computed from raw sweep/FVG/OTE/HTF conditions regardless of which filters are toggled.
2. Minimum-confluence-score gate — suppress low-quality zones without hard-requiring individual filters.
3. Zone mitigation (retest) detection with a dedicated alert.
4. Zone invalidation detection (price closes through) with recoloring and a dedicated alert.
5. Risk overlay — Entry/SL/TP projection with colored price labels drawn on the first mitigation of a zone, sized by zone height and the Risk:Reward ratio.
6. Per-side zone cooldown to prevent clustering.

Key Features

From the Original:
- Break-of-structure detection via crossover/crossunder of the lookback high/low
- Reaction-leg walk-back to locate the trap zone behind the break
- Bullish and bearish flip-zone boxes with labels
- Optional Liquidity Sweep, FVG, HTF 50-EMA alignment, and OTE filters
- Oldest-zone pruning to limit chart clutter

Added in This Version (Viprasol):
- 0-4 confluence score with A/B/C grade on every zone
- Minimum-score quality gate
- Mitigation (retest) and invalidation lifecycle tracking with recoloring
- Entry/SL/TP risk overlay with colored price labels on mitigation
- Per-side cooldown
- Info dashboard (active zone counts, HTF state, filters-on count, min score)
- Six alert conditions with dynamic {{ticker}}/{{close}}/{{interval}} messages

How to Use

Getting Started:
1. Add to a standard candlestick chart (not Heikin Ashi).
2. With all filters off (default), every structure break draws a graded zone — read the A/B/C grade to judge quality.
3. To trade only stronger setups, either raise "Minimum Confluence Score" or turn on the specific filters you require.

Reading the Chart:
- Green zone = bullish flip (drawn after a supply break); red zone = bearish flip (after a demand break).
- The bracket on each zone, e.g. [A 3/4], is the confluence grade and score.
- A zone turning gray means price closed through it — it is invalidated.
- When price returns into a zone and SL/TP is enabled, Entry/SL/TP lines and price labels project to the right.

Recommended Starting Points:
- Intraday (5m-15m): Lookback 20, Reaction 7, Min Score 0-1, Cooldown 0-3
- Swing (1H-4H): Lookback 30, Reaction 7-10, Min Score 2, enable HTF alignment
- Higher conviction: Min Score 3 (grade A only), or require Sweep + FVG

These are starting points only — every market and timeframe behaves differently. Backtest and adjust before trading live.

Settings

Market Structure: structure lookback period, reaction-leg length, and max zones kept per side.

SMC Strict Filters: toggles for Liquidity Sweep, FVG (displacement), HTF 50-EMA alignment (with HTF resolution), and OTE (discount/premium). All default off so zones appear immediately.

Confluence & Quality (Viprasol): minimum confluence score, show grade on zone, and per-side zone cooldown.

Risk Overlay (Viprasol): show SL/TP on mitigation, show price labels, and the Risk:Reward ratio.

Visuals: bullish/bearish fill and border colors, and a toggle to dim invalidated zones gray.

Dashboard / Display: dashboard toggle and position.

Alerts

1. New Bull Zone — a bullish flip zone was created
2. New Bear Zone — a bearish flip zone was created
3. Any New Zone — either direction created
4. Bull Mitigation — price returned to a bullish zone (potential long)
5. Bear Mitigation — price returned to a bearish zone (potential short)
6. Zone Invalidated — a zone was closed through and invalidated

All alerts include {{ticker}}, {{close}}, and {{interval}} for dynamic notification messages.

Limitations & Disclaimer

- Zones are created on the bar the structure break confirms; because detection uses crossover/crossunder of close versus the prior swing, signals are evaluated on the closing relationship and the reaction leg is identified after the fact.
- The HTF alignment filter uses request.security with lookahead disabled; HTF values update only as the higher-timeframe bar progresses.
- The FVG and OTE checks are simplified single-bar/leg-midpoint approximations, not full multi-leg ICT constructs.
- Mitigation is detected on the first wick back into a zone; this is an awareness signal, not a guaranteed reversal.
- SL/TP lines and price labels are visual references only and do not place or manage trades.
- Filters and the minimum-score gate reduce the number of zones; in choppy ranges valid zones may be suppressed, while in fast trends overlapping zones may appear if cooldown is off.
- Past performance does not guarantee future results. This indicator is for educational and analytical purposes only and is not financial advice. Always use proper risk management and test on historical data before trading live.

Credits & Attribution

Based on an open-source "Advanced SMC Flip Zones" community indicator, which provided the break-of-structure detection (crossover/crossunder of the lookback high/low), the reaction-leg walk-back that locates the trap zone, the bullish and bearish flip-zone boxes, the optional Liquidity Sweep / FVG / HTF 50-EMA / OTE filters, and the oldest-zone pruning. Added by Viprasol: the 0-4 confluence score and A/B/C grading, the minimum-score quality gate, zone mitigation and invalidation lifecycle tracking with recoloring, the Entry/SL/TP risk overlay with colored price labels, the per-side cooldown, the info dashboard, and the six-condition dynamic alert set.

Published open-source per TradingView House Rules.

Haftungsausschluss

Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.