OPEN-SOURCE SCRIPT

ADX Trend Strength Analyzer

█  OVERVIEW

This script implements the Average Directional Index (ADX), a powerful tool used to measure the strength of market trends. It works alongside the Directional Movement Index (DMI), which breaks down the directional market pressure into bullish (+DI) and bearish (-DI) components. The purpose of the ADX is to indicate when the market is in a strong trend, without specifying the direction. This indicator can be especially useful for identifying market trends early and validating trading strategies based on trend-following systems.

The ADX component in this script is based on two key parameters:

ADX Smoothing Length (adxlen), which determines the degree of smoothing for the trend strength.
DI Length (dilen), which defines the look-back period for calculating the directional index values.
Additionally, a horizontal line is plotted at the 30 level, providing a widely used threshold that signifies when a trend is considered strong (above 30).

█  CONCEPTS

Directional Movement (DM): The core idea behind this indicator is the calculation of price movement in terms of bullish and bearish forces. By evaluating the change in highs and lows, the script distinguishes between bullish movement (+DM) and bearish movement (-DM). These values are normalized by dividing them by the True Range (TR), creating the +DI and -DI values.

True Range (TR): The True Range is calculated using the Average True Range (ATR) formula, and it serves to smooth out volatility, ensuring that short-term fluctuations don't distort the long-term trend signal.

ADX Calculation: The ADX is derived from the absolute difference between the +DI and -DI. By smoothing this difference and normalizing it, the ADX is able to measure the overall strength of the trend without regard to whether the market is moving up or down. A rising ADX indicates increasing trend strength, while a falling ADX signals weakening trends.

█  METHODOLOGY

Directional Movement Calculation: The script first determines the upward and downward price movement by comparing changes in the high and low prices. If the upward movement is greater than the downward movement, it registers a bullish signal and vice versa for bearish movement.

True Range Adjustment: The script then applies a smoothing function to normalize these movements by dividing them by the True Range (ATR). This ensures that the trend signal is based on relative, rather than absolute, price movements.

ADX Signal Generation: The final step is to calculate the ADX by applying the Relative Moving Average (RMA) to the difference between +DI and -DI. This produces the ADX value, which is plotted in red, making it easy to visualize shifts in market momentum.

Threshold Line: A blue horizontal line is plotted at 30, which serves as a key reference point. When the ADX is above this line, it indicates a strong trend, whether bullish or bearish.

█  HOW TO USE

Trend Strength: Traders typically use the 30 level as a critical threshold. When the ADX is above 30, it signifies a strong trend, making it a favorable environment for trend-following strategies. Conversely, ADX values below 30 suggest a weak or non-trending market.

+DI and -DI Relationship: The indicator also provides insight into whether the trend is bullish or bearish. When +DI is greater than -DI, the market is considered bullish. When -DI is greater than +DI, the market is considered bearish. While this script focuses on the ADX value itself, the underlying +DI and -DI help interpret the trend direction.

Market Conditions: This indicator is effective in trending markets, but not ideal for choppy or sideways conditions. Traders can use it to determine the best entry and exit points when trends are strong, or to avoid trading in periods of low volatility.

Combining with Other Indicators: The ADX is commonly used in conjunction with oscillators like RSI or moving averages, to confirm the trend strength and avoid false signals.

█  METHOD VARIANTS

This script applies the standard approach for calculating the ADX, but could be adapted with the following variants:

Different Timeframes: The script could be modified to calculate ADX values across higher or lower timeframes, depending on the trader's strategy.
Custom Thresholds: Instead of using the default 30 threshold, traders could adjust the horizontal line to suit their own risk tolerance or market conditions.
Average Directional Index (ADX)educationalforecasting

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