Multi-Time Frame DMI

Build a powerful DMI breakout indicator, that incorporates multiple time frames to quickly perform technical analysis across multiple charts.

1 hour
Advanced
youtube-video-thumbnail
Table of Contents
    Add a header to begin generating the table of contents
    Table of Contents
      Add a header to begin generating the table of contents

      Understanding the MTF DMI Indicator

      The MTF DMI (Directional Movement Index) Indicator enhances your ability to analyze trends across multiple time frames, offering you insights into bullish, bearish, and neutral zones.

      Using this tutorial, you’ll learn how to build a Multiple Time Frame indicator (17 different time frames, to be exact!) for ThinkOrSwim. This expands upon the original DMI Indicator (shout-out Hubert Senters and Pete Hahn), and allows for it to work  with multiple time frames in ThinkOrSwim (TOS).

      The original Directional Movement Index (DMI) Indicator is popular among momentum and breakout traders. It tracks the strength and direction of trends, helping you determine the prevailing market bias. With the MTF approach, you can see how trends align across time frames from one minute to a month, providing a comprehensive trend analysis tool.

      By the end, you’ll have a versatile tool that adapts across different time periods, helping you optimize your trading strategy.

      Volatility Box Invite

      We are TOS Indicators.com, home of the Volatility Box.

      The Volatility Box is our secret tool, to help us consistently profit from the market place. We’re a small team, and we spend hours every day, after the market close, doing nothing but studying thousands of data points to keep improving and perfecting the Volatility Box price ranges.

      We have two different Volatility Boxes - a Futures Volatility Box and a Stock Volatility Box.

      Futures Volatility Box - Trade Major Markets With an Edge

      Designed For: Futures, Micro-Futures and Index Market Traders
      Supported Models: Hourly Volatility Box models
      Supported Markets: 10 Major Futures Markets

      The Futures Volatility Box comes with:

      • 5 Volatility Models for each market
      • Support for 10 Futures Markets (/ES, /NQ, /YM, /RTY, /CL, /GC, /SI, /ZB, /HG, /NG)
      • Video Setup Guide
      • Trade Plan
      • Access to all members-only resources, including Squeeze Course

      Learn More About the Futures Volatility Box

      Trade futures and micro futures with a consistent volatility edge

      Stock Volatility Box - Powerful Web Based Volatility Platform

      Designed For: Stock and Options Traders
      Supported Models: Hourly and Daily Volatility Box models
      Supported Markets: 10,000+ Stocks and ETFs (new markets added frequently)

      A Stock Volatility Box membership includes access to: 

      • Live Scanner - A powerful scanner we've built from scratch, to scan 10,000 symbols every 2 seconds for new volatility breaches
      • Dashboard - A quick and easy way to view daily volatility model levels online
      • Short Interest Scanner - Short interest, Squeeze, and EMA data to find short squeezes
      • Squeeze Course - All of our proprietary squeeze tools, including robust backtesters
      • All Members Only Indicators - We don't nickel and dime you. Everything really is included.
      • And much more!

      Learn More About the Stock Volatility Box

      Trade stocks and options with a consistent volatility edge

      Concepts That We’ll Focus On

      There are several key concepts that you can expect to take away from this tutorial video:

      • 1. Reading ThinkOrSwim indicator documentation, to understand how to use the given plot code
      • 2. Integrating multiple time frame analysis, on a single chart (to start to use with any indicator)
      • 3. User controlled plots for the colored candles

      Final product preview:

      Step 1: Setting Up Inputs

      Start by defining the inputs for candle coloring, DMI length, ADX levels, and the averaging method:

      
      input coloredCandlesOn = yes;
      input length = 14;
      input ADXLevels = 20;
      input averageType = AverageType.WILDERS;
        

      Here, you’re defining a 14-period length and an ADX level threshold of 20, which means a trend is considered strong if ADX is above 20. The candle coloring option, coloredCandlesOn, lets you toggle the feature on or off for visual clarity.

      Step 2: Monthly DMI Calculations

      Define calculations for the monthly DMI values, which will help you identify long-term trends. This code block will determine if the current trend is bullish, bearish, or neutral.

      
      def monthPlus;
      def monthMinus;
      def monthAdx;
      
      def monthHiDiff = high(period = "Month") - high(period = "Month")[1];
      def monthLoDiff = low(period = "Month")[1] - low(period = "Month");
      def monthPlusDM = if monthHiDiff > monthLoDiff and monthHiDiff > 0 then monthHiDiff else 0;
      def monthMinusDM = if monthLoDiff > monthHiDiff and monthLoDiff > 0 then monthLoDiff else 0;
      monthPlus = 100 * MovingAverage(averageType, monthPlusDM, length);
      monthMinus = 100 * MovingAverage(averageType, monthMinusDM, length);
      monthAdx = MovingAverage(averageType, if (monthPlus + monthMinus > 0) then 100 * AbsValue(monthPlus - monthMinus) / (monthPlus + monthMinus) else 0, length);
        

      This code calculates the directional movement by comparing the current high and low values to the previous month’s values, giving you the +DI and -DI lines.

      Step 3: Weekly DMI Calculations

      Weekly data provides insight into medium-term trends. Similar to the monthly DMI, you’ll calculate the +DI, -DI, and ADX for weekly data:

      
      def weekPlus;
      def weekMinus;
      def weekAdx;
      
      def weekHiDiff = high(period = "Week") - high(period = "Week")[1];
      def weekLoDiff = low(period = "Week")[1] - low(period = "Week");
      def weekPlusDM = if weekHiDiff > weekLoDiff and weekHiDiff > 0 then weekHiDiff else 0;
      def weekMinusDM = if weekLoDiff > weekHiDiff and weekLoDiff > 0 then weekLoDiff else 0;
      weekPlus = 100 * MovingAverage(averageType, weekPlusDM, length);
      weekMinus = 100 * MovingAverage(averageType, weekMinusDM, length);
      weekAdx = MovingAverage(averageType, if (weekPlus + weekMinus > 0) then 100 * AbsValue(weekPlus - weekMinus) / (weekPlus + weekMinus) else 0, length);
        

      Weekly calculations follow the same pattern as monthly ones, comparing current highs and lows with the previous week’s highs and lows to determine directional movement and the ADX value.

      Step 4: Four-Day DMI Calculations

      The four-day period helps you capture trends within the week but is shorter than weekly data, which allows for more frequent updates on trend shifts.

      
      def fourDaysPlus;
      def fourDaysMinus;
      def fourDaysAdx;
      
      def fourDaysHiDiff = high(period = "4 Days") - high(period = "4 Days")[1];
      def fourDaysLoDiff = low(period = "4 Days")[1] - low(period = "4 Days");
      def fourDaysPlusDM = if fourDaysHiDiff > fourDaysLoDiff and fourDaysHiDiff > 0 then fourDaysHiDiff else 0;
      def fourDaysMinusDM = if fourDaysLoDiff > fourDaysHiDiff and fourDaysLoDiff > 0 then fourDaysLoDiff else 0;
      fourDaysPlus = 100 * MovingAverage(averageType, fourDaysPlusDM, length);
      fourDaysMinus = 100 * MovingAverage(averageType, fourDaysMinusDM, length);
      fourDaysAdx = MovingAverage(averageType, if (fourDaysPlus + fourDaysMinus > 0) then 100 * AbsValue(fourDaysPlus - fourDaysMinus) / (fourDaysPlus + fourDaysMinus) else 0, length);
        

      Using the same format as in the previous sections, this block captures the four-day trend by comparing price differences and determining if the trend is strong enough based on the ADX value.

      Step 5: Three-Day DMI Calculations

      The three-day period offers even more granularity, allowing you to see shorter-term trends while smoothing over daily fluctuations.

      
      def threeDaysPlus;
      def threeDaysMinus;
      def threeDaysAdx;
      
      def threeDaysHiDiff = high(period = "3 Days") - high(period = "3 Days")[1];
      def threeDaysLoDiff = low(period = "3 Days")[1] - low(period = "3 Days");
      def threeDaysPlusDM = if threeDaysHiDiff > threeDaysLoDiff and threeDaysHiDiff > 0 then threeDaysHiDiff else 0;
      def threeDaysMinusDM = if threeDaysLoDiff > threeDaysHiDiff and threeDaysLoDiff > 0 then threeDaysLoDiff else 0;
      threeDaysPlus = 100 * MovingAverage(averageType, threeDaysPlusDM, length);
      threeDaysMinus = 100 * MovingAverage(averageType, threeDaysMinusDM, length);
      threeDaysAdx = MovingAverage(averageType, if (threeDaysPlus + threeDaysMinus > 0) then 100 * AbsValue(threeDaysPlus - threeDaysMinus) / (threeDaysPlus + threeDaysMinus) else 0, length);
        

      Again, you’re comparing current highs and lows with the previous three days to identify the direction of the trend. The ADX value helps determine if the trend is strong enough to be meaningful.

      Step 6: Two-Day DMI Calculations

      In the two-day DMI calculation, you’ll capture very short-term trends. This is especially useful for day traders who want to get a sense of recent momentum shifts.

      
      def twoDaysPlus;
      def twoDaysMinus;
      def twoDaysAdx;
      
      def twoDaysHiDiff = high(period = "2 Days") - high(period = "2 Days")[1];
      def twoDaysLoDiff = low(period = "2 Days")[1] - low(period = "2 Days");
      def twoDaysPlusDM = if twoDaysHiDiff > twoDaysLoDiff and twoDaysHiDiff > 0 then twoDaysHiDiff else 0;
      def twoDaysMinusDM = if twoDaysLoDiff > twoDaysHiDiff and twoDaysLoDiff > 0 then twoDaysLoDiff else 0;
      twoDaysPlus = 100 * MovingAverage(averageType, twoDaysPlusDM, length);
      twoDaysMinus = 100 * MovingAverage(averageType, twoDaysMinusDM, length);
      twoDaysAdx = MovingAverage(averageType, if (twoDaysPlus + twoDaysMinus > 0) then 100 * AbsValue(twoDaysPlus - twoDaysMinus) / (twoDaysPlus + twoDaysMinus) else 0, length);
        

      This two-day data aggregation makes it easier to see recent directional shifts while smoothing over single-day noise, helping to identify early trends as they begin to form.

      Labeling Zones

      For each time frame, you can now add labels to denote bullish, bearish, or neutral zones. For example, for the monthly time frame:

      
      AddLabel(monthBullishZone, "M", Color.GREEN);
      AddLabel(monthBearishZone, "M", Color.RED);
      AddLabel(monthNeutralZone, "M", Color.YELLOW);
        

      Repeat this process for all other time frames using corresponding variables, e.g., weekBullishZone, weekBearishZone, and so on.

      Final Thoughts

      The MTF DMI indicator offers a comprehensive view of trends across multiple time frames, making it a powerful tool for any trading strategy. You’ve just built a custom indicator that lets you spot momentum and trend shifts with ease, all within a single chart.

      downloads

      Download the Multi-Time Frame DMI Indicator for ThinkorSwim.

      The download contains a STUDY.ts file, which you can directly import into your ThinkOrSwim platform.

      Download Indicator

      Download the Multi-Time Frame DMI Indicator for ThinkorSwim.

      The download contains a STUDY.ts file, which you can directly import into your ThinkOrSwim platform.

      Have your own idea?

      Let us help you turn your trading strategy into a powerful indicator, scan and backtester.