OPEN-SOURCE SCRIPT

Double Bollinger Bands with Dynamic Stops and Take Profit

98
### 📊 **Double Bollinger Bands with Dynamic Stops and Take Profit – Technical Description**

The **Double Bollinger Bands with Dynamic Stops and Take Profit** indicator is a comprehensive tool that enhances classic Bollinger Bands by incorporating **dual deviation bands** for improved volatility analysis. It also dynamically calculates **stop-loss** and **take-profit** levels based on recent price action, offering a robust framework for managing trades in trending or ranging markets.

---

### ✅ **Indicator Parameters**
1. **Bollinger Bands Settings:**
- **Period (`length`):** Defines the moving average window (default: 20).
- **Deviation 1 (`deviation1`):** Controls the width of the first Bollinger Band (default: 1.0).
- **Deviation 2 (`deviation2`):** Controls the width of the second Bollinger Band (default: 2.0).

2. **Dynamic Stop-Loss and Take-Profit Settings:**
- **Lookback Period (`stop_lookback`):** Number of bars used to determine dynamic stop levels (default: 26).
- **Stop Multiplier (`stop_multiplier`):** Fraction of the range used to calculate the stop-loss (default: 0.5).
- **Risk/Reward Ratio (`rr_ratio`):** Determines the take-profit relative to the stop-loss (default: 3.0).

---

### 📐 **Calculation Logic**

1. **Bollinger Bands Calculation:**
- **Basis Line:** A **Simple Moving Average (SMA)** of the closing price:

\[
\text{Basis} = \text{SMA}( \text{close}, \text{length})
\]

- **Deviation Multipliers:** Standard deviations scaled by user input:

- **Upper Band 1:** \( \text{Basis} + \text{Deviation 1} \times \text{stdev} \)
- **Lower Band 1:** \( \text{Basis} - \text{Deviation 1} \times \text{stdev} \)
- **Upper Band 2:** \( \text{Basis} + \text{Deviation 2} \times \text{stdev} \)
- **Lower Band 2:** \( \text{Basis} - \text{Deviation 2} \times \text{stdev} \)

2. **Dynamic Stop Calculation:**
- Identifies the **highest high** and **lowest low** over the lookback period:

\[
\text{Range Max} = \text{Highest High} - \text{Lowest Low}
\]

- **Dynamic Stop for Long Positions:**

\[
\text{Dynamic Stop (Long)} = \text{close} - (\text{Range Max} \times \text{Stop Multiplier})
\]

- **Dynamic Stop for Short Positions:**

\[
\text{Dynamic Stop (Short)} = \text{close} + (\text{Range Max} \times \text{Stop Multiplier})
\]

3. **Dynamic Take-Profit Calculation:**
- Extends the stop calculation by multiplying with the **risk/reward ratio**:

\[
\text{Dynamic TP (Long)} = \text{close} + (\text{Range Max} \times \text{Stop Multiplier} \times \text{RR Ratio})
\]

\[
\text{Dynamic TP (Short)} = \text{close} - (\text{Range Max} \times \text{Stop Multiplier} \times \text{RR Ratio})
\]

---

### 📈 **Visual Outputs**
- **Bollinger Bands:**
- **Green Bands:** Inner Bollinger Bands (Deviation 1) indicate short-term volatility.
- **Red Bands:** Outer Bollinger Bands (Deviation 2) highlight extreme price movements.
- **Blue Line:** The central moving average (basis) for trend direction.

- **Dynamic Stops & Take-Profits:**
- **Green Circles:** Dynamic stop-loss and take-profit levels for **long** positions.
- **Red Circles:** Dynamic stop-loss and take-profit levels for **short** positions.

---

### 🛠️ **Practical Use-Cases**
1. **Trend-Following Strategy:** Use the **outer bands** to confirm breakouts, with dynamic stops for protection.
2. **Mean Reversion:** Enter trades when the price touches **outer bands**, aiming for the **basis**.
3. **Volatility Management:** Adjust **stop_multiplier** to adapt stops to changing market conditions.
4. **Dynamic Risk Control:** Automatically calculates stop-loss and take-profit for structured **risk management**.

---

👉 This indicator provides a **multi-layered approach** for both trend and mean-reversion strategies, integrating real-time **risk control** through dynamic stop and take-profit mechanisms.

---

คำจำกัดสิทธิ์ความรับผิดชอบ

ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมที่ ข้อกำหนดการใช้งาน