How To Use ADX For Market-Conditional Trading

Fri, Sep 29, 2023

Learn about ADX (Average Directional Index) and how you can use it in your trading strategy.

What is ADX?

The Average Directional Index (ADX) is a popular technical indicator used by traders to gauge the strength of a trend, regardless of its direction (upward or downward). It was developed by J. Welles Wilder in the 1970s and is often used in conjunction with two other indicators, the Positive Directional Indicator (+DI) and the Negative Directional Indicator (-DI), to determine the direction of the trend.

How ADX is Calculated:

1. Calculate the True Range (TR): The true range is the greatest of the following three values:

  • The current high minus the current low.
  • The absolute value of the current high minus the previous close.
  • The absolute value of the current low minus the previous close.

2. Calculate the +DM (Positive Directional Movement) and -DM (Negative Directional Movement):

  • +DM = Current High - Previous High (Only consider this value if the current high minus the previous high is greater than the previous low minus the current low.)
  • -DM = Previous Low - Current Low (Only consider this value if the previous low minus the current low is greater than the current high minus the previous high.)

3. Smooth these values

  • This is typically done using a 14-period exponential moving average (though other time frames can be used).

4. Calculate the Directional Indicators (+DI and -DI):

  • +DI = 100 times the smoothed +DM divided by the smoothed TR.
  • -DI = 100 times the smoothed -DM divided by the smoothed TR.

5. Calculate the ADX:

  • ADX = 100 times the exponential moving average of the absolute value of (+DI - -DI) divided by (+DI + -DI).

Interpreting the ADX:

1. Strength of the Trend:

  • Values below 20: Weak trend or ranging market.
  • Values above 20: Strong trend.
  • Values above 40: Very strong trend.

2. Direction of the Trend:

  • +DI and -DI can provide insight into the direction. When +DI is above -DI, the trend is considered bullish, and vice versa.

3. Crossovers:

  • A crossover of +DI above -DI can be a signal of a possible bullish trend starting.
  • A crossover of -DI above +DI can be a signal of a possible bearish trend starting.

Using ADX for Trading:

1. Trend Confirmation:

If you’re considering entering a trade based on another indicator or analysis method, you can use the ADX to confirm the strength of the trend. If ADX is rising and above 20, it indicates a strengthening trend.

2. Avoiding Range-Bound Markets:

If ADX is below 20, it can be a sign that the market is range-bound or consolidating, which may be a signal to avoid trend-following strategies.

3. Trend Direction with +DI and -DI:

Using the crossover of these indicators can help traders identify potential entry or exit points. For example, if +DI crosses above -DI and ADX is rising, this might be a bullish signal.

4. Combining with Other Indicators:

Many traders use ADX in combination with other technical indicators like moving averages, MACD, or RSI to get more comprehensive insights.

Using ADX in your Python trading strategy

Use ADX in your trading strategy to establish current market conditions compared to past data. You can use this to set up conditions for other trading logic.

For example, if the market is “Sideways Up” you may want to trade a smaller position size compared to if it’s “Upward” in this case, or even a completely different strategy.

In this case, we are calling a “sideways” market anything below 40 for ADX and then using +DI and -DI to establish upward or downward movement.

# Calculate ADX, +DI and -DI
adx = talib.ADX(df['high'], df['low'],
    df['close'], timeperiod=14)
plus_di = talib.PLUS_DI(
    df['high'], df['low'], df['close'], timeperiod=14)
minus_di = talib.MINUS_DI(
    df['high'], df['low'], df['close'], timeperiod=14)

# Determine the market condition
last_adx = adx.iloc[-1]
last_plus_di = plus_di.iloc[-1]
last_minus_di = minus_di.iloc[-1]

if (last_adx < 40 and last_plus_di > last_minus_di):
    market_condition = 'Sideways Up'
elif (last_adx < 40 and last_plus_di < last_minus_di):
    market_condition = 'Sideways Down'
elif (last_adx >= 40 and last_plus_di > last_minus_di):
    market_condition = 'Upward'
elif (last_adx >= 40 and last_plus_di < last_minus_di):
    market_condition = 'Downward'

# Strategies based on market condition
if market_condition == 'Sideways Up' or market_condition == 'Sideways Down':
    ### Your trading strategy...
elif market_condition == 'Upward' or market_condition == 'Downward':
    ### Different trading strategy...

Ready to take the next step?

If you're serious about creating a trading bot, consider accessing our tutorials and downloads to learn how to build your own trading bot, platorm or data viewer.

Sign up for a membership today for only $9

Get Full Access

Topics discussed in this article:

Trading StrategiesAverage Directional Index (ADX)
by Nick DeRose

Nick DeRose is the owner of ManicDream. His mission is to teach others about automated trading, python, market trends, and host a platform where people can share their experiences and learn from other traders. His holdings include BTC, ETH, XRP, LINK, DOGE, ADA, and SHIB.