OPEN-SOURCE SCRIPT
מעודכן

Unicorn Model Detector [AGPro Series]

2 015
Unicorn Model Detector [AGPro Series]

Overview
The Unicorn Model Detector identifies one of the most discussed setups in Inner Circle Trader (ICT) and Smart Money Concepts literature: the Unicorn Model. A Unicorn forms when a Breaker Block and a Fair Value Gap (FVG) overlap inside the same price zone — a pocket where prior swing liquidity has been swept and an unfilled imbalance still exists at the retest. The detector scans for these overlaps, tracks every occurrence through its full lifecycle, and reports aggregate statistics in a compact on-chart panel. It is a detection and bookkeeping tool, not a trading strategy.

Unique Edge
Most breaker and FVG scripts publish either zones in isolation or require the user to eyeball the overlap. This detector does the overlap match automatically and only draws a zone when both conditions are present on the same chart area with the same directional bias. A strict causality rule is enforced — the Breaker must form first (after liquidity sweep) and the FVG must appear during or after the retest, which matches the true ICT Unicorn definition. A pairing that consumes a given breaker and FVG is removed from future candidate pools, so the chart never stacks redundant zones from the same source structure. A Loose overlap mode is also provided for users who prefer an ATR-based proximity interpretation instead of strict geometric intersection.

Methodology
1. Swing pivots are detected with a configurable left/right length using ta.pivothigh and ta.pivotlow.
2. When a confirmed pivot forms, the body range of the pivot bar is stored as the potential Breaker source zone.
3. A Breaker Block is registered when price closes through the previous-bar swing level in the opposite direction.
4. A Fair Value Gap is registered when a 3-bar formation produces an unfilled imbalance (low > high[2] for bullish, high < low[2] for bearish) and the gap exceeds a user-defined ATR multiple.
5. A Unicorn is spawned when a same-direction Breaker zone and FVG zone overlap vertically AND the FVG formed at or after the Breaker (causality check).
6. A configurable cooldown prevents consecutive spawns from clustering, improving signal hygiene.
7. The overlap rectangle becomes the tracked zone. Zone mid is the reference entry, the stop is placed 0.4 times the zone height beyond the structure boundary, and the target is projected at the user-defined R-multiple.

Signals & Alerts
Four independent alert conditions are exposed:
- New Unicorn Detected — a fresh bullish or bearish Unicorn has just formed.
- Unicorn Triggered — price has entered the overlap zone of a pending Unicorn.
- Target Hit — a triggered Unicorn has reached its R-multiple target.
- Stop Hit — a triggered Unicorn has been invalidated at its stop level.

All alerts fire once per bar close and include the ticker and timeframe in the payload.

Key Inputs
- Swing Pivot Length (default 7) — left/right length used for pivot confirmation.
- Breaker Lookback (default 80 bars) — maximum age for a broken swing to remain a valid Breaker.
- FVG Minimum Size (default 0.25 x ATR) — noise filter for 3-bar imbalances.
- Overlap Mode (Strict / Loose) — geometric intersection vs ATR-tolerance match.
- Reward-to-Risk Target (default 2.0) — multiple used to project the target level.
- Max Active Pending Unicorns (default 3) — chart-cleanliness cap.
- Cooldown After Signal (default 30 bars) — minimum spacing between consecutive spawns.
- Invalidate on Close Through Zone (default off) — optional tighter invalidation rule.
- Visual controls — show/hide per lifecycle state, label size, zone opacity, max recent labels.
- Panel controls — show/hide, location (6 positions), theme (Dark/Light), text size.

How to Use
1. Add the indicator to any timeframe; higher timeframes (1H, 4H, 1D) tend to produce structurally more meaningful Unicorns.
2. Watch for a new Unicorn zone to appear. Pending zones are drawn in the directional state color with a bold border; triggered ones switch to the indigo accent color; TP / SL / Expired zones fade to their respective colors with a thinner border.
3. Each zone carries a tethered flag label outside the price axis — Bullish labels below, Bearish labels above — so they never overlap candles.
4. The panel reports running counts of pending and active Unicorns, historical win rate, average R per setup, and total completed.
5. Use the displayed entry / target / stop reference lines as a structural map for your own analysis. The tool does not place orders and does not recommend position sizing.
6. Combine with higher-timeframe bias (trend, session context, HTF structure) before acting on any zone.

Limitations & Transparency
- The detector is a structural scanner, not a forecasting engine. It reports what has formed, not what will happen.
- Swing detection depends on pivot length; shorter lengths generate more noise, longer lengths miss smaller structures.
- Statistics are calculated on-chart from historical bars loaded by TradingView and will vary with timeframe, symbol and data range.
- Realtime behaviour: zones are drawn on confirmed events (bar close for breaks, 3-bar-complete for FVGs). Some invalidations are evaluated intrabar on wick touches of the stop level.
- The script is open-source under Mozilla Public License 2.0. Users are encouraged to inspect and adapt the methodology.

Risk Disclosure
This indicator is provided for educational and analytical purposes only. It is not financial advice, a trading signal service, or a strategy. Past structural patterns do not guarantee future outcomes. Trading involves substantial risk of loss; readers are solely responsible for their own decisions and risk management.
הערות שחרור
UPDATE NOTES - V1.10

This update focuses on source cleanup, zone ownership, panel standardization, and chart readability.

The core purpose of the script remains unchanged.
This release improves how Unicorn Model overlap pockets are presented and interpreted on the chart.

This script continues to function as an analytical and visualization tool.
It does not attempt to predict price direction or provide guaranteed outcomes.


------------------------
What Changed
------------------------

* Removed the non-required legal block from the source header.
The script now follows the current AGPro public-free source format without an extra legal header.

* Preserved the original Unicorn engine.
Swing pivots, Breaker Block detection, Fair Value Gap detection, same-bias overlap logic, strict/loose overlap mode, pending/triggered/TP/SL lifecycle, target projection, stop logic, statistics, and alerts remain intact.

* Added centered zone badges.
Visible Unicorn pockets can now display a separate centered badge inside the overlap zone.

* Added badge controls.
Show Centered Zone Badges and Show Badge State were added so the pocket can clearly communicate Bull/Bear Unicorn ownership and lifecycle state.

* Expanded font-size support.
Label and panel font controls now include Huge.


------------------------
Visual Improvements
------------------------

* Unicorn zones now read as owned confluence pockets instead of generic rectangles.

* Centered badges use a two-line format such as BULL UNICORN / POCKET | Pending.

* Outside labels and leader lines remain available for lifecycle context.

* Live and completed zones keep clear color-state behavior.


------------------------
Interface & Usability
------------------------

* Expanded panel themes to Elite Dark, Slate, and Clean Light.

* Expanded panel locations to include top, middle, and bottom center positions.

* Added live panel repositioning through table.set_position.

* Panel header now follows the AGPro render order: table.clear -> table.merge_cells -> header.

* Panel header remains a single merged blue row with only the script name.


------------------------
Behavior Notes
------------------------

This update does not change the core analytical logic of the script.

Breaker detection, FVG detection, overlap pairing, lifecycle states, targets, stops, statistics, and alerts should be interpreted the same way as before.

The goal is to improve clarity and usability, not to introduce new predictive behavior.


------------------------
Limitations Reminder
------------------------

The script remains a rule-based analytical tool.

Market conditions such as volatility, liquidity, timeframe differences, and pivot sensitivity may affect Unicorn Model detection and lifecycle outcomes.

Outputs should always be interpreted within broader market context.


------------------------
Risk Reminder
------------------------

This script is for educational and analytical purposes only.

It does not provide financial advice or guaranteed trading outcomes.

Users remain responsible for their own decisions.
הערות שחרור
🔧 UPDATE NOTES - 2.0

This update turns the Unicorn Model Detector into a decision-focused planner,
improving how each confluence pocket is scored, presented and interpreted on
the chart. The core detection logic (Breaker Block + Fair Value Gap overlap)
remains unchanged. This script continues to function as an analytical and
visualization tool. It does not predict price direction or guarantee outcomes.

------------------------
What Changed
------------------------

- 0-100 Readiness Score
Every pocket is now scored on overlap depth, FVG strength, freshness, price
proximity and trigger state, so quality is visible at a glance.

- Next-Action State
A clear Action readout (Stand Aside, Monitor, Prepare, Arm Entry, Manage Active)
summarizes what the current primary setup suggests.

- Decision Panel
The panel now shows readiness, action, setup, entry, stop, target, R:R, win rate
with sample size, and average R in one structured readout.

- Stricter Proof Layer
Statistics are confirmed-bar gated, same-bar target/stop ambiguity resolves
conservatively as a loss, and a new Confirm Window excludes pockets that take
too long to resolve, preventing inflated win-rate figures.

------------------------
Visual Improvements
------------------------

- Removed duplicate outside labels; each pocket now uses a single centered badge
- Faded completed pockets so the active setup stands out clearly
- Entry / target / stop lines and price tags are now focused on the primary setup
- Centered badges display the live readiness score directly inside the pocket

------------------------
Interface & Usability
------------------------

- Reorganized panel for a clearer, decision-first information flow
- Improved badge readability on light and dark chart backgrounds
- Adjusted default visuals for a cleaner, less cluttered first-glance read
- Enhanced overall experience without changing the core detection logic

------------------------
Behavior Notes
------------------------

This update does not change how Unicorn pockets are detected. The goal is to
improve clarity, structure and usability. Outputs should be interpreted the same
way as before, now with added readiness context.

------------------------
Limitations Reminder
------------------------

The script remains a rule-based analytical tool. Volatility, liquidity and
timeframe differences can affect how pockets and statistics appear. Always
interpret outputs within broader market context.

------------------------
Risk Reminder
------------------------

This script is for educational and analytical purposes only. It does not provide
financial advice or guaranteed trading outcomes. Users remain responsible for
their own decisions.

כתב ויתור

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