OPEN-SOURCE SCRIPT
KEY LEVEL SMC - Order Block

The "KEY LEVEL SMC - Order Block" is a specialized institutional technical analysis tool optimized for TradingView v6. It automatically detects, highlights, and projects Order Blocks (OB) using strict algorithmic price action and structural efficiency logic.
This indicator is specifically engineered for traders utilizing Smart Money Concepts (SMC) and Order Flow mechanics to maintain an objective view of institutional supply and demand zones.
### 📐 How It Works (Algorithmic Logic):
Unlike standard engulfing indicators, this script applies a strict filter requiring the immediate displacement to leave a structural imbalance (Fair Value Gap/Inefficiency) behind. The signal evaluates a 3-candle sequence:
1. **Bullish Order Block Configuration:**
- The setup identifies a specific institutional down-candle followed by aggressive upward displacement.
- A valid signal is triggered only if the opening price of the current setup candle is within or below the previous candle's body, closes above the previous candle's open, and the subsequent candle's low fails to mitigate the high of the initial candle (confirming an immediate structural imbalance).
- **Zone Boundaries:** The automated box marks the lowest point between the two initial candles as the bottom zone, and the open price of the setup candle as the top zone.
2. **Bearish Order Block Configuration:**
- The setup tracks an institutional up-candle followed by sharp downward displacement.
- Trigger criteria mandate that the setup candle opens within or above the previous body, closes below the previous open, and the subsequent candle's high leaves an unmitigated gap below the previous candle's low.
- **Zone Boundaries:** The automated box spans from the highest point of the displacement candles to the open price of the setup candle.
### 💻 Key Features & Customization:
* **Dynamic Box Array Management:** The script utilizes dynamic arrays (`box[]`) to plot and track multiple historical zones simultaneously. To ensure peak chart performance without causing lag, it features an automated memory cleanup loop governed by the "Maximum Box Displayed" parameter.
* **Real-time Extensions:** Zones remain active and extend dynamically to the right with each new bar until the price action fully mitigates or invalidates the defined structural level.
* **Dark-Mode Optimized UI:** Built-in customized color groups allow traders to seamlessly adjust candle overlays and box transparencies to fit professional dark layout themes perfectly.
### 🛑 Disclaimer & Use Case:
This tool is intended for professional intraday and swing trading strategies across major pairs, indices, and metals. It works best when combined with higher-timeframe order flow alignment and key Fibonacci expansion target objectives.
This indicator is specifically engineered for traders utilizing Smart Money Concepts (SMC) and Order Flow mechanics to maintain an objective view of institutional supply and demand zones.
### 📐 How It Works (Algorithmic Logic):
Unlike standard engulfing indicators, this script applies a strict filter requiring the immediate displacement to leave a structural imbalance (Fair Value Gap/Inefficiency) behind. The signal evaluates a 3-candle sequence:
1. **Bullish Order Block Configuration:**
- The setup identifies a specific institutional down-candle followed by aggressive upward displacement.
- A valid signal is triggered only if the opening price of the current setup candle is within or below the previous candle's body, closes above the previous candle's open, and the subsequent candle's low fails to mitigate the high of the initial candle (confirming an immediate structural imbalance).
- **Zone Boundaries:** The automated box marks the lowest point between the two initial candles as the bottom zone, and the open price of the setup candle as the top zone.
2. **Bearish Order Block Configuration:**
- The setup tracks an institutional up-candle followed by sharp downward displacement.
- Trigger criteria mandate that the setup candle opens within or above the previous body, closes below the previous open, and the subsequent candle's high leaves an unmitigated gap below the previous candle's low.
- **Zone Boundaries:** The automated box spans from the highest point of the displacement candles to the open price of the setup candle.
### 💻 Key Features & Customization:
* **Dynamic Box Array Management:** The script utilizes dynamic arrays (`box[]`) to plot and track multiple historical zones simultaneously. To ensure peak chart performance without causing lag, it features an automated memory cleanup loop governed by the "Maximum Box Displayed" parameter.
* **Real-time Extensions:** Zones remain active and extend dynamically to the right with each new bar until the price action fully mitigates or invalidates the defined structural level.
* **Dark-Mode Optimized UI:** Built-in customized color groups allow traders to seamlessly adjust candle overlays and box transparencies to fit professional dark layout themes perfectly.
### 🛑 Disclaimer & Use Case:
This tool is intended for professional intraday and swing trading strategies across major pairs, indices, and metals. It works best when combined with higher-timeframe order flow alignment and key Fibonacci expansion target objectives.
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.