Joe Rabil ADX For ThinkOrSwim

@cswu1211 here is a version of Joe Rabil's ADX/DMI study I crafted together. Use at your own risk... ;)

lngWw8E.png

Code:
#
# An implementatio of ADX and DI+/- based on following Joe Rabil
#
# customized with cross line and individual DMI and ADX lengths

declare lower;

script func_DMI {
input length_di = 14; #DI+- length
input length_adx = 14; #ADX length
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_di);
plot "DI+" = 100 * MovingAverage(averageType, plusDM, length_di) / ATR;
plot "DI-" = 100 * MovingAverage(averageType, minusDM, length_di) / ATR;

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

};

input di_length = 13;  #original 14  Use Joe's 13 and 8
input adx_length = 8;  #original 14
input averageType = AverageType.WILDERS;

#add cross line
input crossline = 25;
input showlabels = yes; #show labels

#CORE
DefineGlobalColor("Bullish", Color.GREEN);
DefineGlobalColor("Bearish", Color.RED);
DefineGlobalColor("Neutral", Color.dark_orange);

plot "DI+" = func_DMI(di_length, adx_length, averageType)."DI+";
plot "DI-" = func_DMI(di_length, adx_length, averageType)."DI-";

def ADXfast = func_DMI(di_length, adx_length, averageType)."ADX";
plot ADX = ADXfast;

"DI+".SetDefaultColor(GetColor(1));
"DI-".SetDefaultColor(GetColor(5));
ADX.SetDefaultColor(GetColor(8));
ADX.SetLineWeight(2);

plot diffDI = Round(("DI+" / "DI-" - 1) * 100,0);
diffDI.SetDefaultColor(Color.Orange);
diffDI.SetHiding(1);

def sellersOnTop = "DI+" > "DI-";
def sellersOverX = "DI+" > crossline;
def bullish = sellersOnTop and "DI+" * 1.025 > crossline and (ADX > crossline);
def bearish = diffDI < -5 or (!sellersOnTop and "DI-" > crossline * 0.80 and "DI-"[1] > crossline * 0.80);

plot bbsState = if bullish then 50 else if bearish then -20 else 0;
bbsState.Hide();

AddLabel(showlabels, if bbsState == 50 then ("Bullish " + diffDI + "% " + if sellersOverX then "+ " else "") else
 if bbsState == -20 then "Bearish " + diffDI + "% " + if sellersOverX then "+ " else ""
 else "Sideways " + diffDI + "% " + if sellersOverX then "+ " else "",
 if IsNan(bbsState) then COLOR.GRAY else
 if bbsState == 50 then GlobalColor("Bullish") else
 if bbsState == -20 then GlobalColor("Bearish")
 else GlobalColor("Neutral"));
AddLabel(showlabels and ADX < 18, " No Strength ", Color.Light_Orange);
AddLabel(showlabels and ADX > 18 and diffDI < -5, " SELLERS ", Color.Red);

plot cross_line = crossline;
cross_line.SetDefaultColor(GetColor(7));
cross_line.AssignValueColor( if IsNan(bbsState) then COLOR.GRAY else
 if bbsState == 50 then GlobalColor("Bullish") else
 if bbsState == -20 then GlobalColor("Bearish")
 else GlobalColor("Neutral"));
cross_line.SetLineWeight(2);
cross_line.HideTitle();

# detect new session of day
def isNewDay = GetYYYYMMDD() != GetYYYYMMDD()[1];

# mark new sessions on intraday charts
AddVerticalLine(isNewDay && GetAggregationPeriod() < AggregationPeriod.DAY, "", Color.GRAY, curve.SHORT_DASH);

#END
 
Last edited by a moderator:
@cswu1211 here is a version of Joe Rabil's ADX/DMI study I crafted together. Use at your own risk... ;)

lngWw8E.png

Code:
#
# An implementatio of ADX and DI+/- based on following Joe Rabil
#
# customized with cross line and individual DMI and ADX lengths

declare lower;

script func_DMI {
input length_di = 14; #DI+- length
input length_adx = 14; #ADX length
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_di);
plot "DI+" = 100 * MovingAverage(averageType, plusDM, length_di) / ATR;
plot "DI-" = 100 * MovingAverage(averageType, minusDM, length_di) / ATR;

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

};

input di_length = 13;  #original 14  Use Joe's 13 and 8
input adx_length = 8;  #original 14
input averageType = AverageType.WILDERS;

#add cross line
input crossline = 25;
input showlabels = yes; #show labels

#CORE
DefineGlobalColor("Bullish", Color.GREEN);
DefineGlobalColor("Bearish", Color.RED);
DefineGlobalColor("Neutral", Color.dark_orange);

plot "DI+" = func_DMI(di_length, adx_length, averageType)."DI+";
plot "DI-" = func_DMI(di_length, adx_length, averageType)."DI-";

def ADXfast = func_DMI(di_length, adx_length, averageType)."ADX";
plot ADX = ADXfast;

"DI+".SetDefaultColor(GetColor(1));
"DI-".SetDefaultColor(GetColor(5));
ADX.SetDefaultColor(GetColor(8));
ADX.SetLineWeight(2);

plot diffDI = Round(("DI+" / "DI-" - 1) * 100,0);
diffDI.SetDefaultColor(Color.Orange);
diffDI.SetHiding(1);

def sellersOnTop = "DI+" > "DI-";
def sellersOverX = "DI+" > crossline;
def bullish = sellersOnTop and "DI+" * 1.025 > crossline and (ADX > crossline);
def bearish = diffDI < -5 or (!sellersOnTop and "DI-" > crossline * 0.80 and "DI-"[1] > crossline * 0.80);

plot bbsState = if bullish then 50 else if bearish then -20 else 0;
bbsState.Hide();

AddLabel(showlabels, if bbsState == 50 then ("Bullish " + diffDI + "% " + if sellersOverX then "+ " else "") else
 if bbsState == -20 then "Bearish " + diffDI + "% " + if sellersOverX then "+ " else ""
 else "Sideways " + diffDI + "% " + if sellersOverX then "+ " else "",
 if IsNan(bbsState) then COLOR.GRAY else
 if bbsState == 50 then GlobalColor("Bullish") else
 if bbsState == -20 then GlobalColor("Bearish")
 else GlobalColor("Neutral"));
AddLabel(showlabels and ADX < 18, " No Strength ", Color.Light_Orange);
AddLabel(showlabels and ADX > 18 and diffDI < -5, " SELLERS ", Color.Red);

plot cross_line = crossline;
cross_line.SetDefaultColor(GetColor(7));
cross_line.AssignValueColor( if IsNan(bbsState) then COLOR.GRAY else
 if bbsState == 50 then GlobalColor("Bullish") else
 if bbsState == -20 then GlobalColor("Bearish")
 else GlobalColor("Neutral"));
cross_line.SetLineWeight(2);
cross_line.HideTitle();

# detect new session of day
def isNewDay = GetYYYYMMDD() != GetYYYYMMDD()[1];

# mark new sessions on intraday charts
AddVerticalLine(isNewDay && GetAggregationPeriod() < AggregationPeriod.DAY, "", Color.GRAY, curve.SHORT_DASH);

#END
greatly appreciated
 
never heard about this version of ADX/DMI. what is the big feature of this indicator and/or eventually the best way to use it?
 
Rabil, along with Charles Schapp, use 13 (14 is the default) for the DMIs and 8 for the ADX.

Here's my code.
declare lower;

input length = 13;
input ADXLength = 8;
input averageType = AverageType.WILDERS;
input ADXLvl = 25;

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, ADXLength);
plot SignalLine = 25;

"DI+".SetDefaultColor(GetColor(1));
"DI-".SetDefaultColor(GetColor(8));
ADX.SetDefaultColor(GetColor(5));

def UpTrend = "DI+" > "DI-" and ADX > 20 and ADX > "DI-";
def DownTrend = "DI+" < "DI-";
def NeutralTrend = "DI+" == "DI-";
AddLabel(yes, if UpTrend then "DM Positive" else "", Color.GREEN);
AddLabel(yes, if !UpTrend and !DownTrend and !NeutralTrend then "DM Weak" else "", Color.PINK);
AddLabel(yes, if DownTrend then "DM Negative" else "", Color.RED);
AddLabel(yes, if NeutralTrend then "DM Neutral" else "", Color.LIGHT_ORANGE);
AddLabel(yes, if ADX > 50 then "Trend Alert" else "", Color.YELLOW);
 
For a detailed explanation, both Rabil and Schapp (ADXellence) have written books.
Thirteen is a Fib sequence number and a quarter on the weekly Chart. Wilder's smoothing technique introduces a lot of lags into ADX so 8, another Fib sequence number, speeds it up.
 

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
509 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