OPEN-SOURCE SCRIPT
ICT Unicorn Model [Kodexius]

ICT Unicorn Model is a market structure and imbalance confluence tool that automatically detects high probability “Unicorn” setups by combining three key elements into a single, clean script:
-A first, clean break of that swing level (displacement style break)
-A Fair Value Gap that overlaps a breaker candle body range
Instead of plotting every pivot or every imbalance independently, the script waits for a specific sequence: price establishes a valid swing, breaks that swing for the first time, and prints a setup only when the resulting context aligns with a valid, volatility filtered FVG and a clearly defined breaker range.
Each detected setup is drawn directly on the chart with labeled zones (Breaker and FVG) and is then actively monitored. If price violates the breaker boundary based on your chosen invalidation basis (Close or Wick), the setup is marked inactive and can optionally be removed to keep the chart clean.
This indicator is designed for traders who work with ICT style concepts such as liquidity runs, displacement, breaker blocks, and imbalance reversion, and who want a structured, rules based visualization rather than discretionary drawing.

🔹 Features
🔸 Fair Value Gap Detection With Volatility Filtering
Bullish and bearish FVGs are detected using classic three candle imbalance logic. To avoid low quality gaps during compression, the script applies an ATR based minimum size filter using the “FVG Min Size (ATR Multiplier)” input. Only gaps larger than ATR * threshold are considered valid.
🔸 First Break Validation (Clean Break Logic)
A key part of the model is identifying a “first break” of a swing level. The script checks whether the swing price has already been invalidated between the swing bar and the current bar. If it has, the swing is ignored. This helps reduce repeated signals and focuses on fresh structural breaks.
🔸 Breaker and FVG Confluence With Overlap Requirement
After a valid break occurs, the script defines a breaker range using the body of the swing candle (open and close). A setup is only created if this breaker body range overlaps the detected FVG price range. This overlap requirement is what filters many “almost” conditions and keeps signals more selective.
Bullish Unicorn:

Bearish Unicorn:

🔸 Configurable Invalidation Basis (Close or Wick)
You can choose how a setup fails:
-Close: invalidation requires a candle close beyond the breaker boundary
-Wick: invalidation occurs as soon as any wick crosses beyond the breaker boundary
This allows the tool to adapt to different trading styles, from conservative confirmation to more sensitive risk control.
🔸 Automatic Cleanup of Failed Setups
If “Delete Invalidated Setups” is enabled, the script removes the breaker box, FVG box, and label as soon as the setup is invalidated. If disabled, the zones remain visible for review while the setup is marked inactive internally.
🔸 Clear Chart Visuals
Each setup plots:
-A labeled Breaker zone box
-A labeled FVG zone box
-A directional Unicorn label (Bull or Bear) that updates position as the chart advances
Colors for bullish and bearish structures are fully configurable.
🔸 Alert Conditions
Two alert conditions are provided:
-Bullish Unicorn Setup Detected
-Bearish Unicorn Setup Detected
Alerts trigger only on the bar a new setup is created.
🔹 Calculations
This section summarizes the main computations used internally. The goal here is to explain the model mechanics rather than reproduce every implementation detail.
1. Swing Detection (Pivot High / Pivot Low)
Swing levels are detected using a symmetric pivot definition with “Swing Length” bars on both sides:
Pine Script®
When a pivot is confirmed, its price and originating bar index are stored:
-Swing High: price = pivot high, isHigh = true
-Swing Low: price = pivot low, isHigh = false
The script keeps a limited history (most recent swings) to stay efficient.
2. Fair Value Gap Detection
FVGs use the classic three candle displacement imbalance:
Bullish FVG condition
Pine Script®
Bullish gap range is defined as:
-Top = low[0]
-Bottom = high[2]
Bearish FVG condition
Pine Script®
Bearish gap range is defined as:
-Top = low[2]
-Bottom = high[0]
3. ATR Based Minimum Gap Filter
ATR is computed (length 14), then the gap size is compared against a user threshold:
Pine Script®
This prevents very small imbalances from generating setups in low volatility conditions.
4. “First Break” Check Using Level Invalidation Scan
Before accepting a swing break, the script scans forward from the swing bar to the current bar to confirm the level has not already been breached. The scan can be based on wick or close:
-Wick mode: uses high or low
-Close mode: uses close
Conceptually:
Pine Script®
If a prior breach is found, the swing is treated as already invalidated and is ignored for setup creation.
5. Break Of Structure Condition
Bullish break requirement
A bullish setup requires breaking a stored swing high with bullish body intent:
-close > swingHighPrice
-open < close
Bearish break requirement
A bearish setup requires breaking a stored swing low with bearish body intent:
-close < swingLowPrice
-open > close
An additional proximity filter is applied in the bearish branch to reduce weak or overly extended breaks by requiring the prior close to be reasonably near the swing level.
6. Breaker Range Construction
Once a qualifying swing is found, the breaker range is derived from the body of the swing candle (the candle at the swing bar index). The body boundaries are:
Pine Script®
This models the breaker as the candle body range rather than full wick range, which typically produces more practical invalidation boundaries.
7. Overlap Test Between Breaker and FVG
A setup is only created if the breaker body overlaps the FVG zone. Conceptually the script rejects cases where one range is fully above or fully below the other:
-If there is no overlap, no setup is created
-If overlap exists, the Unicorn setup is valid
8. Active Monitoring and Invalidation
Each setup remains active until invalidated. Invalidation is evaluated every bar using your selected basis:
-Close basis: compares close to breaker boundary
-Wick basis: compares high or low to breaker boundary
Bullish invalidation
Setup fails if price crosses below breaker bottom.
Bearish invalidation
Setup fails if price crosses above breaker top.
If deletion is enabled, all drawings related to that setup are removed immediately on invalidation.
9. Drawing Updates and Object Lifecycle
Breaker and FVG boxes are extended to the right while the setup is active to keep zones visible into the near future. The Unicorn label is also repositioned as new bars print so the most recent context stays readable.


-A first, clean break of that swing level (displacement style break)
-A Fair Value Gap that overlaps a breaker candle body range
Instead of plotting every pivot or every imbalance independently, the script waits for a specific sequence: price establishes a valid swing, breaks that swing for the first time, and prints a setup only when the resulting context aligns with a valid, volatility filtered FVG and a clearly defined breaker range.
Each detected setup is drawn directly on the chart with labeled zones (Breaker and FVG) and is then actively monitored. If price violates the breaker boundary based on your chosen invalidation basis (Close or Wick), the setup is marked inactive and can optionally be removed to keep the chart clean.
This indicator is designed for traders who work with ICT style concepts such as liquidity runs, displacement, breaker blocks, and imbalance reversion, and who want a structured, rules based visualization rather than discretionary drawing.
🔹 Features
🔸 Fair Value Gap Detection With Volatility Filtering
Bullish and bearish FVGs are detected using classic three candle imbalance logic. To avoid low quality gaps during compression, the script applies an ATR based minimum size filter using the “FVG Min Size (ATR Multiplier)” input. Only gaps larger than ATR * threshold are considered valid.
🔸 First Break Validation (Clean Break Logic)
A key part of the model is identifying a “first break” of a swing level. The script checks whether the swing price has already been invalidated between the swing bar and the current bar. If it has, the swing is ignored. This helps reduce repeated signals and focuses on fresh structural breaks.
🔸 Breaker and FVG Confluence With Overlap Requirement
After a valid break occurs, the script defines a breaker range using the body of the swing candle (open and close). A setup is only created if this breaker body range overlaps the detected FVG price range. This overlap requirement is what filters many “almost” conditions and keeps signals more selective.
Bullish Unicorn:
Bearish Unicorn:
🔸 Configurable Invalidation Basis (Close or Wick)
You can choose how a setup fails:
-Close: invalidation requires a candle close beyond the breaker boundary
-Wick: invalidation occurs as soon as any wick crosses beyond the breaker boundary
This allows the tool to adapt to different trading styles, from conservative confirmation to more sensitive risk control.
🔸 Automatic Cleanup of Failed Setups
If “Delete Invalidated Setups” is enabled, the script removes the breaker box, FVG box, and label as soon as the setup is invalidated. If disabled, the zones remain visible for review while the setup is marked inactive internally.
🔸 Clear Chart Visuals
Each setup plots:
-A labeled Breaker zone box
-A labeled FVG zone box
-A directional Unicorn label (Bull or Bear) that updates position as the chart advances
Colors for bullish and bearish structures are fully configurable.
🔸 Alert Conditions
Two alert conditions are provided:
-Bullish Unicorn Setup Detected
-Bearish Unicorn Setup Detected
Alerts trigger only on the bar a new setup is created.
🔹 Calculations
This section summarizes the main computations used internally. The goal here is to explain the model mechanics rather than reproduce every implementation detail.
1. Swing Detection (Pivot High / Pivot Low)
Swing levels are detected using a symmetric pivot definition with “Swing Length” bars on both sides:
float ph = ta.pivothigh(high, swingLength, swingLength)
float pl = ta.pivotlow(low, swingLength, swingLength)
When a pivot is confirmed, its price and originating bar index are stored:
-Swing High: price = pivot high, isHigh = true
-Swing Low: price = pivot low, isHigh = false
The script keeps a limited history (most recent swings) to stay efficient.
2. Fair Value Gap Detection
FVGs use the classic three candle displacement imbalance:
Bullish FVG condition
bool isBullFVG = high[2] < low[0]
Bullish gap range is defined as:
-Top = low[0]
-Bottom = high[2]
Bearish FVG condition
bool isBearFVG = low[2] > high[0]
Bearish gap range is defined as:
-Top = low[2]
-Bottom = high[0]
3. ATR Based Minimum Gap Filter
ATR is computed (length 14), then the gap size is compared against a user threshold:
float atr = ta.atr(14)
bool validBullFVG = isBullFVG and (bullFvgTop - bullFvgBot) > (atr * fvgThreshold)
bool validBearFVG = isBearFVG and (bearFvgTop - bearFvgBot) > (atr * fvgThreshold)
This prevents very small imbalances from generating setups in low volatility conditions.
4. “First Break” Check Using Level Invalidation Scan
Before accepting a swing break, the script scans forward from the swing bar to the current bar to confirm the level has not already been breached. The scan can be based on wick or close:
-Wick mode: uses high or low
-Close mode: uses close
Conceptually:
priceToCheck = mode == "Wick" ? (checkBelow ? low : high) : close
If a prior breach is found, the swing is treated as already invalidated and is ignored for setup creation.
5. Break Of Structure Condition
Bullish break requirement
A bullish setup requires breaking a stored swing high with bullish body intent:
-close > swingHighPrice
-open < close
Bearish break requirement
A bearish setup requires breaking a stored swing low with bearish body intent:
-close < swingLowPrice
-open > close
An additional proximity filter is applied in the bearish branch to reduce weak or overly extended breaks by requiring the prior close to be reasonably near the swing level.
6. Breaker Range Construction
Once a qualifying swing is found, the breaker range is derived from the body of the swing candle (the candle at the swing bar index). The body boundaries are:
float breakerTop = math.max(bOpen, bClose)
float breakerBot = math.min(bOpen, bClose)
This models the breaker as the candle body range rather than full wick range, which typically produces more practical invalidation boundaries.
7. Overlap Test Between Breaker and FVG
A setup is only created if the breaker body overlaps the FVG zone. Conceptually the script rejects cases where one range is fully above or fully below the other:
-If there is no overlap, no setup is created
-If overlap exists, the Unicorn setup is valid
8. Active Monitoring and Invalidation
Each setup remains active until invalidated. Invalidation is evaluated every bar using your selected basis:
-Close basis: compares close to breaker boundary
-Wick basis: compares high or low to breaker boundary
Bullish invalidation
Setup fails if price crosses below breaker bottom.
Bearish invalidation
Setup fails if price crosses above breaker top.
If deletion is enabled, all drawings related to that setup are removed immediately on invalidation.
9. Drawing Updates and Object Lifecycle
Breaker and FVG boxes are extended to the right while the setup is active to keep zones visible into the near future. The Unicorn label is also repositioned as new bars print so the most recent context stays readable.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.