OPEN-SOURCE SCRIPT
Directional Movement Index - DMI | TR

🎯 Overview
Directional Movement Index - DMI | TR is a comprehensive trend strength and direction indicator that measures the strength and direction of price movement. Developed by Tiagorocha1989, this enhanced version of Welles Wilder's classic DMI system offers multiple visualization modes, customizable moving averages, and comprehensive visual features to help traders identify trend direction, measure trend strength, and generate clear entry and exit signals.
🔧 How It Works
The DMI system consists of three key components: the Positive Directional Indicator (+DI), the Negative Directional Indicator (-DI), and the Average Directional Index (ADX). The relationship between +DI and -DI determines trend direction, while ADX measures trend strength regardless of direction.
Core Calculation Logic:
The indicator calculates directional movement by comparing current price highs and lows with previous periods to determine:
+DI (Positive Directional Indicator): Measures upward price pressure
-DI (Negative Directional Indicator): Measures downward price pressure
ADX (Average Directional Index): Smoothed average of the directional movement, indicating trend strength
The relationship between +DI and -DI creates the primary signals:
When +DI crosses above -DI → Bullish trend developing
When -DI crosses above +DI → Bearish trend developing
The spread between them indicates trend strength
Additionally, the indicator calculates DMI as the difference between +DI and -DI (+DI minus -DI), creating an oscillator that oscillates around zero:
Positive DMI values → Bullish momentum ( +DI above -DI)
Negative DMI values → Bearish momentum (-DI above +DI)
✨ Key Features
🔹 Multiple Display Modes
DMI Average Mode: Shows the DMI oscillator (+DI minus -DI) with signal line, providing a clean, oscillator-style view of directional balance
Normal DMI Mode: Displays the classic +DI and -DI lines for traditional analysis
ADX Mode: Shows the Average Directional Index for trend strength measurement
All modes can be combined for comprehensive analysis
🔹 Dual Operating Modes for Signals
Zero Line Mode: Signals occur when the DMI oscillator crosses above or below the zero line
DMI MA Mode: Enhanced mode where signals occur when DMI crosses its own moving average, providing filtered entries
🔹 Flexible Moving Average Selection
Choose from six MA types for the DMI MA mode:
EMA, SMA, RMA, WMA, VWMA, and HMA
🔹 Customizable DMI Parameters
Length: Lookback period for DMI calculation (default 8)
ADX Smoothing: Additional smoothing for ADX calculation (default 1)
🔹 Customizable Color Themes
Eight distinct color schemes to match your charting preferences:
Classic – Green for bullish, Red for bearish
Modern – White for bullish, Purple for bearish
Robust – Amber for bullish, Maroon for bearish
Accented – Violet for bullish, Pink for bearish
Monochrome – Light gray for bullish, Dark gray for bearish
Moderate – Green for bullish, Red for bearish
Aqua – Blue for bullish, Orange for bearish
Cosmic – Pink for bullish, Purple for bearish
🔹 Comprehensive Visual Feedback
DMI Oscillator: Colored line showing the difference between +DI and -DI
Signal Line: Yellow line for MA-based signals
Gradient Fill Zones: Clear visualization of extreme readings
Dynamic Zone Fills: Semi-transparent fills showing when DMI is above or below the signal line
+DI and -DI Lines: Optional display of classic directional indicators
ADX Line: Optional blue line showing trend strength
Color-Coded Candles: Bars reflect current trend direction based on +DI/-DI relationship
Signal Markers: Triangle up/down symbols at crossover points
Live Value Display: Floating labels showing current values for each enabled component
Trend Table: Bullish/Bearish status displayed on the chart
🔹 Ready-to-Use Alerts
Built-in alert conditions trigger LONG signals when +DI crosses above -DI, and SHORT signals when +DI crosses below -DI.
⚙️ Settings Summary
Color Choice: Select from eight visual themes (Default: Classic)
DMI Display: Toggle to show the DMI Average oscillator (Default: Enabled)
Length: Lookback period for DMI calculation (Default: 8)
Entry/Exit Signal: Choose between zero line or DMI MA mode (Default: Zero Line)
Length MA: Moving average period for DMI MA mode (Default: 365)
DMI MA Type: Moving average method for signal line (Default: EMA)
Normal DMI: Toggle to show classic +DI and -DI lines (Default: Disabled)
ADX Smoothing: Toggle to show ADX with adjustable smoothing (Default: Disabled)
📈 Practical Applications
🔹 Trend Direction Identification
The primary use of the DMI system is identifying trend direction:
+DI above -DI → Bullish trend
-DI above +DI → Bearish trend
The wider the separation, the stronger the trend
🔹 Trend Strength Measurement
The ADX component quantifies trend strength regardless of direction:
ADX below 20 → Weak or non-trending market
ADX between 20-40 → Trending market with moderate strength
ADX above 40 → Strong trend (can signal trend exhaustion in some cases)
🔹 Crossover Signals
Crossovers between +DI and -DI provide classic entry signals:
+DI crosses above -DI → Potential LONG entry
-DI crosses above +DI → Potential SHORT entry
🔹 DMI Oscillator Analysis
The DMI oscillator (+DI minus -DI) offers additional insights:
Positive values indicate bullish dominance
Negative values indicate bearish dominance
Crossovers of the zero line confirm trend changes
Crossovers of the moving average provide filtered signals
🔹 Trend Exhaustion Detection
When ADX reaches very high levels (above 50-60) after a prolonged trend, it may indicate trend exhaustion and potential reversal. Combined with a narrowing spread between +DI and -DI, this can signal trend weakening.
🔹 Multiple Timeframe Confirmation
Compare DMI readings across different timeframes:
Higher timeframe DMI confirms primary trend direction
Lower timeframe DMI identifies entry timing
🎯 Ideal For
✅ Trend Traders seeking to identify and follow established trends
✅ Swing Traders wanting to capture medium-term directional moves
✅ System Developers needing reliable trend direction signals
✅ Multi-Timeframe Analysts comparing trend strength across periods
✅ Risk Managers assessing whether markets are trending or ranging
📌 Key Takeaways
Comprehensive Trend Analysis: Combines direction (+DI/-DI), strength (ADX), and oscillator views in one indicator
Multiple Display Modes: Choose between classic +DI/-DI lines, DMI oscillator, or ADX based on your analysis style
Dual-Mode Signal Generation: Zero line crossovers for classic signals or MA-smoothed signals for filtered entries
Rich Visual Feedback: Color themes, gradient fills, candles, and floating labels provide immediate market awareness
Alert-Ready: Built-in alerts for trend change signals when +DI crosses -DI
⚠️ Important Notes
The DMI system works best in trending markets and can produce false signals in ranging conditions. ADX does not indicate direction, only strength; always use it in conjunction with +DI/-DI. The 365-day MA default in DMI MA mode is designed for longer-term trend context on daily charts. Consider using ADX above 20-25 to filter for trending conditions before taking crossover signals. Always combine with proper risk management and additional confirmation for best results.
Disclaimer: This indicator is provided for educational and informational purposes only. Past performance is not indicative of future results. Always conduct thorough testing and align with your risk management strategy before live deployment.
Directional Movement Index - DMI | TR is a comprehensive trend strength and direction indicator that measures the strength and direction of price movement. Developed by Tiagorocha1989, this enhanced version of Welles Wilder's classic DMI system offers multiple visualization modes, customizable moving averages, and comprehensive visual features to help traders identify trend direction, measure trend strength, and generate clear entry and exit signals.
🔧 How It Works
The DMI system consists of three key components: the Positive Directional Indicator (+DI), the Negative Directional Indicator (-DI), and the Average Directional Index (ADX). The relationship between +DI and -DI determines trend direction, while ADX measures trend strength regardless of direction.
Core Calculation Logic:
The indicator calculates directional movement by comparing current price highs and lows with previous periods to determine:
+DI (Positive Directional Indicator): Measures upward price pressure
-DI (Negative Directional Indicator): Measures downward price pressure
ADX (Average Directional Index): Smoothed average of the directional movement, indicating trend strength
The relationship between +DI and -DI creates the primary signals:
When +DI crosses above -DI → Bullish trend developing
When -DI crosses above +DI → Bearish trend developing
The spread between them indicates trend strength
Additionally, the indicator calculates DMI as the difference between +DI and -DI (+DI minus -DI), creating an oscillator that oscillates around zero:
Positive DMI values → Bullish momentum ( +DI above -DI)
Negative DMI values → Bearish momentum (-DI above +DI)
✨ Key Features
🔹 Multiple Display Modes
DMI Average Mode: Shows the DMI oscillator (+DI minus -DI) with signal line, providing a clean, oscillator-style view of directional balance
Normal DMI Mode: Displays the classic +DI and -DI lines for traditional analysis
ADX Mode: Shows the Average Directional Index for trend strength measurement
All modes can be combined for comprehensive analysis
🔹 Dual Operating Modes for Signals
Zero Line Mode: Signals occur when the DMI oscillator crosses above or below the zero line
DMI MA Mode: Enhanced mode where signals occur when DMI crosses its own moving average, providing filtered entries
🔹 Flexible Moving Average Selection
Choose from six MA types for the DMI MA mode:
EMA, SMA, RMA, WMA, VWMA, and HMA
🔹 Customizable DMI Parameters
Length: Lookback period for DMI calculation (default 8)
ADX Smoothing: Additional smoothing for ADX calculation (default 1)
🔹 Customizable Color Themes
Eight distinct color schemes to match your charting preferences:
Classic – Green for bullish, Red for bearish
Modern – White for bullish, Purple for bearish
Robust – Amber for bullish, Maroon for bearish
Accented – Violet for bullish, Pink for bearish
Monochrome – Light gray for bullish, Dark gray for bearish
Moderate – Green for bullish, Red for bearish
Aqua – Blue for bullish, Orange for bearish
Cosmic – Pink for bullish, Purple for bearish
🔹 Comprehensive Visual Feedback
DMI Oscillator: Colored line showing the difference between +DI and -DI
Signal Line: Yellow line for MA-based signals
Gradient Fill Zones: Clear visualization of extreme readings
Dynamic Zone Fills: Semi-transparent fills showing when DMI is above or below the signal line
+DI and -DI Lines: Optional display of classic directional indicators
ADX Line: Optional blue line showing trend strength
Color-Coded Candles: Bars reflect current trend direction based on +DI/-DI relationship
Signal Markers: Triangle up/down symbols at crossover points
Live Value Display: Floating labels showing current values for each enabled component
Trend Table: Bullish/Bearish status displayed on the chart
🔹 Ready-to-Use Alerts
Built-in alert conditions trigger LONG signals when +DI crosses above -DI, and SHORT signals when +DI crosses below -DI.
⚙️ Settings Summary
Color Choice: Select from eight visual themes (Default: Classic)
DMI Display: Toggle to show the DMI Average oscillator (Default: Enabled)
Length: Lookback period for DMI calculation (Default: 8)
Entry/Exit Signal: Choose between zero line or DMI MA mode (Default: Zero Line)
Length MA: Moving average period for DMI MA mode (Default: 365)
DMI MA Type: Moving average method for signal line (Default: EMA)
Normal DMI: Toggle to show classic +DI and -DI lines (Default: Disabled)
ADX Smoothing: Toggle to show ADX with adjustable smoothing (Default: Disabled)
📈 Practical Applications
🔹 Trend Direction Identification
The primary use of the DMI system is identifying trend direction:
+DI above -DI → Bullish trend
-DI above +DI → Bearish trend
The wider the separation, the stronger the trend
🔹 Trend Strength Measurement
The ADX component quantifies trend strength regardless of direction:
ADX below 20 → Weak or non-trending market
ADX between 20-40 → Trending market with moderate strength
ADX above 40 → Strong trend (can signal trend exhaustion in some cases)
🔹 Crossover Signals
Crossovers between +DI and -DI provide classic entry signals:
+DI crosses above -DI → Potential LONG entry
-DI crosses above +DI → Potential SHORT entry
🔹 DMI Oscillator Analysis
The DMI oscillator (+DI minus -DI) offers additional insights:
Positive values indicate bullish dominance
Negative values indicate bearish dominance
Crossovers of the zero line confirm trend changes
Crossovers of the moving average provide filtered signals
🔹 Trend Exhaustion Detection
When ADX reaches very high levels (above 50-60) after a prolonged trend, it may indicate trend exhaustion and potential reversal. Combined with a narrowing spread between +DI and -DI, this can signal trend weakening.
🔹 Multiple Timeframe Confirmation
Compare DMI readings across different timeframes:
Higher timeframe DMI confirms primary trend direction
Lower timeframe DMI identifies entry timing
🎯 Ideal For
✅ Trend Traders seeking to identify and follow established trends
✅ Swing Traders wanting to capture medium-term directional moves
✅ System Developers needing reliable trend direction signals
✅ Multi-Timeframe Analysts comparing trend strength across periods
✅ Risk Managers assessing whether markets are trending or ranging
📌 Key Takeaways
Comprehensive Trend Analysis: Combines direction (+DI/-DI), strength (ADX), and oscillator views in one indicator
Multiple Display Modes: Choose between classic +DI/-DI lines, DMI oscillator, or ADX based on your analysis style
Dual-Mode Signal Generation: Zero line crossovers for classic signals or MA-smoothed signals for filtered entries
Rich Visual Feedback: Color themes, gradient fills, candles, and floating labels provide immediate market awareness
Alert-Ready: Built-in alerts for trend change signals when +DI crosses -DI
⚠️ Important Notes
The DMI system works best in trending markets and can produce false signals in ranging conditions. ADX does not indicate direction, only strength; always use it in conjunction with +DI/-DI. The 365-day MA default in DMI MA mode is designed for longer-term trend context on daily charts. Consider using ADX above 20-25 to filter for trending conditions before taking crossover signals. Always combine with proper risk management and additional confirmation for best results.
Disclaimer: This indicator is provided for educational and informational purposes only. Past performance is not indicative of future results. Always conduct thorough testing and align with your risk management strategy before live deployment.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.