PROTECTED SOURCE SCRIPT
Consolidating Box with EMA

**Consolidating Box with EMA** automatically identifies tight consolidation zones near an EMA and draws a dotted box around the most recent valid range. It also displays key stats (range and candle count) in a small table.
---
### What it shows
* **Consolidation Box (dotted white border):**
* **Top:** Highest High within the detected range
* **Bottom:** Lowest Low within the detected range
* **Info Table (bottom-right):**
* **R:** Range in ATR units → `(BoxHigh - BoxLow) / ATR`
* **N:** Number of candles in the consolidation
> Only the **latest** consolidation box is displayed. The script removes the previous box/table on each last-bar update.
---
### How it works
On the latest bar, the script scans back up to **50 candles** and attempts to find a consolidation where:
* The overall High–Low range stays within a volatility threshold:
`Range <= ATR Multiplier × ATR`
* The consolidation is **near the EMA**, meaning at least one candle overlaps this EMA band:
`EMA ± (EMA Multiplier × ATR)`
* The range contains at least **Minimum Consolidation Candles**.
To be flexible across different volatility conditions, it iterates ATR thresholds from **ATR Multiplier Min** to **ATR Multiplier Max**, using **ATR Multiplier Step**, and stops at the first valid match.
---
### Inputs
**General**
* **Minimum Consolidation Candles:** Minimum number of candles required to qualify.
**ATR**
* **ATR Length:** ATR period used for volatility normalization.
* **ATR Multiplier Min / Max:** Tightness range used to search for consolidation.
* **ATR Multiplier Step:** Increment size while searching.
**EMA**
* **EMA Length:** EMA period used as the “mean” reference.
* **EMA Multiplier:** Width of the EMA proximity band in ATR units.
---
### Tips
* Lower **ATR Multiplier Max** → fewer but tighter boxes
* Increase **Minimum Consolidation Candles** → longer, more reliable consolidations
* Increase **EMA Multiplier** → allows boxes farther from the EMA band
---
---
### What it shows
* **Consolidation Box (dotted white border):**
* **Top:** Highest High within the detected range
* **Bottom:** Lowest Low within the detected range
* **Info Table (bottom-right):**
* **R:** Range in ATR units → `(BoxHigh - BoxLow) / ATR`
* **N:** Number of candles in the consolidation
> Only the **latest** consolidation box is displayed. The script removes the previous box/table on each last-bar update.
---
### How it works
On the latest bar, the script scans back up to **50 candles** and attempts to find a consolidation where:
* The overall High–Low range stays within a volatility threshold:
`Range <= ATR Multiplier × ATR`
* The consolidation is **near the EMA**, meaning at least one candle overlaps this EMA band:
`EMA ± (EMA Multiplier × ATR)`
* The range contains at least **Minimum Consolidation Candles**.
To be flexible across different volatility conditions, it iterates ATR thresholds from **ATR Multiplier Min** to **ATR Multiplier Max**, using **ATR Multiplier Step**, and stops at the first valid match.
---
### Inputs
**General**
* **Minimum Consolidation Candles:** Minimum number of candles required to qualify.
**ATR**
* **ATR Length:** ATR period used for volatility normalization.
* **ATR Multiplier Min / Max:** Tightness range used to search for consolidation.
* **ATR Multiplier Step:** Increment size while searching.
**EMA**
* **EMA Length:** EMA period used as the “mean” reference.
* **EMA Multiplier:** Width of the EMA proximity band in ATR units.
---
### Tips
* Lower **ATR Multiplier Max** → fewer but tighter boxes
* Increase **Minimum Consolidation Candles** → longer, more reliable consolidations
* Increase **EMA Multiplier** → allows boxes farther from the EMA band
---
Script protégé
Ce script est publié en source fermée. Cependant, vous pouvez l'utiliser librement et sans aucune restriction – pour en savoir plus, cliquez ici.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.
Script protégé
Ce script est publié en source fermée. Cependant, vous pouvez l'utiliser librement et sans aucune restriction – pour en savoir plus, cliquez ici.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.