Average Directional Index
The Average Directional Index (ADX) is a technical analysis indicator developed by J. Welles Wilder Jr. in 1978. It is used to quantify the strength of a trend in a financial market, whether the trend is upward or downward. The ADX is part of the Directional Movement System and is typically plotted as a single line, which helps traders to distinguish between strong and weak trends.
Components of ADX
The ADX is calculated using the Moving Average of price range expansion. The system it belongs to also involves two other indicators:
- Positive Directional Index (+DI): Measures the presence and strength of upward movement in the market.
- Negative Directional Index (-DI): Measures the presence and strength of downward movement in the market.
When combined, the ADX, +DI, and -DI provide a comprehensive view of market trends and their strengths.
Calculating the ADX
Let H_t, L_t, and C_t denote each candle’s high, low, and close. Calculate true range and the upward and downward changes for candles with a previous close.
\begin{aligned}
\mathrm{TR}_t &= \max(H_t-L_t,\lvert H_t-C_{t-1}\rvert,\lvert L_t-C_{t-1}\rvert) \\
u_t &= H_t-H_{t-1} \\
d_t &= L_{t-1}-L_t
\end{aligned}Only the larger positive change contributes to directional movement. If the changes are equal, both components are zero.
\mathrm{DM}^+_t=\begin{cases}u_t&u_t>\max(0,d_t)\\0&\text{otherwise}\end{cases},
\qquad
\mathrm{DM}^-_t=\begin{cases}d_t&d_t>\max(0,u_t)\\0&\text{otherwise}\end{cases}Apply Wilder’s smoothing to each of X=\mathrm{TR},\mathrm{DM}^+,\mathrm{DM}^-. Start with the sum of the first n-1 values and apply the recurrence from the n-th value. The usual period is 14 candles.
S_t(X)=S_{t-1}(X)-\frac{S_{t-1}(X)}{n}+X_tDivide each smoothed directional movement by the smoothed true range to obtain \mathrm{DI}^+ and \mathrm{DI}^-. If the smoothed range is zero, both indices are set to zero.
\mathrm{DI}^+_t=100\cdot\frac{S_t(\mathrm{DM}^+)}{S_t(\mathrm{TR})},
\qquad
\mathrm{DI}^-_t=100\cdot\frac{S_t(\mathrm{DM}^-)}{S_t(\mathrm{TR})}Compute DX from the two dimensionless indices. When their sum is zero, carry forward the previous DX, starting at zero.
\mathrm{DX}_t=100\cdot\frac{\lvert\mathrm{DI}^+_t-\mathrm{DI}^-_t\rvert}{\mathrm{DI}^+_t+\mathrm{DI}^-_t}The first ADX is the average of the first n DX values. Update it using Wilder’s smoothing for each subsequent value. TA-Lib ADX formula
\mathrm{ADX}_t=\frac{(n-1)\cdot\mathrm{ADX}_{t-1}+\mathrm{DX}_t}{n}Loading candle history…
Loading candle history…
Interpreting the ADX
- An ADX value above 25 typically indicates a strong trend.
- An ADX value below 20 signals a weak trend or a ranging market.
- ADX values can help traders avoid false signals by confirming the trend strength.
Use Cases in Algorithmic Trading
In algorithmic trading, the ADX is often used in various strategic approaches, including:
- Trend Following: Algorithms can enter or exit trades based on whether the ADX indicates a strong or weak trend.
- Volatility Filters: ADX values can act as filters to ensure that trades are only initiated when there is sufficient market movement.
- Risk Management: ADX can be used to adjust position sizing according to trend strength to manage risk better.
Limitations of ADX
While the ADX is a valuable tool, it has some limitations:
- Lagging Indicator: Like many trend-following indicators, the ADX is often slow to respond to rapid market changes.
- No Directional Bias: The ADX indicates trend strength but does not specify the direction – traders must use +DI and -DI or other indicators for directional cues.
- Complex Calculation: The multi-step calculation can be complex without software or algorithmic assistance.
Implementation in Trading Algorithms
Python Example
This example uses numpy and TA-Lib. With a period of two, the first ADX is available on the fourth candle.
import numpy as np
import talib
high = np.array([1.20, 1.25, 1.30, 1.35, 1.40])
low = np.array([1.10, 1.15, 1.18, 1.20, 1.25])
close = np.array([1.15, 1.20, 1.25, 1.32, 1.35])
adx = talib.ADX(high, low, close, timeperiod=2)
print(adx[np.isfinite(adx)])
Popular Tools and Platforms that Support ADX
Several financial platforms and tools support the ADX indicator. Notable examples include:
- MetaTrader: One of the most popular trading platforms that offer ADX built-in indicators.
- TradeStation: A comprehensive trading platform that supports advanced indicator scripting, including ADX.
- TradingView: An online platform known for its powerful charting tools and extensive indicator library, including ADX.
Each of these platforms provides customization features allowing traders to tweak ADX settings to fit their trading strategies.
MetaTrader: MetaTrader
TradeStation: TradeStation
TradingView: TradingView
In conclusion, the Average Directional Index (ADX) is an essential tool in the arsenal of both manual and algorithmic traders. It provides a quantitative measure of trend strength, helping traders make informed decisions on market entry and exit points. While it has its limitations, when used correctly, the ADX can significantly enhance the effectiveness of a trading strategy.