OPEN-SOURCE SCRIPT

ADX & DI with dynamic threshold indicator

Updated
<documentation>
<title>ADX and DI with Dynamic Threshold</title>
<overview>
<description>This Pine Script indicator, "ADX & DI with Dynamic Threshold," helps traders detect trends, trend reversals, and trend strength using the Average Directional Index (ADX) and the Directional Indexes (DI+ and DI-). It incorporates a dynamic threshold calculated using the average ADX over a user-defined period, along with a fixed minimum threshold, making trend detection more flexible and adaptable.</description>
</overview>

<keyFeatures>
<feature>
<title>ADX and Directional Indexes (DI+ and DI-)</title>
<description>ADX measures the strength of a trend, while DI+ and DI- measure the direction of the trend. High DI+ signals upward price strength, and high DI- signals downward price strength.</description>
</feature>
<feature>
<title>Dynamic Threshold</title>
<description>A threshold based on the average ADX over a certain number of periods, ensuring the indicator adapts to market conditions. The threshold is compared to DI+ and DI- to generate trend signals.</description>
</feature>
<feature>
<title>Fixed Minimum Threshold</title>
<description>A user-defined minimum threshold ensures that signals are only generated in markets with a certain level of trend strength, preventing false signals in low-trending markets.</description>
</feature>
<feature>
<title>Visual Highlights</title>
<description>The background color highlights:
<highlight>Green for potential uptrend</highlight>,
<highlight>Red for potential downtrend</highlight>, and
<highlight>Orange when directional movement is strong but trend strength is weak, helping traders avoid false signals in sideways markets.</description>
</feature>
<feature>
<title>Customization</title>
<description>Several input parameters allow for complete customization of the indicator, ensuring it can adapt to different timeframes and assets.</description>
</feature>
</keyFeatures>

<usage>
<title>How to Use</title>
<inputs>
<input>
<name>Length (len)</name>
<description>This is the smoothing period used to calculate the ADX and DI+/- values. Range: 5 to 50 (default: 14).</description>
</input>
<input>
<name>Threshold Period (th_period)</name>
<description>Determines the number of periods over which the dynamic ADX threshold is calculated. Range: 5 to 200 (default: 50).</description>
</input>
<input>
<name>Fixed Minimum Threshold (fixed_th)</name>
<description>The minimum ADX value that must be exceeded for the indicator to trigger signals. Range: 10 to 40 (default: 20).</description>
</input>
<input>
<name>Smoothing Method</name>
<description>Choose between SMA (Simple Moving Average) or EMA (Exponential Moving Average) for smoothing the true range and directional movement calculations.</description>
</input>
</inputs>

<plots>
<plot>
<name>DI+ (Green)</name>
<description>Indicates the strength of upward price movements.</description>
</plot>
<plot>
<name>DI- (Red)</name>
<description>Indicates the strength of downward price movements.</description>
</plot>
<plot>
<name>ADX (Navy)</name>
<description>Indicates the overall strength of the trend, regardless of direction.</description>
</plot>
<plot>
<name>Dynamic Threshold (Gray)</name>
<description>The dynamic threshold used for comparing ADX values.</description>
</plot>
<plot>
<name>Fixed Threshold Line</name>
<description>A dotted black line showing the user-defined minimum threshold for ADX.</description>
</plot>
</plots>

<visualCues>
<cue>
<color>Green Background</color>
<description>Indicates a potential uptrend when DI+ > DI- and ADX is above the threshold.</description>
</cue>
<cue>
<color>Red Background</color>
<description>Indicates a potential downtrend when DI- > DI+ and ADX is above the threshold.</description>
</cue>
<cue>
<color>Orange Background</color>
<description>Indicates that DI+ or DI- are strong, but ADX is weak, suggesting a lack of trend strength despite directional movement, which could lead to false signals.</description>
</cue>
</visualCues>
</usage>

<customizationTips>
<tip>Adjust the length (len) based on the volatility of the asset. A lower len (e.g., 10) may be suitable for faster timeframes (like 5-min charts), while a higher value (e.g., 20-30) may work better on longer timeframes.</tip>
<tip>Use the threshold period (th_period) to fine-tune the dynamic ADX threshold. A higher value smooths the dynamic threshold over a longer period, making it more resistant to sudden volatility.</tip>
<tip>Fixed Threshold (fixed_th) should be set based on the strength of trends you want to capture. A higher value (e.g., 30-40) is more conservative and will only trigger signals in very strong trends.</tip>
</customizationTips>

<exampleUsage>
<title>Example Usage</title>
<description>This indicator can be used to:
<useCase>Identify trends: When the ADX crosses the threshold and DI+ or DI- is dominant, indicating an uptrend or downtrend.</useCase>
<useCase>Spot trend reversals: When DI+ and DI- cross each other with a strong ADX reading.</useCase>
<useCase>Avoid false signals: By recognizing when DI+ or DI- are strong, but the ADX is below the threshold (highlighted in orange).</useCase>
</description>
</exampleUsage>

<conclusion>
<title>Conclusion</title>
<description>The ADX and DI with Dynamic Threshold indicator is a versatile tool for trend-following strategies. It adapts to market conditions using dynamic and fixed thresholds and provides clear visual signals to help traders make informed decisions about market direction and trend strength.</description>
<description>By adjusting the various input parameters, this indicator can be tailored to any asset class or timeframe, making it suitable for all types of traders, from scalpers to swing traders.</description>
<note>Feel free to experiment with different settings and incorporate this indicator into your trading strategy for enhanced market analysis.</note>
</conclusion>
</documentation>
Release Notes
# ADX and DI with Dynamic Threshold

## Overview

This Pine Script indicator, **"ADX & DI with Dynamic Threshold,"** helps traders detect trends, trend reversals, and trend strength using the **Average Directional Index (ADX)** and the **Directional Indexes (DI+ and DI-)**. It incorporates a **dynamic threshold** calculated using the average ADX over a user-defined period, along with a **fixed minimum threshold**, making trend detection more flexible and adaptable.

---

## Key Features

- **ADX and Directional Indexes (DI+ and DI-)**:
ADX measures the **strength** of a trend, while DI+ and DI- measure the **direction** of the trend. High DI+ signals upward price strength, and high DI- signals downward price strength.

- **Dynamic Threshold**:
A threshold based on the average ADX over a certain number of periods, ensuring the indicator adapts to market conditions. The threshold is compared to DI+ and DI- to generate trend signals.

- **Fixed Minimum Threshold**:
A user-defined minimum threshold ensures that signals are only generated in markets with a certain level of trend strength, preventing false signals in low-trending markets.

- **Visual Highlights**:
The background color highlights:
- **Green for potential uptrend**.
- **Red for potential downtrend**.
- **Orange when directional movement is strong but trend strength is weak**, helping traders avoid false signals in sideways markets.

- **Customization**:
Several input parameters allow for complete customization of the indicator, ensuring it can adapt to different timeframes and assets.

---

## How to Use

### Inputs

1. **Length (len)**:
This is the smoothing period used to calculate the ADX and DI+/- values.
- Range: 5 to 50 (default: 14).

2. **Threshold Period (th_period)**:
Determines the number of periods over which the dynamic ADX threshold is calculated.
- Range: 5 to 200 (default: 50).

3. **Fixed Minimum Threshold (fixed_th)**:
The minimum ADX value that must be exceeded for the indicator to trigger signals.
- Range: 10 to 40 (default: 20).

4. **Smoothing Method**:
Choose between **SMA** (Simple Moving Average) or **EMA** (Exponential Moving Average) for smoothing the true range and directional movement calculations.

### Plots

1. **DI+ (Green)**:
Indicates the strength of upward price movements.

2. **DI- (Red)**:
Indicates the strength of downward price movements.

3. **ADX (Navy)**:
Indicates the overall strength of the trend, regardless of direction.

4. **Dynamic Threshold (Gray)**:
The dynamic threshold used for comparing ADX values.

5. **Fixed Threshold Line**:
A dotted black line showing the user-defined minimum threshold for ADX.

### Visual Cues

- **Green Background**:
Indicates a potential **uptrend** when DI+ > DI- and ADX is above the threshold.

- **Red Background**:
Indicates a potential **downtrend** when DI- > DI+ and ADX is above the threshold.

- **Orange Background**:
Indicates that **DI+** or **DI-** are strong, but ADX is weak. This suggests a lack of trend strength despite directional movement, which could lead to false signals or choppy market conditions.

---

## Customization Tips

- **Adjust the length (len)** based on the volatility of the asset.
A lower `len` (e.g., 10) may be suitable for faster timeframes (like 5-min charts), while a higher value (e.g., 20-30) may work better on longer timeframes.

- **Use the threshold period (th_period)** to fine-tune the dynamic ADX threshold.
A higher value for `th_period` smooths the dynamic threshold over a longer period, making it more resistant to sudden spikes in volatility.

- **Fixed Threshold (fixed_th)** should be set based on the strength of trends you want to capture.
A higher value (e.g., 30-40) is more conservative and will only trigger signals in very strong trends.

---

## Example Usage

This indicator can be used to:

- **Identify trends**:
When the ADX crosses the threshold and DI+ or DI- is dominant, indicating an uptrend or downtrend.

- **Spot trend reversals**:
When DI+ and DI- cross each other with a strong ADX reading.

- **Avoid false signals**:
By recognizing when DI+ or DI- are strong, but the ADX is below the threshold (highlighted in orange).

---

## Conclusion

The **ADX and DI with Dynamic Threshold** indicator is a versatile tool for trend-following strategies. It adapts to market conditions using dynamic and fixed thresholds and provides clear visual signals to help traders make informed decisions about market direction and trend strength.

By adjusting the various input parameters, this indicator can be tailored to any asset class or timeframe, making it suitable for all types of traders, from scalpers to swing traders.

Feel free to experiment with different settings and incorporate this indicator into your trading strategy for enhanced market analysis.
Release Notes
# ADX and DI with Dynamic Threshold

## Overview

This Pine Script indicator, **"ADX & DI with Dynamic Threshold,"** helps traders detect trends, trend reversals, and trend strength using the **Average Directional Index (ADX)** and the **Directional Indexes (DI+ and DI-)**. It incorporates a **dynamic threshold** calculated using the average ADX over a user-defined period, along with a **fixed minimum threshold**, making trend detection more flexible and adaptable.

---

## Key Features

- **ADX and Directional Indexes (DI+ and DI-)**:
ADX measures the **strength** of a trend, while DI+ and DI- measure the **direction** of the trend. High DI+ signals upward price strength, and high DI- signals downward price strength.

- **Dynamic Threshold**:
A threshold based on the average ADX over a certain number of periods, ensuring the indicator adapts to market conditions. The threshold is compared to DI+ and DI- to generate trend signals.

- **Fixed Minimum Threshold**:
A user-defined minimum threshold ensures that signals are only generated in markets with a certain level of trend strength, preventing false signals in low-trending markets.

- **Visual Highlights**:
The background color highlights:
- **Green for potential uptrend**.
- **Red for potential downtrend**.
- **Orange when directional movement is strong but trend strength is weak**, helping traders avoid false signals in sideways markets.

- **Customization**:
Several input parameters allow for complete customization of the indicator, ensuring it can adapt to different timeframes and assets.

---

## How to Use

### Inputs

1. **Length (len)**:
This is the smoothing period used to calculate the ADX and DI+/- values.
- Range: 5 to 50 (default: 14).

2. **Threshold Period (th_period)**:
Determines the number of periods over which the dynamic ADX threshold is calculated.
- Range: 5 to 200 (default: 50).

3. **Fixed Minimum Threshold (fixed_th)**:
The minimum ADX value that must be exceeded for the indicator to trigger signals.
- Range: 10 to 40 (default: 20).

4. **Smoothing Method**:
Choose between **SMA** (Simple Moving Average) or **EMA** (Exponential Moving Average) for smoothing the true range and directional movement calculations.

### Plots

1. **DI+ (Green)**:
Indicates the strength of upward price movements.

2. **DI- (Red)**:
Indicates the strength of downward price movements.

3. **ADX (Navy)**:
Indicates the overall strength of the trend, regardless of direction.

4. **Dynamic Threshold (Gray)**:
The dynamic threshold used for comparing ADX values.

5. **Fixed Threshold Line**:
A dotted black line showing the user-defined minimum threshold for ADX.

### Visual Cues

- **Green Background**:
Indicates a potential **uptrend** when DI+ > DI- and ADX is above the threshold.

- **Red Background**:
Indicates a potential **downtrend** when DI- > DI+ and ADX is above the threshold.

- **Orange Background**:
Indicates that **DI+** or **DI-** are strong, but ADX is weak. This suggests a lack of trend strength despite directional movement, which could lead to false signals or choppy market conditions.

---

## Customization Tips

- **Adjust the length (len)** based on the volatility of the asset.
A lower `len` (e.g., 10) may be suitable for faster timeframes (like 5-min charts), while a higher value (e.g., 20-30) may work better on longer timeframes.

- **Use the threshold period (th_period)** to fine-tune the dynamic ADX threshold.
A higher value for `th_period` smooths the dynamic threshold over a longer period, making it more resistant to sudden spikes in volatility.

- **Fixed Threshold (fixed_th)** should be set based on the strength of trends you want to capture.
A higher value (e.g., 30-40) is more conservative and will only trigger signals in very strong trends.

---

## Example Usage

This indicator can be used to:

- **Identify trends**:
When the ADX crosses the threshold and DI+ or DI- is dominant, indicating an uptrend or downtrend.

- **Spot trend reversals**:
When DI+ and DI- cross each other with a strong ADX reading.

- **Avoid false signals**:
By recognizing when DI+ or DI- are strong, but the ADX is below the threshold (highlighted in orange).

---

## Conclusion

The **ADX and DI with Dynamic Threshold** indicator is a versatile tool for trend-following strategies. It adapts to market conditions using dynamic and fixed thresholds and provides clear visual signals to help traders make informed decisions about market direction and trend strength.

By adjusting the various input parameters, this indicator can be tailored to any asset class or timeframe, making it suitable for all types of traders, from scalpers to swing traders.

Feel free to experiment with different settings and incorporate this indicator into your trading strategy for enhanced market analysis.
Trend Analysis

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?

Disclaimer