OPEN-SOURCE SCRIPT

ATR Zone Levels Pro

98
### 🧠 **Purpose of the Script**

The script calculates **dynamic support/resistance levels** above and below a base price using the **ATR (Average True Range)**. These "zones" help traders identify potential areas of price reaction, entries, or stop placement based on current market volatility.

---

### ⚙️ **1. User Inputs**

```pinescript
show_long = input(true, "Show Long Levels")
show_short = input(true, "Show Short Levels")
use_close_price = input(true, "Use Close Price")
atr_length = input.int(14, "ATR Period", minval=1)
smoothing = input.string("RMA", "Smoothing Type", options=["RMA", "SMA", "EMA", "WMA"])
```

* `show_long` and `show_short`: Allow toggling visibility of long/short zones.
* `use_close_price`: If true, base level = close price; else, it’s the average of high and low.
* `atr_length`: Number of bars used for ATR calculation.
* `smoothing`: Type of smoothing applied to the ATR.

---

### 📐 **2. ATR Calculation with Custom Smoothing**

```pinescript
ma_function(source, length) => ...
true_range = ta.tr(true)
atr = ma_function(true_range, atr_length)
```

* `true_range`: Calculates the true range for each bar.
* `atr`: Applies user-selected smoothing function to the true range to get ATR.

---

### 📏 **3. Base Level Calculation**

```pinescript
base_level = use_close_price ? close : (high + low) / 2
```

* Defines the **base price level** for the zones:

* `close` if selected, otherwise midpoint of high and low.

---

### 🔢 **4. Calculating Zone Levels**

```pinescript
array.push(long_levels, base_level + atr * 0.3) ...
array.push(short_levels, base_level - atr * 0.3) ...
```

* Creates arrays of levels spaced at multipliers of ATR (0.3x, 0.5x, 1x, 1.5x).
* `long_levels` are above the base level (for breakout or continuation).
* `short_levels` are below (for breakdown or reversal).

---

### 🖼️ **5. Plotting Levels**

```pinescript
plot(show_long ? array.get(long_levels, 1) : na, ...)
```

* Each level is plotted with distinct colors.
* If `show_long` or `show_short` is disabled, the corresponding lines are hidden.

---

### 📋 **6. Info Table (Top Right Corner)**

```pinescript
var table info_table = table.new(position.top_right, 2, 5)
```

* Displays:

* Current ATR value
* Main Long/Short zone level (1 ATR above/below base)
* Chosen smoothing type
* Current base price

---

### 🏷️ **7. Info Label on Chart**

```pinescript
label.new(bar_index, base_level, ...)
```

* Shows a label near the base price on the last bar with:

* Base level
* ATR value
* Old label is deleted on each bar to keep only one active label.

---

### ✅ **Use Case**

This indicator is ideal for:

* Determining dynamic **support/resistance levels**
* Planning entries/exits based on volatility zones
* Structuring trades with ATR-based risk zones (e.g. 1.5x ATR stops)

---

Would you like me to add **alerts** when price reaches these zones or crosses them?

Penafian

Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.