OPEN-SOURCE SCRIPT
Order Blocks & Imbalance

This indicator automatically identifies and plots Order Blocks (also known as Fair Value Gaps or Imbalances) based on Smart Money Concepts (SMC) and ICT methodology. It detects significant price inefficiencies (gaps between candles) that often act as institutional supply or demand zones.
How It Works (Technical Methodology)
1. Fair Value Gap (FVG) Detection
The indicator identifies classic 3-candle imbalances:
- Bullish Order Block (Demand): When the low of the current candle is significantly below the high of the candle two bars ago (low[0] - high[2]).
- Bearish Order Block (Supply): When the high of the current candle is significantly above the low of the candle two bars ago (low[2] - high[0]).
A minimum size threshold is enforced using ATR(14) × user-defined multiplier (default 0.5) to filter out minor gaps and focus on meaningful inefficiencies.
2. Zone Creation
- Bullish zones are created at the candle two bars ago (the "origin" candle where inefficiency occurred).
- Bearish zones use the same origin candle.
- Zone boundaries:
Top = high of origin candle
Bottom = low of origin candle
This captures the full range where price moved aggressively, leaving an imbalance that institutions may later revisit.
3. Mitigation Detection
Zones can be mitigated in two ways (user-selectable):
- "Close": Zone is considered touched only if the close price enters the zone.
- "Wick": Zone is touched if any wick (high/low) enters the zone (more sensitive).
When mitigated:
- Background becomes more transparent
- Border turns dotted
- Label changes to "Mitigated"
Broken zones (price fully closes beyond the opposite side) are automatically deleted.
4. Zone Lifecycle Management
- Active Zone: Strong color fill (green for demand, red for supply) with solid border.
- Mitigated Zone: Faded color, dotted border – indicates partial fill or reduced strength.
- Broken Zone: Automatically removed from chart to reduce clutter.
Old zones are also pruned when exceeding 450 total to maintain performance.
5. Smart Visibility Engine (Optional)
When enabled:
- All zones are initially hidden.
- Only the closest relevant zones are shown:
- Up to user-defined limit (default 10) highest bullish zones (closest below price)
- Up to user-defined limit (default 10) lowest bearish zones (closest above price)
- Visible zones are automatically extended to the right and styled appropriately.
This keeps the chart clean while highlighting the most actionable zones near current price.
6. Visual Elements
- Demand Zones: Green fill, labeled "OB Demand"
- Supply Zones: Red fill, labeled "OB Supply"
- Tiny text size to minimize chart clutter
- Zones drawn as boxes using bar_index positioning
How to Use
Order Blocks represent areas of price inefficiency where smart money likely entered/exited positions aggressively.
- Demand Zones (Green): Potential long entry areas when price returns. Expect buying pressure to defend these levels. Best setups when price retests an active (non-mitigated) zone.
- Supply Zones (Red): Potential short entry areas when price returns. Expect selling pressure to emerge.
- Mitigated Zones: Lower probability – may act as weaker support/resistance.
- Smart Visibility: Highly recommended for cleaner charts. Focuses attention on zones most likely to be tested soon.
- Combine with:
- Break of Structure (BOS)/Change of Character (CHOCH)
- Liquidity grabs
- Higher timeframe confluence
- Volume or momentum confirmation
Use higher FVG threshold (e.g., 0.8–1.0) for fewer, higher-quality zones. Lower threshold for more aggressive detection.
Disclaimer
This indicator is a technical analysis tool and should be used in conjunction with other forms of analysis. Past performance does not guarantee future results. Always use proper risk management.
How It Works (Technical Methodology)
1. Fair Value Gap (FVG) Detection
The indicator identifies classic 3-candle imbalances:
- Bullish Order Block (Demand): When the low of the current candle is significantly below the high of the candle two bars ago (low[0] - high[2]).
- Bearish Order Block (Supply): When the high of the current candle is significantly above the low of the candle two bars ago (low[2] - high[0]).
A minimum size threshold is enforced using ATR(14) × user-defined multiplier (default 0.5) to filter out minor gaps and focus on meaningful inefficiencies.
2. Zone Creation
- Bullish zones are created at the candle two bars ago (the "origin" candle where inefficiency occurred).
- Bearish zones use the same origin candle.
- Zone boundaries:
Top = high of origin candle
Bottom = low of origin candle
This captures the full range where price moved aggressively, leaving an imbalance that institutions may later revisit.
3. Mitigation Detection
Zones can be mitigated in two ways (user-selectable):
- "Close": Zone is considered touched only if the close price enters the zone.
- "Wick": Zone is touched if any wick (high/low) enters the zone (more sensitive).
When mitigated:
- Background becomes more transparent
- Border turns dotted
- Label changes to "Mitigated"
Broken zones (price fully closes beyond the opposite side) are automatically deleted.
4. Zone Lifecycle Management
- Active Zone: Strong color fill (green for demand, red for supply) with solid border.
- Mitigated Zone: Faded color, dotted border – indicates partial fill or reduced strength.
- Broken Zone: Automatically removed from chart to reduce clutter.
Old zones are also pruned when exceeding 450 total to maintain performance.
5. Smart Visibility Engine (Optional)
When enabled:
- All zones are initially hidden.
- Only the closest relevant zones are shown:
- Up to user-defined limit (default 10) highest bullish zones (closest below price)
- Up to user-defined limit (default 10) lowest bearish zones (closest above price)
- Visible zones are automatically extended to the right and styled appropriately.
This keeps the chart clean while highlighting the most actionable zones near current price.
6. Visual Elements
- Demand Zones: Green fill, labeled "OB Demand"
- Supply Zones: Red fill, labeled "OB Supply"
- Tiny text size to minimize chart clutter
- Zones drawn as boxes using bar_index positioning
How to Use
Order Blocks represent areas of price inefficiency where smart money likely entered/exited positions aggressively.
- Demand Zones (Green): Potential long entry areas when price returns. Expect buying pressure to defend these levels. Best setups when price retests an active (non-mitigated) zone.
- Supply Zones (Red): Potential short entry areas when price returns. Expect selling pressure to emerge.
- Mitigated Zones: Lower probability – may act as weaker support/resistance.
- Smart Visibility: Highly recommended for cleaner charts. Focuses attention on zones most likely to be tested soon.
- Combine with:
- Break of Structure (BOS)/Change of Character (CHOCH)
- Liquidity grabs
- Higher timeframe confluence
- Volume or momentum confirmation
Use higher FVG threshold (e.g., 0.8–1.0) for fewer, higher-quality zones. Lower threshold for more aggressive detection.
Disclaimer
This indicator is a technical analysis tool and should be used in conjunction with other forms of analysis. Past performance does not guarantee future results. Always use proper risk management.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.