DMI (Directional Movement Index) Format, Label, Watchlist, Scan for ThinkorSwim

Seems to work alright. One thing I noticed is that if both plusDM and minusDM are both 0 then it colors the label red. Not sure if you want that.

To troubleshoot I used. Could have been in one line, I just did it with two.
Code:
AddLabel(yes, "plusDM: " +plusDM+ "", color.gray );
AddLabel(yes, "minusDM: " +minusDM+ "", color.gray );


Altered your label a bit to turn cyan if both are 0 but you can choose whatever color you like.
Code:
AddLabel(yes, "DMI("+length+"):" + Round(DX/ATR,1),(if plusDM > minusDM then Color.GREEN else if minusDM > plusDM then Color.RED else color.cyan));


Is that what you were asking about?

Cheers,
Rick

edited
 
Last edited by a moderator:
Seems to work alright. One thing I noticed is that if both plusDM and minusDM are both 0 then it colors the label red. Not sure if you want that.

To troubleshoot I used. Could have been in one line, I just did it with two.
Code:
AddLabel(yes, "plusDM: " +plusDM+ "", color.gray );
AddLabel(yes, "minusDM: " +minusDM+ "", color.gray );


Altered your label a bit to turn cyan if both are 0 but you can choose whatever color you like.
Code:
AddLabel(yes, "DMI("+length+"):" + Round(DX/ATR,1),(if plusDM > minusDM then Color.GREEN else if minusDM > plusDM then Color.RED else color.cyan));


Is that what you were asking about?

Cheers,
Rick
Thank you so much!! I use dmi with other indicator , I wanted to see where the dmi number is at . Sometimes it shows the correct number but sometimes it don't .
 
Seems to work alright. One thing I noticed is that if both plusDM and minusDM are both 0 then it colors the label red. Not sure if you want that.

To troubleshoot I used. Could have been in one line, I just did it with two.
Code:
AddLabel(yes, "plusDM: " +plusDM+ "", color.gray );
AddLabel(yes, "minusDM: " +minusDM+ "", color.gray );


Altered your label a bit to turn cyan if both are 0 but you can choose whatever color you like.
Code:
AddLabel(yes, "DMI("+length+"):" + Round(DX/ATR,1),(if plusDM > minusDM then Color.GREEN else if minusDM > plusDM then Color.RED else color.cyan));


Is that what you were asking about?

Cheers,
Rick

edited
Hi Rick, I am looking for DMI labels, it seems that you have helped edit the script here. Could you direct me to the message with the corrected script? Thank you.
 
@Jonas99 use this for the way RickAns modded label script

#
# TD Ameritrade IP Company, Inc. (c) 2008-2021
#
declare lower;
input length = 30;
input averageType = AverageType.WILDERS;

def hiDiff = high - high[1];
def loDiff = low[1] - low;

def plusDM = if hiDiff > loDiff and hiDiff > 0 then hiDiff else 0;
def minusDM = if loDiff > hiDiff and loDiff > 0 then loDiff else 0;

def ATR = MovingAverage(averageType, TrueRange(high, close, low), length);
plot "DI+" = 100 * MovingAverage(averageType, plusDM, length) / ATR;
plot "DI-" = 100 * MovingAverage(averageType, minusDM, length) / ATR;

def DX = if ("DI+" + "DI-" > 0) then 100 * AbsValue("DI+" - "DI-") / ("DI+" + "DI-") else 0;

plot ADX = MovingAverage(averageType, DX, length);
"DI+".SetDefaultColor(GetColor(6));
"DI-".SetDefaultColor(GetColor(5));
ADX.SetDefaultColor(GetColor(8));

AddLabel(yes, "plusDM: " +plusDM+ "", color.gray );
AddLabel(yes, "minusDM: " +minusDM+ "", color.gray );
AddLabel(yes, "DMI("+length+"):" + Round(DX/ATR,1),(if plusDM > minusDM then Color.GREEN else if minusDM > plusDM then Color.RED else color.cyan));
 
Last edited:
This is what I use for DM labels. I have been a disciple of Wilder for 30 years. Please feel free to modify as you wish.

Code:
##### Begin Code #####

# SD_DMILabel
# Scott Da####
# Version: 01
# Original: November 17, 2020
# Last Mod: November 17, 2020

declare upper;

input Length = 14;
input DMPDiff = 20;
input DMMDiff = -20;
input DMRev = 30;
input NoiseLimit = 5;
input CrossVal = 2;
input DM_Tradeable = yes;


def DMPlabel = reference DIPlus(Length);
def DMMlabel = reference DIMinus(Length);
def DMDiffCalc = DMPlabel - DMMlabel;

AddLabel(DM_Tradeable, if AbsValue(DMDiffCalc) < NoiseLimit then "    DM NOISY   " + round(DMDiffCalc,0) + "   " else "    DM TRADEABLE   " + round(DMDiffCalc,0) + "   ", if AbsValue(DMDiffCalc) < NoiseLimit then Color.MAGENTA else Color.CYAN);

AddLabel(yes, "           DM PLUS UP          ", if DMPlabel > DMPlabel[1] then Color.GREEN else Color.BLACK);

AddLabel(yes, "           DM MINUS UP           ", if DMMlabel > DMMlabel[1] then Color.RED else Color.BLACK);

#AddLabel(yes, " DM EXTREME  " + round(DMDiffCalc,0), if DMDiffCalc > DMPDiff then Color.GREEN else Color.BLACK);

AddLabel(yes, if AbsValue(DMDiffCalc) > DMRev then " DM CAUTION - REVERSAL " else "",  Color.YELLOW);

AddLabel(yes, if absValue(DMDiffCalc) < CrossVal then "                         WATCH FOR DM CROSS                         " else "", Color.YELLOW);

##### End Code #####
 
Thanks, @s1111, and @RickAns I am looking for a label that displays DMI value on the upper chart only. Can you help?

Here you are for the upper chart Labels

#
# TD Ameritrade IP Company, Inc. (c) 2008-2021
#
input length = 30;
input averageType = AverageType.WILDERS;

def hiDiff = high - high[1];
def loDiff = low[1] - low;

def plusDM = if hiDiff > loDiff and hiDiff > 0 then hiDiff else 0;
def minusDM = if loDiff > hiDiff and loDiff > 0 then loDiff else 0;

def ATR = MovingAverage(averageType, TrueRange(high, close, low), length);
plot "DI+" = 100 * MovingAverage(averageType, plusDM, length) / ATR;
plot "DI-" = 100 * MovingAverage(averageType, minusDM, length) / ATR;

def DX = if ("DI+" + "DI-" > 0) then 100 * AbsValue("DI+" - "DI-") / ("DI+" + "DI-") else 0;
plot ADX = MovingAverage(averageType, DX, length);
"DI+".SetDefaultColor(GetColor(1));
"DI-".SetDefaultColor(GetColor(8));
ADX.SetDefaultColor(GetColor(5));

AddLabel(yes, "plusDM: " +plusDM+ "", color.gray );
AddLabel(yes, "minusDM: " +minusDM+ "", color.gray );
AddLabel(yes, "DMI("+length+"):" + Round(DX/ATR,1),(if plusDM > minusDM then Color.GREEN else if minusDM > plusDM then Color.RED else color.Yellow));
 
Scott and s1111 beat me to it. Jonas, I was going to suggest to comment out the declare lower. As well as the addlabels for plus/minusDM if you did not want them. Also uncheck in settings (or comment out) the plots.

It is real easy to start experimenting with the code. That is how I got started. Wanting custom labels and whatnot. :)
 
Here you are for the upper chart Labels

#
# TD Ameritrade IP Company, Inc. (c) 2008-2021
#
input length = 30;
input averageType = AverageType.WILDERS;

def hiDiff = high - high[1];
def loDiff = low[1] - low;

def plusDM = if hiDiff > loDiff and hiDiff > 0 then hiDiff else 0;
def minusDM = if loDiff > hiDiff and loDiff > 0 then loDiff else 0;

def ATR = MovingAverage(averageType, TrueRange(high, close, low), length);
plot "DI+" = 100 * MovingAverage(averageType, plusDM, length) / ATR;
plot "DI-" = 100 * MovingAverage(averageType, minusDM, length) / ATR;

def DX = if ("DI+" + "DI-" > 0) then 100 * AbsValue("DI+" - "DI-") / ("DI+" + "DI-") else 0;
plot ADX = MovingAverage(averageType, DX, length);
"DI+".SetDefaultColor(GetColor(1));
"DI-".SetDefaultColor(GetColor(8));
ADX.SetDefaultColor(GetColor(5));

AddLabel(yes, "plusDM: " +plusDM+ "", color.gray );
AddLabel(yes, "minusDM: " +minusDM+ "", color.gray );
AddLabel(yes, "DMI("+length+"):" + Round(DX/ATR,1),(if plusDM > minusDM then Color.GREEN else if minusDM > plusDM then Color.RED else color.Yellow));
@s1111 not coming up, could you double check? thanks!
 
# TD Ameritrade IP Company, Inc. (c) 2008-2021
#
input length = 30;
input averageType = AverageType.WILDERS;

def hiDiff = high - high[1];
def loDiff = low[1] - low;

def plusDM = if hiDiff > loDiff and hiDiff > 0 then hiDiff else 0;
def minusDM = if loDiff > hiDiff and loDiff > 0 then loDiff else 0;

def ATR = MovingAverage(averageType, TrueRange(high, close, low), length);
plot "DI+" = 100 * MovingAverage(averageType, plusDM, length) / ATR;
plot "DI-" = 100 * MovingAverage(averageType, minusDM, length) / ATR;

def DX = if ("DI+" + "DI-" > 0) then 100 * AbsValue("DI+" - "DI-") / ("DI+" + "DI-") else 0;
plot ADX = MovingAverage(averageType, DX, length);
"DI+".SetDefaultColor(GetColor(1));
"DI-".SetDefaultColor(GetColor(8));
ADX.SetDefaultColor(GetColor(5));

AddLabel(yes, "plusDM: " +plusDM+ "", color.gray );
AddLabel(yes, "minusDM: " +minusDM+ "", color.gray );
AddLabel(yes, "DMI("+length+"):" + Round(DX/ATR,1),(if plusDM > minusDM then Color.GREEN else if minusDM > plusDM then Color.RED else color.Yellow));
 
I use ADX and and DMI to select stocks. The gap between DMI+ and DMI- is important in my strategy. Currently I cut and paste from the watchlist to Excel. I'd rather create a custom study and perform that math in TOS.

Can somebody please point me in the right direction to get started?
 
Hi Guys,

I have this code on ADX DMI Indicator. Can someone help me to add label to show the below.

1) DMI+ crossover DMI - and vice versa.
2) Shows Strong trend if above 25
3) Maybe something to show me when DMIs are very closed to show neutral trend?

I am not a coder so any help is appreciated.

Code:
# DI, ADX, and Trend Indicator (updated 12/18/13)

declare lower;



input DI_length = 5;

input ADX_length = 13;

input Strong_Trend = 25;



def DX = if (diplus(di_length) + diminus(di_length) > 0) then 100 * AbsValue(diplus(di_length) - diminus(di_length)) / (diplus(di_length) + diminus(di_length)) else 0;

plot ADX = WildersAverage(DX, adx_length);ADX.DefineColor("Stronger", Color.CYAN);

ADX.DefineColor("Weaker", Color.PINK);

ADX.AssignValueColor(if ADX > ADX[1] then ADX.Color("Stronger" ) else ADX.Color("Weaker" ));

ADX.SetPaintingStrategy(PaintingStrategy.LINE);

ADX.SetStyle(Curve.SHORT_DASH);



AddCloud(ADX, 0, ADX.Color("stronger" ));

def weaker = if ADX < ADX[1] then ADX else Double.NaN;

AddCloud(weaker, 0, ADX.Color("weaker" ));



plot "DI+" = DIPlus(DI_length);

"DI+".SetDefaultColor(Color.RED);

"DI+".SetLineWeight(2);



plot "DI-" = DIMinus(DI_length);

"DI-".SetDefaultColor(Color.GREEN);

"DI-".SetLineWeight(2);



plot StrongTrend = Strong_Trend;

StrongTrend.SetDefaultColor(Color.LIGHT_GRAY);
 
Hi Guys,

I have this code on ADX DMI Indicator. Can someone help me to add label to show the below.

1) DMI+ crossover DMI - and vice versa.
2) Shows Strong trend if above 25
3) Maybe something to show me when DMIs are very closed to show neutral trend?

I am not a coder so any help is appreciated.

Code:
# DI, ADX, and Trend Indicator (updated 12/18/13)

declare lower;



input DI_length = 5;

input ADX_length = 13;

input Strong_Trend = 25;



def DX = if (diplus(di_length) + diminus(di_length) > 0) then 100 * AbsValue(diplus(di_length) - diminus(di_length)) / (diplus(di_length) + diminus(di_length)) else 0;

plot ADX = WildersAverage(DX, adx_length);ADX.DefineColor("Stronger", Color.CYAN);

ADX.DefineColor("Weaker", Color.PINK);

ADX.AssignValueColor(if ADX > ADX[1] then ADX.Color("Stronger" ) else ADX.Color("Weaker" ));

ADX.SetPaintingStrategy(PaintingStrategy.LINE);

ADX.SetStyle(Curve.SHORT_DASH);



AddCloud(ADX, 0, ADX.Color("stronger" ));

def weaker = if ADX < ADX[1] then ADX else Double.NaN;

AddCloud(weaker, 0, ADX.Color("weaker" ));



plot "DI+" = DIPlus(DI_length);

"DI+".SetDefaultColor(Color.RED);

"DI+".SetLineWeight(2);



plot "DI-" = DIMinus(DI_length);

"DI-".SetDefaultColor(Color.GREEN);

"DI-".SetLineWeight(2);



plot StrongTrend = Strong_Trend;

StrongTrend.SetDefaultColor(Color.LIGHT_GRAY);
Did you try: https://usethinkscript.com/threads/...atchlist-scan-for-thinkorswim.193/#post-65825
 
Hi guys, I combined the DIPlus and DIminus indicators on TOS and works fine. I need help in creating the signal for the crossovers. Thank you in advance.

declare lower;

input length = 14;
input averageType = AverageType.WILDERS;

plot "DI+" = DMI(length, averageType)."DI+";
"DI+".SetDefaultColor(GetColor(1));

plot "DI-" = DMI(length, averageType)."DI-";
"DI-".SetDefaultColor(GetColor(8));
 
Hi guys, I combined the DIPlus and DIminus indicators on TOS and works fine. I need help in creating the signal for the crossovers. Thank you in advance.

declare lower;

input length = 14;
input averageType = AverageType.WILDERS;

plot "DI+" = DMI(length, averageType)."DI+";
"DI+".SetDefaultColor(GetColor(1));

plot "DI-" = DMI(length, averageType)."DI-";
"DI-".SetDefaultColor(GetColor(8));
Best DMI script is this by @cabe1332 , try it out .

https://usethinkscript.com/threads/adx-dmi-indicator-for-thinkorswim.8055/
 
Hello Everyone,
I don't know how to code but I need your help: there's an existent TOS indicator calls DMI. I played around and came up with this average type: EXPONENTIAL AND length: 4 I would appreciate if anyone can add GREEN SIGNAL ARROW UP when DMX Dl+ Crosse Dl- and it Shows RED ARROW DOWN when Dl- cross Dl+
[Pls look at the image as i made simple and that's something i am looking forward to]
It would be nice to see signals on chart as well on lower indicator too. THANK YOU
agBtP80.png

yrZo5SP.png
 
Last edited by a moderator:
@Montana101x I did use ADX, turned off for plot to mimic your settings, to reduce some noise. have fun.

Ruby:
declare lower;

input length = 4;
input averageType = AverageType.WILDERS;
input HideArrows = No;

def hiDiff = high - high[1];
def loDiff = low[1] - low;

def plusDM = if hiDiff > loDiff and hiDiff > 0 then hiDiff else 0;
def minusDM =  if loDiff > hiDiff and loDiff > 0 then loDiff else 0;

def ATR = MovingAverage(averageType, TrueRange(high, close, low), length);
plot "DI+" = 100 * MovingAverage(averageType, plusDM, length) / ATR;
plot "DI-" = 100 * MovingAverage(averageType, minusDM, length) / ATR;

def DX = if ("DI+" + "DI-" > 0) then 100 * AbsValue("DI+" - "DI-") / ("DI+" + "DI-") else 0;
def ADX = MovingAverage(averageType, DX, length);

"DI+".SetDefaultColor(Color.GREEN);
"DI-".SetDefaultColor(Color.RED);

plot ArrowUp = if ADX >= 25 and "DI+" crosses above "DI-" then "DI-" else Double.NaN;
plot ArrowDn = if ADX >= 25 and "DI-" crosses above "DI+" then "DI+" else Double.NaN;

ArrowUp.SetDefaultColor(Color.GREEN);
ArrowUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
ArrowUp.SetLineWeight(2);
ArrowUp.SetHiding(HideArrows);

ArrowDn.SetDefaultColor(Color.RED);
ArrowDn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ArrowDn.SetLineWeight(2);
ArrowDn.SetHiding(HideArrows);

Alert(ArrowUp, "ArrowUp", Alert.Bar, Sound.Chimes);
Alert(ArrowDn, "ArrowDn", Alert.Bar, Sound.Chimes);
 
Last edited by a moderator:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
261 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top