Pine Script ta.dmi: Guide & Strategies
The Directional Movement Index (DMI) is a widely used technical analysis indicator that measures both the strength and direction of price trends. In TradingView's Pine Script, the ta.dmi()
function simplifies the process of integrating this powerful tool into custom indicators and strategies. This article will provide an in-depth exploration of the ta.dmi()
function, its syntax, practical applications, and how to use it effectively in trading strategies.
What is the Directional Movement Index (DMI)?
The Directional Movement Index (DMI), developed by J. Welles Wilder in 1978, is a trend-following indicator that evaluates the strength and direction of a market trend. It consists of three components:
- +DI (Positive Directional Indicator): Measures upward price movement.
- DI (Negative Directional Indicator): Measures downward price movement.
- ADX (Average Directional Index): Quantifies the strength of the trend, regardless of its direction.
Key Features

- The DMI helps traders identify whether a market is trending or ranging.
- Crossovers between +DI and -DI generate potential buy or sell signals.
- The ADX value indicates trend strength:
- ADX > 25: Strong trend.
- ADX < 20: Weak or no trend.
Understanding ta.dmi()
in Pine Script
The ta.dmi()
function in Pine Script simplifies the calculation of DMI components and integrates them into custom indicators or strategies.
Syntax
ta.dmi(diLength, adxSmoothing) → [series float, series float, series float]
Arguments
diLength
(int): The period for calculating +DI and -DI values.adxSmoothing
(int): The smoothing period for the ADX calculation.
Returns
A tuple containing three series:
+DI
(Positive Directional Indicator)DI
(Negative Directional Indicator)ADX
(Average Directional Index)
Example: Creating a DMI Indicator
Below is an example of how to use ta.dmi()
to create a DMI indicator in Pine Script:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Pineify
//======================================================================//
// ____ _ _ __ //
// | _ \(_)_ __ ___(_)/ _|_ _ //
// | |_) | | '_ \ / _ \ | |_| | | | //
// | __/| | | | | __/ | _| |_| | //
// |_| |_|_| |_|\___|_|_| \__, | //
// |___/ //
//======================================================================//
//@version=6
indicator(title="[Pineify - Best Pine Script Generator] Directional Movement Index", shorttitle="DMI", format=format.price, precision=4)
// Input parameters
diLength = input.int(17, minval=1, title="DI Length")
adxSmoothing = input.int(14, minval=1, maxval=50, title="ADX Smoothing")
// Calculate DMI components
[diplus, diminus, adx] = ta.dmi(diLength, adxSmoothing)
// Plot the results
plot(adx, color=color.red, title="ADX")
plot(diplus, color=color.blue, title="+DI")
plot(diminus, color=color.orange, title="-DI")
