PROTECTED SOURCE SCRIPT
Mis à jour

AFB_TrendMarketDMS

78
This script is an implementation of the **Directional Movement System (DMS)**, which includes the **Positive Directional Indicator (+DI)**, **Negative Directional Indicator (-DI)**, and **Average Directional Index (ADX)**. Additionally, the script provides visualizations and logic to identify trends and key levels. Below is a detailed explanation of how to use this script:

---

### 1. **Function `dirmov(jarak)`**:
This function calculates the **+DI (Plus Directional Indicator)** and **-DI (Minus Directional Indicator)**.

- **Input**:
- `jarak`: The period used for calculation (in this script, `14`).

- **Process**:
- `naik = ta.change(high)`: Calculates the change in the high price (upward movement).
- `turun = -ta.change(low)`: Calculates the change in the low price (downward movement).
- `truerange = ta.rma(ta.tr, jarak)`: Calculates the **True Range (TR)** smoothed using RMA (Rolling Moving Average).
- `plus`: Calculates +DI by comparing upward (`naik`) and downward (`turun`) movements.
- `minus`: Calculates -DI by comparing downward (`turun`) and upward (`naik`) movements.

- **Output**:
- Returns the values of `plus` (+DI) and `minus` (-DI).

---

### 2. **Function `adx(dilen, adxlen)`**:
This function calculates the **ADX (Average Directional Index)**, **+DI**, and **-DI**.

- **Input**:
- `dilen`: The period for calculating +DI and -DI.
- `adxlen`: The period for calculating ADX.

- **Process**:
- Calls the `dirmov(dilen)` function to get the values of `plus` (+DI) and `minus` (-DI).
- Calculates ADX by comparing the difference between +DI and -DI, then smoothing it with RMA.

- **Output**:
- Returns the values of `adx`, `plus` (+DI), and `minus` (-DI).

---

### 3. **Variables and Plots**:
- `[sig, up, down] = adx(14, 14)`:
- `sig`: The ADX value.
- `up`: The +DI value.
- `down`: The -DI value.

- `RatioNT = up - down`:
- Calculates the difference between +DI and -DI. This value represents the relative strength between the upward and downward trends.

- `Garis_ratioNT = ta.sma(RatioNT, 14)`:
- Calculates the Simple Moving Average (SMA) of `RatioNT` with a period of 14. This is used as a key level to identify trend changes.

- **Plots**:
- `L1 = plot(RatioNT, 'Trend', ...)`:
- Plots the `RatioNT` value as a trend line. The line color changes based on whether `RatioNT` is above or below `Garis_ratioNT`.
- Green (`#00d36880`) if `RatioNT > Garis_ratioNT` (strong uptrend).
- Red (`#fe585880`) if `RatioNT < Garis_ratioNT` (strong downtrend).
- `L3 = plot(Garis_ratioNT, 'KeyLevel', ...)`:
- Plots `Garis_ratioNT` as a key level (blue line, `#1848cc`).

- **Horizontal Lines (HLine)**:
- `hline(0.8, 'Top', ...)`: A horizontal line at the `0.8` level (pink color, `#fe585850`).
- `hline(0, 'Mid', ...)`: A horizontal line at the `0` level (black color, `#00000050`).
- `hline(-0.8, 'Bottom', ...)`: A horizontal line at the `-0.8` level (green color, `#00d36850`).

---

### 4. **How to Use This Script**:
This script can be used to:
1. **Identify Trends**:
- If `RatioNT` is above `Garis_ratioNT` and colored green, it indicates a strong uptrend.
- If `RatioNT` is below `Garis_ratioNT` and colored red, it indicates a strong downtrend.

2. **Identify Key Levels**:
- `Garis_ratioNT` (blue line) is a key level that can be used as a reference to confirm trend changes.

3. **Use Horizontal Lines**:
- The horizontal lines at `0.8`, `0`, and `-0.8` can be used as overbought/oversold levels or trend confirmation levels.

4. **Trading Signals**:
- **Buy Signal**: When `RatioNT` crosses above `Garis_ratioNT` and turns green.
- **Sell Signal**: When `RatioNT` crosses below `Garis_ratioNT` and turns red.

---

### 5. **Visual Interpretation**:
- **Uptrend**:
- `RatioNT` is green and above `Garis_ratioNT`.
- `RatioNT` approaches or exceeds the `0.8` level (pink line).

- **Downtrend**:
- `RatioNT` is red and below `Garis_ratioNT`.
- `RatioNT` approaches or exceeds the `-0.8` level (green line).

- **Sideways/Consolidation**:
- `RatioNT` fluctuates around the `0` level (black line).

---

### 6. **Example Trading Signals**:
- **Buy Signal Example**:
- `RatioNT` crosses above `Garis_ratioNT` and turns green.
- `RatioNT` approaches the `0.8` level (confirms strong uptrend).

- **Sell Signal Example**:
- `RatioNT` crosses below `Garis_ratioNT` and turns red.
- `RatioNT` approaches the `-0.8` level (confirms strong downtrend).

---

### 7. **Conclusion**:
This script is a useful tool for:
- Identifying the strength and direction of trends.
- Providing trading signals based on the movement of `RatioNT` and `Garis_ratioNT`.
- Offering key levels for trend confirmation.

If you'd like to add more features or need further clarification, let me know! 😊
Notes de version
fix bugs

Clause de non-responsabilité

Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.