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.
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.