Updated May 2026: I’ve refreshed this guide with clearer DMI formulas, better notes on +DI and -DI signals, ADX confirmation, DDif, and an updated Python walkthrough.

What Is the Directional Movement Index?
The Directional Movement Index, usually shortened to DMI, is a technical indicator used to compare upward and downward directional movement.
It is closely related to ADX, but it is not the same thing. DMI focuses on direction. ADX focuses on trend strength.
The DMI side of the indicator gives two lines: +DI and -DI. The +DI line measures positive directional movement. The -DI line measures negative directional movement.
When +DI is above -DI, upward directional movement is stronger. When -DI is above +DI, downward directional movement is stronger.
That does not make every crossover a trade. In a choppy market, +DI and -DI can cross repeatedly without price making much progress. DMI is most useful when it is read alongside price structure and, often, ADX.
DMI Indicator at a Glance
DMI has three moving parts that are easy to mix up.
+DI shows positive directional movement.
-DI shows negative directional movement.
ADX shows the strength of the directional environment.
A bullish DMI reading usually means +DI is above -DI. A bearish DMI reading usually means -DI is above +DI. A stronger trend backdrop usually needs ADX to be rising or above a chosen trend-strength threshold.
In practice, +DI and -DI show which side is leading, while ADX helps judge whether that lead has enough force to matter.
Directional Movement Index Formula
Formula key
| Symbol | Meaning |
|---|---|
t | current bar |
t - 1 | previous bar |
n | lookback period, commonly 14 |
Hₜ | current high |
Lₜ | current low |
Cₜ | current close |
Cₜ₋₁ | previous close |
TRₜ | True Range |
Uₜ | upward movement from the previous high |
Dₜ | downward movement from the previous low |
+DMₜ | positive directional movement |
-DMₜ | negative directional movement |
ATRₜ | Wilder-smoothed True Range |
+DIₜ | Positive Directional Indicator |
-DIₜ | Negative Directional Indicator |
DXₜ | directional index used later for ADX |
1. Calculate True Range
True Range measures the largest of three possible ranges. It captures ordinary high-low movement, but it also accounts for gaps from the previous close.
TR_t = \max \left( H_t - L_t,\ \left| H_t - C_{t-1} \right|,\ \left| L_t - C_{t-1} \right| \right)True Range is the largest of current high minus current low, current high minus previous close, or current low minus previous close. The last two use absolute values.
2. Calculate upward and downward movement
The next step checks whether the current bar extended further upward or further downward compared with the previous bar.
U_t = H_t - H_{t-1}Upward movement is current high minus previous high.
D_t = L_{t-1} - L_tDownward movement is previous low minus current low.
3. Calculate +DM and -DM
\text{+DM}_t =
\begin{cases}
U_t, & \text{if } U_t > D_t \text{ and } U_t > 0 \\
0, & \text{otherwise}
\end{cases}+DM counts upward directional movement only when the upward move is both positive and larger than the downward move. Otherwise, +DM is zero.
\text{-DM}_t =
\begin{cases}
D_t, & \text{if } D_t > U_t \text{ and } D_t > 0 \\
0, & \text{otherwise}
\end{cases}-DM counts downward directional movement only when the downward move is both positive and larger than the upward move. Otherwise, -DM is zero.
The minus sign in -DM is a label for downward directional movement. It does not mean the value is negative.
4. Smooth TR, +DM and -DM
Wilder’s method uses smoothing rather than a simple raw sum. After the first seed value, each new smoothed value updates the previous smoothed value with the latest input.
\text{WS}_t = \frac{\text{WS}_{t-1} \times (n - 1) + X_t}{n}Wilder’s smoothed value equals the previous smoothed value multiplied by n minus 1, plus the current value, all divided by n.
In the DMI calculation, this smoothing is applied to True Range, +DM and -DM.
For the first smoothed value, platforms usually seed the calculation with a simple average over the first n periods. Small differences can appear at the start of a chart depending on how a platform handles the warm-up period.
5. Calculate +DI and -DI
The smoothed directional movement values are divided by ATR, which is the smoothed True Range. This normalises the directional movement against recent range size.
\text{+DI}_t = 100 \times \frac{\text{Smoothed +DM}_t}{ATR_t}+DI is smoothed positive directional movement divided by ATR, multiplied by 100.
\text{-DI}_t = 100 \times \frac{\text{Smoothed -DM}_t}{ATR_t}-DI is smoothed negative directional movement divided by ATR, multiplied by 100.
When +DI is above -DI, upward directional movement is stronger. When -DI is above +DI, downward directional movement is stronger.
6. Calculate DX for ADX
DX is not the main DMI signal line, but it connects DMI to ADX. DX measures the distance between +DI and -DI as a percentage of their combined value.
DX_t = 100 \times \frac{\left| \text{+DI}_t - \text{-DI}_t \right|}{\text{+DI}_t + \text{-DI}_t}DX equals the absolute difference between +DI and -DI, divided by the sum of +DI and -DI, multiplied by 100.
ADX then smooths DX to measure trend strength. The DMI lines show which side is leading; ADX shows whether the directional move has strength behind it.
This is the key distinction. DMI gives the directional comparison through +DI and -DI. ADX is derived from that information, but ADX measures strength rather than direction. That is why the two studies are often shown together.
DMI vs ADX
DMI and ADX are closely related, but they answer different questions.
DMI compares positive and negative directional movement. The +DI line shows positive directional movement. The -DI line shows negative directional movement.
ADX is derived from the DMI calculation, but it does not show direction. ADX measures trend strength.
That distinction matters. A chart can have +DI above -DI, which means upward directional movement is stronger, while ADX is still low or falling. That suggests the bullish side is leading, but the trend backdrop may not be strong.
A chart can also have -DI above +DI with ADX rising. That suggests downside directional movement is leading and trend strength is improving.
| Question | Better line to watch | What it tells you |
|---|---|---|
| Which side is leading? | +DI and -DI | Whether positive or negative directional movement is stronger |
| Is upward directional movement stronger? | +DI above -DI | Buyers have the stronger directional movement component |
| Is downward directional movement stronger? | -DI above +DI | Sellers have the stronger directional movement component |
| Is the trend gaining strength? | ADX rising | Directional movement is becoming stronger |
| Is the market losing directional force? | ADX falling | Trend strength may be fading |
For a simple reading, I would start with +DI and -DI. If +DI is above -DI, upward directional movement is leading. If -DI is above +DI, downward directional movement is leading.
Then I would look at ADX. If ADX is rising, the directional move may have more force behind it. If ADX is flat or falling, the DI crossover may be less convincing.
This is why DMI crossovers can be noisy without ADX or price confirmation. The crossover may show a directional shift, but it does not prove that price has enough trend strength to follow through.
How to Interpret DMI Signals
DMI signals come from the relationship between +DI and -DI.
When +DI is above -DI, positive directional movement is stronger. When -DI is above +DI, negative directional movement is stronger.
A crossover can show that leadership has changed, but it should not be treated as a complete trade signal by itself. In a choppy market, +DI and -DI can cross repeatedly while price goes nowhere.
| DMI signal | Possible reading | Main caution |
|---|---|---|
| +DI above -DI | Upward directional movement is stronger | Does not guarantee a strong trend |
| -DI above +DI | Downward directional movement is stronger | Does not guarantee downside follow-through |
| +DI crosses above -DI | Bullish directional shift | Can whipsaw if ADX is low or price is range-bound |
| -DI crosses above +DI | Bearish directional shift | Can arrive late after a sharp move |
| +DI and -DI close together | Directional pressure is unclear | Market may be choppy |
| +DI and -DI separating | Directional pressure is becoming clearer | Still needs price confirmation |
ADX is often used with DMI because it adds the missing trend-strength filter.
If +DI crosses above -DI while ADX is rising, the bullish signal has a stronger trend backdrop. If -DI crosses above +DI while ADX is rising, the bearish signal has a stronger trend backdrop.
If ADX is flat or falling, the crossover deserves more caution. It may show a directional change, but not enough trend strength for a clean follow-through trade.
Price structure still matters. A bullish DMI crossover is more useful if price is also breaking resistance, holding a higher low, or reclaiming a moving average. A bearish crossover is more useful if price is breaking support, forming a lower high, or failing at resistance.
| Setup type | What the trader looks for | Confirmation to watch |
|---|---|---|
| Bullish DMI continuation | +DI above -DI and ADX rising | Higher low, breakout hold, strong close |
| Bearish DMI continuation | -DI above +DI and ADX rising | Lower high, breakdown hold, weak bounce |
| Weak bullish crossover | +DI crosses above -DI while ADX is low | Avoid assuming trend strength |
| Weak bearish crossover | -DI crosses above +DI while ADX is low | Watch for range-bound whipsaw |
| Directional confusion | +DI and -DI keep crossing | Market may lack a clean trend |
The safer habit is to treat DMI as a directional movement tool rather than a mechanical buy/sell system. +DI and -DI can show which side is leading, but ADX and the price chart help decide whether that lead is strong enough to matter.
DMI Indicator Settings and Parameters
The standard DMI setting is usually 14 periods. That is the baseline most traders should understand before changing anything.
The period controls the smoothing window used for True Range, +DM and -DM. A shorter setting makes +DI and -DI react faster. A longer setting makes the lines smoother but slower.
The word period simply means the chart bar being used. On a daily chart, 14 periods means 14 trading days. On a five-minute chart, it means 14 five-minute candles.
The setting does not make DMI automatically better or worse. It changes the balance between responsiveness and noise.
| DMI setting | Behaviour | Possible use | Main trade-off |
|---|---|---|---|
| Shorter than 14 | Faster +DI and -DI movement | Intraday testing, early directional shifts | More whipsaws |
| 14 periods | Common baseline | General chart reading and platform comparison | May lag sharp turns |
| Longer than 14 | Smoother +DI and -DI lines | Swing trading, broader trend filtering | Later confirmation |
| ADX threshold filter | Requires trend strength before acting | Filtering weak DI crossovers | May miss earlier entries |
| Price-structure filter | Requires support, resistance, breakout or pullback confirmation | Reduces mechanical signals | More discretion needed |
There is no single best DMI setting. A lower timeframe futures chart, a daily stock chart and a weekly currency chart may all need different treatment.
If the +DI and -DI lines are crossing constantly, the setting may be too fast for the market, or the market may simply be choppy. If the lines react too slowly, the setting may be too long for the trade horizon.
ADX can act as a filter. A DI crossover with low or falling ADX may be weaker because directional strength is not improving. A crossover with rising ADX may have a stronger trend backdrop.
I would start with the standard 14-period setting, then test changes against that baseline. Changing the setting only because it makes the last few signals look cleaner is usually curve-fitting, not improvement.
| What you see on the chart | Possible issue | What to test |
|---|---|---|
| +DI and -DI cross constantly | Market may be choppy or setting too short | Longer period or stronger ADX filter |
| Signals arrive too late | Setting may be too long | Shorter period or price-structure confirmation |
| +DI leads but ADX falls | Direction exists but strength may be fading | Avoid assuming strong follow-through |
| -DI leads but ADX stays low | Bearish movement leads, but trend may be weak | Wait for price confirmation |
| DI lines separate and ADX rises | Direction and strength are aligning | Look for trend-continuation setups |
The setting should match the job. If DMI is being used for early directional warnings, a faster setup may be worth testing. If it is being used as a trend filter, the standard or a slower setting may be more useful. Either way, the setting should be written down and tested rather than adjusted from chart to chart.
DMI Strategy Examples
A DMI strategy should start with direction, then check strength.
The direction comes from +DI and -DI. If +DI is above -DI, upward directional movement is leading. If -DI is above +DI, downward directional movement is leading.
The strength filter usually comes from ADX. A DI crossover with rising ADX is more useful than a DI crossover with ADX flat or falling.
That does not make the signal automatic. DMI can help identify which side is leading, but the trade still needs price structure, risk control and a reason to enter at that location.
| Strategy idea | What the trader looks for | Main risk |
|---|---|---|
| Bullish DMI continuation | +DI above -DI, ADX rising, price holding higher lows | Entering after the move is already stretched |
| Bearish DMI continuation | -DI above +DI, ADX rising, price holding lower highs | Shorting after the easy part of the move |
| Bullish crossover | +DI crosses above -DI | Whipsaw if ADX is weak |
| Bearish crossover | -DI crosses above +DI | Late signal after a sharp selloff |
| Range filter | +DI and -DI keep crossing | Market may lack a clean trend |
A bullish continuation setup might use DMI after a pullback. If price holds a higher low, +DI remains above -DI, and ADX begins rising, the setup has a stronger directional backdrop than a simple crossover alone.
A bearish continuation setup works the other way. If price forms a lower high, -DI remains above +DI, and ADX rises, the chart may have a cleaner bearish trend backdrop.
Crossovers need more caution. A +DI cross above -DI can mark a bullish shift, but if it happens inside a range with low ADX, the signal may not have enough force. A -DI cross above +DI can mark a bearish shift, but if price is already sitting on support, the entry may be poor.
For range-bound markets, DMI can be more useful as a warning than a trigger. If +DI and -DI keep crossing back and forth, the chart may not be suitable for a trend-following strategy.
| Setup | Possible trigger | Confirmation to watch |
|---|---|---|
| Bullish continuation | +DI stays above -DI after a pullback | Higher low, breakout hold, ADX rising |
| Bearish continuation | -DI stays above +DI after a rally | Lower high, breakdown hold, ADX rising |
| Bullish crossover | +DI crosses above -DI | Price reclaiming resistance or a moving average |
| Bearish crossover | -DI crosses above +DI | Price losing support or failing at resistance |
| No-trade warning | DI lines cross repeatedly | Low ADX, sideways price action, weak follow-through |
The mistake is using DMI as a standalone crossover system. A DI crossover can show a shift in directional movement, but it does not tell you whether the move has enough strength, whether the entry is late, or where the trade should be invalidated.
Understanding DDif, or DMI Difference
DDif, short for Directional Movement Index Difference, is a simple way to turn the two DMI lines into one line.
Instead of plotting +DI and -DI separately, DDif subtracts the -DI line from the +DI line.
If DDif is positive, +DI is above -DI, so upward directional movement is leading.
If DDif is negative, -DI is above +DI, so downward directional movement is leading.
If DDif keeps moving around zero, neither side has a clear directional lead.
\text{DDif}_t = \text{+DI}_t - \text{-DI}_tDDif equals the +DI line minus the -DI line.
The minus sign in -DI is part of the line’s name. It does not mean the value is negative. That is why DDif should be read as “+DI minus the -DI line,” not as a double-negative shortcut.
| DDif reading | What it means | Main caution |
|---|---|---|
| DDif above zero | +DI is above -DI; upward directional movement is leading | Does not guarantee a strong trend |
| DDif below zero | -DI is above +DI; downward directional movement is leading | Does not guarantee downside follow-through |
| DDif crossing above zero | Directional lead shifts toward buyers | Can whipsaw in a range |
| DDif crossing below zero | Directional lead shifts toward sellers | Can arrive late after a sharp drop |
| DDif oscillating around zero | No clear directional lead | Trend-following signals may be weak |
DDif can be useful because it makes the DMI relationship easier to scan. Instead of watching two lines cross, you can watch one line move above or below zero.
The trade-off is that DDif hides some detail. A small positive DDif and a large positive DDif both sit above zero, but they do not show the same degree of separation between +DI and -DI. The slope and distance from zero matter.
ADX can still help. A positive DDif with rising ADX gives a stronger bullish trend backdrop than a positive DDif with falling ADX. A negative DDif with rising ADX gives a stronger bearish trend backdrop than a negative DDif with weak ADX.
| DDif plus ADX condition | Possible interpretation | What I would check |
|---|---|---|
| DDif positive and ADX rising | Bullish directional movement with improving trend strength | Higher lows, breakout hold, resistance above |
| DDif negative and ADX rising | Bearish directional movement with improving trend strength | Lower highs, breakdown hold, support below |
| DDif positive but ADX falling | Buyers lead, but trend strength may be fading | Avoid assuming strong follow-through |
| DDif negative but ADX falling | Sellers lead, but trend strength may be fading | Watch for chop or failed breakdown |
| DDif near zero and ADX low | Direction and strength are both unclear | Trend-following may be poor |
DDif is best treated as a compact DMI spread. It can make directional shifts easier to see, but it still needs ADX, price structure and risk control before it becomes part of a trade plan.
Coding the DMI Indicator with Python
Now we can calculate DMI in Python and plot it on a chart.
The script below calculates +DI, -DI, ADX and DDif from price data. It does not rely on a technical-analysis library, so the code follows the formula section directly.
The chart has four parts: price, volume, DDif, and the DMI/ADX panel.
Step 1: Install the Python libraries
python -m pip install pandas yfinance numpy matplotlib mplfinanceIf your Windows setup uses the py launcher, this version may work better:
py -m pip install pandas yfinance numpy matplotlib mplfinancePandas handles the data table, yfinance downloads price data, NumPy helps with the calculations, matplotlib builds the figure, and mplfinance provides the candlestick plotting function.
Step 2: Create the file and import the libraries
Save a new file as dmi_indicator.py, then paste the following imports at the top.
import numpy as np
import pandas as pd
import yfinance as yf
import matplotlib.pyplot as plt
from mplfinance.original_flavor import candlestick_ohlcStep 3: Add the chart settings
ticker = "^RUT"
display_name = "Russell 2000 Index"
start_date = "2025-05-13"
end_date = "2026-05-13"
dmi_period = 14This example uses ^RUT – Russell 2000 Index with a 14-period DMI. The same script can be reused with another ticker, date range or period by changing these settings.
Step 4: Download the price data
data = yf.download(
ticker,
start=start_date,
end=end_date,
auto_adjust=True,
progress=False,
multi_level_index=False
)
if isinstance(data.columns, pd.MultiIndex):
data.columns = data.columns.get_level_values(0)
data.index = pd.DatetimeIndex(data.index)
data = data.dropna(subset=["Open", "High", "Low", "Close", "Volume"])
if data.empty:
raise ValueError("No price data downloaded. Check the ticker and date range.")The auto_adjust=True setting means the OHLC data is adjusted for splits and dividends. The MultiIndex fallback is included because yfinance can return multi-level columns depending on version and settings.
Step 5: Define Wilder smoothing
def wilder_smoothing(series, period=14):
"""
Wilder-style smoothing.
First smoothed value = simple average of the first valid period.
Later values = (previous smoothed value * (period - 1) + current value) / period.
"""
series = series.astype(float)
smoothed = pd.Series(np.nan, index=series.index)
valid = series.dropna()
if len(valid) < period:
return smoothed
first_valid_pos = series.index.get_loc(valid.index[0])
seed_pos = first_valid_pos + period - 1
if seed_pos >= len(series):
return smoothed
smoothed.iloc[seed_pos] = series.iloc[first_valid_pos:seed_pos + 1].mean()
for i in range(seed_pos + 1, len(series)):
smoothed.iloc[i] = (
smoothed.iloc[i - 1] * (period - 1) + series.iloc[i]
) / period
return smoothedThis function matches the Wilder smoothing used in the formula section. It also explains why the first rows of the output are blank: the indicator needs enough bars to seed the first smoothed value.
Step 6: Calculate +DI, -DI, ADX and DDif
def calculate_dmi(price_data, period=14):
df = price_data.copy()
previous_close = df["Close"].shift(1)
# True Range
tr_1 = df["High"] - df["Low"]
tr_2 = (df["High"] - previous_close).abs()
tr_3 = (df["Low"] - previous_close).abs()
df["TR"] = pd.concat([tr_1, tr_2, tr_3], axis=1).max(axis=1)
# Directional movement
upward_move = df["High"] - df["High"].shift(1)
downward_move = df["Low"].shift(1) - df["Low"]
df["+DM"] = np.where(
(upward_move > downward_move) & (upward_move > 0),
upward_move,
0.0
)
df["-DM"] = np.where(
(downward_move > upward_move) & (downward_move > 0),
downward_move,
0.0
)
# Wilder smoothing
df["ATR"] = wilder_smoothing(df["TR"], period)
df["+DM_smooth"] = wilder_smoothing(df["+DM"], period)
df["-DM_smooth"] = wilder_smoothing(df["-DM"], period)
# Directional indicators
df["+DI"] = 100 * (df["+DM_smooth"] / df["ATR"])
df["-DI"] = 100 * (df["-DM_smooth"] / df["ATR"])
# DDif: +DI minus the -DI line
df["DDif"] = df["+DI"] - df["-DI"]
# DX and ADX
di_sum = df["+DI"] + df["-DI"]
df["DX"] = np.where(
di_sum != 0,
100 * (df["+DI"] - df["-DI"]).abs() / di_sum,
np.nan
)
df["ADX"] = wilder_smoothing(df["DX"], period)
return dfThe DDif line is simply +DI minus -DI. Positive DDif means +DI is leading. Negative DDif means -DI is leading.
ADX is calculated from DX and then Wilder-smoothed. This keeps the code consistent with the DMI and ADX formulas.
Step 7: Add the calculated columns
data = calculate_dmi(data, dmi_period)
plot_data = data.dropna(subset=["+DI", "-DI", "ADX", "DDif"]).copy()
if plot_data.empty:
raise ValueError("Not enough valid data to calculate DMI.")The dropna line removes warm-up rows before plotting. Those blanks are expected because DMI needs enough bars to build the smoothed readings.
Step 8: Prepare the chart data
plot_data["Bar"] = np.arange(len(plot_data))
ohlc = plot_data[["Bar", "Open", "High", "Low", "Close"]].values
volume_colors = np.where(
plot_data["Close"] >= plot_data["Open"],
"green",
"red"
)This prepares the candlestick and volume data for the chart.
Step 9: Create the price, volume, DDif and DMI panels
fig, (ax_price, ax_volume, ax_ddif, ax_dmi) = plt.subplots(
4,
1,
figsize=(12, 8),
sharex=True,
gridspec_kw={
"height_ratios": [4, 1, 1.2, 1.5],
"hspace": 0.0
}
)
fig.suptitle(
f"{display_name} with {dmi_period}-Period DMI, ADX and DDif",
fontsize=12,
fontweight="bold"
)
candlestick_ohlc(
ax_price,
ohlc,
width=0.6,
colorup="green",
colordown="red",
alpha=0.85
)
ax_price.set_ylabel("Price")
ax_price.grid(True, alpha=0.25)
ax_volume.bar(
plot_data["Bar"],
plot_data["Volume"],
color=volume_colors,
width=0.6,
alpha=0.55
)
ax_volume.set_ylabel("Volume")
ax_volume.grid(True, alpha=0.25)
ax_ddif.plot(
plot_data["Bar"],
plot_data["DDif"],
label="DDif",
color="purple",
linewidth=1.2
)
ax_ddif.axhline(
0,
color="black",
linestyle="--",
linewidth=0.9,
alpha=0.8
)
ax_ddif.set_ylabel("DDif")
ax_ddif.legend(loc="upper left", fontsize=8)
ax_ddif.grid(True, alpha=0.25)
ax_dmi.plot(
plot_data["Bar"],
plot_data["+DI"],
label="+DI",
color="green",
linewidth=1.1
)
ax_dmi.plot(
plot_data["Bar"],
plot_data["-DI"],
label="-DI",
color="red",
linewidth=1.1
)
ax_dmi.plot(
plot_data["Bar"],
plot_data["ADX"],
label="ADX",
color="blue",
linewidth=1.2
)
ax_dmi.axhline(20, color="gray", linestyle="--", linewidth=0.8, alpha=0.7)
ax_dmi.axhline(25, color="gray", linestyle=":", linewidth=0.8, alpha=0.7)
ax_dmi.text(
1.002, 25, "25",
transform=ax_dmi.get_yaxis_transform(),
va="center",
fontsize=8,
color="gray"
)
ax_dmi.text(
1.002, 20, "20",
transform=ax_dmi.get_yaxis_transform(),
va="center",
fontsize=8,
color="gray"
)
ax_dmi.set_ylabel("+DI / -DI / ADX")
ax_dmi.legend(loc="upper left", fontsize=8)
ax_dmi.grid(True, alpha=0.25)The DDif panel shows the spread between +DI and -DI. The lower DMI panel shows +DI, -DI and ADX together, with 20 and 25 marked as common trend-strength reference zones.
Step 10: Add date labels, save and show the chart
tick_count = 9
tick_positions = np.linspace(0, len(plot_data) - 1, tick_count, dtype=int)
tick_labels = plot_data.index[tick_positions].strftime("%Y-%m-%d")
ax_dmi.set_xticks(tick_positions)
ax_dmi.set_xticklabels(tick_labels, rotation=45, ha="right")
plt.setp(ax_price.get_xticklabels(), visible=False)
plt.setp(ax_volume.get_xticklabels(), visible=False)
plt.setp(ax_ddif.get_xticklabels(), visible=False)
fig.subplots_adjust(
top=0.91,
bottom=0.14,
left=0.08,
right=0.94,
hspace=0.0
)
output_file = "dmi_ddif_python_chart.png"
fig.savefig(output_file, dpi=150, bbox_inches="tight")
print(f"Saved chart as {output_file}")
plt.show()The script saves the chart as dmi_ddif_python_chart.png and opens the chart window.
Step 11: Run the script
Run the file from VS Code, or use this command in the terminal:
Run the file from VS Code, or use this command in the terminal:If your Windows setup uses the py launcher, use:
py dmi_indicator.pyYou should get a four-panel chart with price, volume, DDif, and DMI/ADX. Positive DDif means +DI is above -DI. Negative DDif means -DI is above +DI.
If all has gone to plan you should have a chart like mine, shown here:

This chart shows why DMI and ADX are useful together. During the stronger advances, DDif moves above zero as +DI leads -DI, while ADX rises toward or above the 20–25 area as trend strength improves. That gives a cleaner bullish backdrop than a positive DDif reading on its own.
The autumn pullback shows the other side. DDif drops below zero as -DI takes the lead, but the trade reading still depends on whether ADX is confirming trend strength or whether the move is only a short-lived rotation.
By the right side of the chart, price has pushed higher again and DDif is positive, while ADX is still around the common trend-strength reference zone. That supports the idea that upward directional movement is leading, but it still needs price structure and risk control before it becomes a trade.
DMI vs MACD, ADX and Moving Averages
DMI is most useful when it has a specific job. It compares positive and negative directional movement.
That makes it different from MACD, moving averages and ADX. MACD tracks moving-average momentum. Moving averages show a trend baseline. ADX measures trend strength without showing direction. DMI sits between those ideas by showing which side has stronger directional movement.
This is why DMI can pair well with other indicators, but it should not be asked to do every job on the chart.
| Indicator | Main job | How it differs from DMI | Useful pairing idea |
|---|---|---|---|
| ADX | Measures trend strength | ADX does not show direction by itself | Use ADX to filter weak DMI crossovers |
| MACD | Tracks moving-average momentum | MACD is based on moving averages, not directional movement | Use MACD for momentum confirmation |
| Moving averages | Show trend baseline | Moving averages smooth price directly | Use them to judge whether DMI agrees with broader trend |
| ATR | Measures volatility | ATR has no directional signal | Use ATR for stop-distance and risk context |
| Price structure | Shows support, resistance and swing behaviour | DMI is indicator-based; structure is chart-based | Use structure to validate DMI signals |
How I Actually Use DMI
I have used DMI for around 25 years, mostly because it was already sitting on the chart screens when I first started on the electronic trading floor.
I began at MacFutures in London in 2002. Back then, the technical-analysis screens I shared were running CQG IC for charts. Execution was on TT X_TRADER, so CQG was there for the charting rather than the actual trading. The DMI setup had been left by the previous trader, who had moved from London to trade in sunny, low-tax Gibraltar.
At first, I did not know much about the indicator’s construction. I am not sure I even knew it was called DMI. But after watching it for long hours every day over the first few months, I started to recognise how it behaved before certain types of move.
That is the point I would keep in mind with DMI. The textbook rules matter, but screen time matters too. Indicators are built with formulas and standard interpretations, yet traders often get more from them by learning how they behave in the markets and timeframes they actually trade.
For me, DMI works especially well beside MACD because they look at different things. DMI shows which side has stronger directional movement. MACD shows whether moving-average momentum is improving or weakening.
The part of DMI I still pay attention to is not only the crossover. When both +DI and -DI are dropping together, it often tells me there is not much conviction on either side. The market can feel thin, choppy, or directionless. In that situation, not trading can be the better trade.
So I would not look for a Directional Movement Index strategy as a fixed recipe. Start with the standard rules, then watch how +DI, -DI, ADX and DDif behave on your own charts. The useful edge, if there is one, usually comes from knowing when the signal is worth acting on and when the market is better left alone.
Frequently Asked Questions about the Directional Movement Index
Q: What is the Directional Movement Index?
The Directional Movement Index, or DMI, is a technical indicator that compares positive and negative directional movement using the +DI and -DI lines.
Q: What does +DI mean?
+DI is the Positive Directional Indicator. It measures upward directional movement after smoothing and normalising the movement by True Range.
Q: What does -DI mean?
-DI is the Negative Directional Indicator. It measures downward directional movement after smoothing and normalising the movement by True Range. The minus sign is part of the line’s name; the value itself is not negative.
Q: What is a DMI crossover?
A DMI crossover happens when +DI crosses above -DI, or when -DI crosses above +DI. It can show a change in directional leadership, but it still needs confirmation from ADX and price structure.
Q: Is DMI the same as ADX?
No. DMI shows which side has stronger directional movement. ADX is derived from DMI and measures trend strength, not direction.
Q: What is the best DMI setting?
The common setting is 14 periods. Shorter settings react faster but create more whipsaws. Longer settings are smoother but react later.
Q: What is DDif?
DDif is the difference between +DI and -DI. A positive DDif means +DI is above -DI. A negative DDif means -DI is above +DI.
Q: Can DMI be used for day trading?
Yes, but short timeframes can be noisy. I would use DMI as a directional filter, then check ADX and price structure before treating a signal as tradable.
Q: Is DMI better than MACD?
Not better, just different. DMI compares directional movement. MACD tracks moving-average momentum. They can be useful together when each one has a clear role.
Final Thoughts
The Directional Movement Index is useful because it separates directional leadership from general price movement.
+DI shows positive directional movement. -DI shows negative directional movement. When one line is above the other, that side has the stronger directional component.
The trap is treating every crossover as a trade. DMI crossovers can whipsaw when the market is choppy or when ADX is weak. A signal becomes more useful when DMI, ADX and price structure point in the same direction.
DDif can make the relationship easier to scan by turning +DI and -DI into one spread-style line. Positive DDif favours +DI. Negative DDif favours -DI. It still needs the same confirmation as the raw DMI lines.
I would use DMI as a directional movement tool, not as a complete trading system. The trade still needs trend strength, price structure, risk control and a clear reason for the entry.
Further Reading
Related AlphaSquawk guides:
ADX, for trend-strength confirmation and the companion indicator to DMI.
MACD, for moving-average momentum and crossover signals.
Moving Averages, for trend direction and baseline filtering.
ATR, for volatility and stop-distance context.
Parabolic SAR, for a price-based stop-and-reversal tool.
Books and references:
Wilder, J. Welles. “New Concepts in Technical Trading Systems.” Trend Research, 1978. This is the original book where Wilder introduced the DMI and several other technical indicators such as ATR, RSI, ASI and SAR.
“Technical Analysis of the Financial Markets”, John J. Murphy.
“Technical Analysis Explained”, Martin J. Pring.




