ICT Unicorn Model [UAlgo]ICT Unicorn Model is a chart overlay indicator that automates a practical interpretation of the ICT “Unicorn” concept by combining two core components: a Market Structure Shift style Breaker Block (BB) and a Fair Value Gap (FVG). The script first builds a rolling pivot map using configurable left and right pivot bars, then monitors those pivots for structure breaks that qualify as bullish or bearish breaker blocks. Separately, it detects 3 candle FVG imbalances with a minimum size filter. A Unicorn is confirmed when a newly printed FVG overlaps an active breaker block of the same direction.
The output is built for real trading workflows and chart readability. Breaker blocks and FVGs can exist independently, but when they align, the script highlights the overlap region as a Unicorn zone and labels it. All zones extend forward in time and are automatically removed when mitigation or invalidation conditions are met. Optional session filtering is included to restrict detection to a specific trading window for killzone style usage.
Educational tool only. Not financial advice.
🔹 Features
🔸 1) Pivot Based Structure Mapping
The indicator uses built-in pivot detection to create a reliable swing framework. Both pivot highs and pivot lows are stored as structured objects that keep track of pivot time, bar index, pivot price, pivot direction, and whether that pivot has already been “broken” to prevent repeated processing. This pivot map becomes the backbone of the breaker block engine, allowing the script to reference meaningful swing points instead of reacting to minor noise.
🔸 2) Breaker Block Detection via Market Structure Shift Logic
Breaker blocks are created when price breaks through an unbroken pivot in a way that signals a directional shift in structure.
Bullish Breaker Block: price closes above an unbroken pivot high, then the script validates the context by locating two pivot lows around that pivot high and requiring a lower low relationship between them (LL style confirmation in this implementation). Once confirmed, a bullish breaker block zone is stored using the pivot candle’s full range.
Bearish Breaker Block: price closes below an unbroken pivot low, then the script validates the context by locating two pivot highs around that pivot low and requiring a higher high relationship between them (HH style confirmation in this implementation). Once confirmed, a bearish breaker block zone is stored using the pivot candle’s full range.
🔸 3) Fair Value Gap Detection with Minimum Size Filter
The FVG engine detects classic 3 candle price imbalances:
Bullish FVG: current low is above high from two bars ago.
Bearish FVG: current high is below low from two bars ago.
A minimum FVG size filter is applied using raw price points so you can ignore tiny gaps that are usually filled immediately. This makes the script easier to adapt across different markets and timeframes.
🔸 4) Unicorn Confirmation via Directional Overlap
A Unicorn is confirmed only when a newly printed FVG overlaps an active breaker block and both are in the same direction. The overlap test is a standard price interval intersection check, and the direction match ensures bullish FVGs only confirm bullish unicorns and bearish FVGs only confirm bearish unicorns.
When a Unicorn is confirmed, the script draws a dedicated Unicorn zone covering the combined overlap footprint and prints a simple Bull or Bear label directly on the chart.
🔸 5) Optional Session Filter for Killzone Style Workflows
A session filter can restrict detection to a specific time window. If enabled, the script only runs breaker block detection, FVG detection, and Unicorn confirmation while the current bar is inside the selected session. This is useful when you only want signals during higher participation windows.
🔸 6) Automatic Forward Extension, Mitigation, and Cleanup
All zones behave as live objects:
Breaker block boxes extend forward until invalidation.
FVG boxes extend forward until mitigation.
Unicorn boxes extend forward until the associated FVG mitigation condition is met.
When a zone is mitigated or invalidated, its box and label objects are deleted and removed from internal arrays. This keeps the chart clean and prevents stale zones from accumulating.
🔸 7) Object and Memory Management for Chart Stability
The script uses arrays of custom types (Pivot, BreakerBlock, FVG, Unicorn) and enforces internal history limits to reduce clutter and object growth. Older items are shifted out when limits are exceeded, and graphical objects are deleted when no longer valid to maintain stable chart performance.
🔹 Calculations
1) Time Filter (Session Gate)
If the time filter is disabled, detection runs on every bar. If enabled, detection only runs when the chart time is inside the selected session.
in_session = not use_time_filter or time(timeframe.period, time_session) != 0
Interpretation:
If use_time_filter is false, in_session is always true.
If use_time_filter is true, time() returns non-zero only while the bar is inside the session.
2) Pivot Detection and Pivot Object Storage
Pivot highs and lows are detected using TradingView pivot functions with user-defined left and right bars. Pivots are confirmed after right_bars bars, so the stored pivot time and bar index are offset by right_bars to align the pivot to the originating candle.
ph = ta.pivothigh(high, left_bars, right_bars)
pl = ta.pivotlow(low, left_bars, right_bars)
When a pivot is found:
array.unshift(pivots, Pivot.new(time , bar_index , ph, true, false, high , low ))
The pivot list is capped to keep the script lightweight:
if array.size(pivots) > 20
array.pop(pivots)
3) Bullish Breaker Block Detection
A bullish breaker is triggered when price closes above an unbroken pivot high. The script then searches for pivot lows around that pivot high and requires a lower low relationship between them. If this context check passes, the pivot is marked as broken and a bullish breaker block is stored.
if p.isHigh and not p.isBroken and close > p.price
...
if foundLL
p.isBroken := true
array.push(active_bbs, BreakerBlock.new(p.time, p.index, p.highPrice, p.lowPrice, true, true, na))
Breaker block zone definition is derived from the pivot candle:
Top = pivot candle high
Bottom = pivot candle low
4) Bearish Breaker Block Detection
A bearish breaker is triggered when price closes below an unbroken pivot low. The script then searches for pivot highs around that pivot low and requires a higher high relationship between them. If this context check passes, the pivot is marked as broken and a bearish breaker block is stored.
if not p.isHigh and not p.isBroken and close < p.price
...
if foundHH
p.isBroken := true
array.push(active_bbs, BreakerBlock.new(p.time, p.index, p.highPrice, p.lowPrice, false, true, na))
5) Fair Value Gap Detection and Sizing
Bullish FVG requires current low to be above high .
Bearish FVG requires current high to be below low .
A minimum size filter is applied in points:
bool isBullishFVG = low > high and (low - high ) >= fvg_min_volume
bool isBearishFVG = high < low and (low - high) >= fvg_min_volume
FVGs are stored with their start anchored to bar_index and time , matching the gap’s originating structure:
if isBullishFVG
array.push(active_fvgs, FVG.new(time , bar_index , low, high , true, false, na))
if isBearishFVG
array.push(active_fvgs, FVG.new(time , bar_index , low , high, false, false, na))
6) Overlap Rule for Unicorn Confirmation
A Unicorn requires overlap plus direction agreement. The overlap is calculated as an interval intersection:
method overlaps(BreakerBlock this, FVG fvg) =>
bool isOverlapping = (fvg.bottom <= this.top) and (fvg.top >= this.bottom)
isOverlapping and (this.isBullish == fvg.isBullish)
Interpretation:
The FVG range must intersect the breaker block range, and both must be bullish or both bearish.
7) Unicorn Zone Construction
When a new FVG prints, the script compares it against all active breaker blocks. If an overlap is found, it creates a Unicorn zone and a Bull or Bear label. The Unicorn box boundaries are computed using min and max edges between the BB and FVG:
float topEdge = math.min(bb.top, latestFVG.top)
float bottomEdge = math.max(bb.bottom, latestFVG.bottom)
The Unicorn zone is then drawn and extended forward.
8) Mitigation and Invalidation Logic
Breaker Block invalidation
Bullish BB invalidates if close goes below BB bottom.
Bearish BB invalidates if close goes above BB top.
if (bb.isBullish and close < bb.bottom) or (not bb.isBullish and close > bb.top)
bb.isActive := false
if not na(bb.bbBox)
box.delete(bb.bbBox)
array.remove(active_bbs, i)
FVG mitigation
Bullish FVG mitigates if close goes below FVG bottom.
Bearish FVG mitigates if close goes above FVG top.
if (fvg.isBullish and close < fvg.bottom) or (not fvg.isBullish and close > fvg.top)
fvg.isMitigated := true
if not na(fvg.fvgBox)
box.delete(fvg.fvgBox)
array.remove(active_fvgs, i)
Unicorn mitigation
Unicorn zones are removed when the associated FVG mitigation condition is met:
bool isMitigated = (uni.isBullish and close < uni.fvg.bottom) or (not uni.isBullish and close > uni.fvg.top)
if isMitigated
box.delete(uni.uniBox)
label.delete(uni.uniLabel)
array.remove(unicorns, i)
9) Forward Extension and Internal Limits
Boxes are extended on each bar by updating right = bar_index + 5 to keep them projected slightly forward. Arrays are capped to control history size and object usage:
if array.size(active_bbs) > 50
array.shift(active_bbs)
if array.size(active_fvgs) > 50
array.shift(active_fvgs)
if array.size(unicorns) > 50
array.shift(unicorns)
Pine Script® インジケーター






















