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

The DMI indicator (Directional Movement Index) will tell you which direction the price of a stock is moving. When the +DI line is above the -DI line, it means there is more upward movement than downward and vice versa.

The way I use the DMI is a bit different. Instead of using this indicator to tell bullish or bearish trend, I use it as a sideways detector. When the two lines are moving next to each other, it's telling me that the market is choppy at the moment.

Here is an example on the $BYND chart:

I99Lf1J.png


The DMI indicator is available right inside ThinkorSwim. You can just add it without additional code. To make things a bit easier on my part, I asked @WalkingBallista if it was possible to make a Watchlist column that displays the range between the DMI lines. The closer they are to each other the more likely that the stock isn't moving anywhere. And of course, he said yes.

Here is the DMI Range watchlist column for anyone interested.

iBDu6uI.png


thinkScript Code

Rich (BB code):
# WalkingBallista DMI Range
# https://usethinkscript.com/d/193-dmi-directional-movement-index-watchlist-for-thinkorswim

input length = 14;
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);
def "DI+" = 100 * MovingAverage(averageType, plusDM, length) / ATR;
def "DI-" = 100 * MovingAverage(averageType, minusDM, length) / ATR;

plot range = AbsValue(AbsValue("DI+")-AbsValue("DI-"));

Shareable Link

https://tos.mx/IgnhP6
is there any way to create a color coded watchlist column? green for DMI up and red for DMI down? DMI only not ADX combo
 

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

Hey there!

Ive been beating my head against the wall on some simple *** issue, and had given up all hope...and then I remembered this site that is full of coding geniuses who are glad to help us dumb shits out with the technicals... pretty straight forward, Im looking to AddCloud to the DMI...green in between when D+ is over D-, and red in between when D+ is under D-... here is what i got so far but Im getting error after error....Thanks a ton to whomever feels generous enough to situate this for me...

declare lower;


input length = 14;
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));

plot "D+" = close;
plot "D-" = close(10);
AddCloud ("D+", "D-" , Color.GREEN, Color.RED);
 
declare lower;

input length = 14;
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 DIplus = 100 * MovingAverage(averageType, plusDM, length) / ATR;
plot DIminus = 100 * MovingAverage(averageType, minusDM, length) / ATR;

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


DIplus.SetDefaultColor(GetColor(1));
DIminus.SetDefaultColor(GetColor(8));
ADX.SetDefaultColor(GetColor(5));

AddCloud (DIplus, DIminus , Color.GREEN, Color.RED);



I posted it on my github:
https://github.com/ConnorSmiley/UseThinkScript/blob/main/DMI Cloud
 
Last edited:
You shouldn't define variables as a string. It said (plot "D+" = close; && plot "D-" = close(10);) were already defined. I deleted, seemed to work
 
Is it possible or is there a code for a DMI label that measures the difference between the DMI+ and the DMI- readings?
 
This what you mean?

Ruby:
def DMIPlus = DMI(14,"Wilders")."DI+";
def DMINeg = DMI(14,"Wilders")."DI-";
def DMIDiff = DMIPlus - DMINeg;

AddLabel(1, "DMI Diff is "+ DMIDiff, if DMIDiff > 0 then color.green else if DMIDiff < 0 then color.red else color.gray);
 
Hi guys,

Think this is my first post after lurking for a long time. thanks for being here and everything y'all post!

I am trying to clean up and fix whats not working in my below code -

Issues:
1 - When DI+ is above or below Over Sold or Over Bought I have Upsignal and Downsignal arrows, but I Truly only want an arrow when the DI+ is extended beyond the over bought value and reversing lower then the previous closed DI+ value in the last candle to have an arrow, not a bunch of arrows. Vice versa issue for Over bought, I am trying to get only 1 arrow to show when the DI+ is reversing and beyond the Over Sold value line and now reversing higher then the previous DI+ value to have an arrow close in that candle time frame.

2. My chart alerts are not going off when an arrow is showing! If anyone can fix my chart alert code to go off when an arrow is showing, I'd appreciate it.

3. DI+ Bullish and bearish Divergences. I would love to be able to see DI+ Divergences. Bullish Divergence when The stock price having found a previous low, went up and now creating a new lower low, but the DI+ is showing and closing higher then DI+ found at previous low.
Bearish divergences when the stock price had a high, went down, and now creating a new high. It would be nice to see DI+ Divergences when the DI+ is now lower at the new high then what it was when stock price was previous high.

Alot to ask, but I can provide coffee as needed! Thank you so much for even reading this!

I posted my example of divergences to explain myself better in red lines. and my terrible arrows that need help fixing so they dont repeat!

9lnT19D.png




Code:
declare lower;

input length = 14;
input averageType = AverageType.WILDERS;
input over_Sold = 15;
input over_Bought = 70;

plot oversold = over_Sold;
plot overbought = over_Bought;

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));

plot UpSignal = if "DI+" < over_Sold then "DI+" else Double.NaN;
plot DownSignal = if "DI+" > over_bought then "DI+" else Double.NaN;

UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

Alert((UpSignal) or (DownSignal), GetSymbol() + "DI+ Alert", Alert.BAR, Sound.Ring);
refine the DI+ from the DMI TOS default indicator.
 
my terrible arrows that need help fixing so they dont repeat!

Not sure what you are asking.
Your question is how to print only one arrow? And the one arrow needs to be the last arrow?

Replace your arrow plots with:
Code:
plot UpSignal = if "DI+"[1]  crosses above over_Sold and  then "DI+" else Double.NaN;
plot DownSignal = if "DI+" crosses below over_bought then "DI+" else Double.NaN;
 
Does Anyone know how to Plot Lines For Scanning Purposes For "Stronger" Cyan And "Weaker" White... Thanks

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.white);

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.green);

"DI+".SetLineWeight(2);



plot "DI-" = DIMinus(DI_length);

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

"DI-".SetLineWeight(2);



plot StrongTrend = Strong_Trend;

StrongTrend.SetDefaultColor(Color.Black);
 
Does Anyone know how to Plot Lines For Scanning Purposes For "Stronger" Cyan And "Weaker" White... Thanks

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.white);

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.green);

"DI+".SetLineWeight(2);



plot "DI-" = DIMinus(DI_length);

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

"DI-".SetLineWeight(2);



plot StrongTrend = Strong_Trend;

StrongTrend.SetDefaultColor(Color.Black);
Ruby:
plot scan_stronger = ADX > ADX[1] ;
#or
plot scan_weaker = ADX <= ADX[1] ;
 
Hi all,
I am asking if one of you code masters could modify the TOS DMI indicator for me. What I want is a marker (of some sort) on the price chart when the DI+ DI- lines cross. The screenshot gives you an idea of what I am asking for. An alert would be helpful too, but don't want to take advantage of anyone.

/DMI.png

thanks in advance...
 
Last edited by a moderator:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
270 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