Excellent ADX For ThinkOrSwim

https://www.tradingview.com/script/VocSxIq4-excellent-adx/

//@author=newmen
//@version=4
//
// This is the classic Average Directional Movement Index (ADX) indicator/oscilator that highlights the trend, pivot points and the close moment
//
study("Excellent ADX", shorttitle="ADX")
fast_adxlen = input(5, title="Fast ADX Smoothing")
slow_adxlen = input(19, title="Slow ADX Smoothing")
fast_dilen = input(13, title="Fast DI Length")
slow_dilen = input(21, title="Slow DI Length")
fast_atrlen = input(14, title="Fast ATR Length")
slow_atrlen = input(21, title="Slow ATR Length")
upper_treshold = input(41, title="Upper Treshold")
lower_treshold = input(19, title="Lower Treshold")
pullback_out_sencivity = input(2.55, title="Pullback Sencivity")
trend_sencivity = input(0.13, title="Trend Sencivity")

dirmov(len, atrlen) =>
up = change(high)
down = -change(low)
plus_dm = na(up) ? na : (up > down and up > 0 ? up : 0)
minus_dm = na(down) ? na : (down > up and down > 0 ? down : 0)
truerange = rma(tr, atrlen)
plus = fixnan(100 * rma(plus_dm, len) / truerange)
minus = fixnan(100 * rma(minus_dm, len) / truerange)
[plus, minus]

adx(dilen, adxlen, atrlen) =>
[plus, minus] = dirmov(dilen, atrlen)
sum = plus + minus
rate = abs(plus - minus) / (sum == 0 ? 1 : sum)
adx_v = 100 * rma(rate, adxlen)
[plus, minus, adx_v]

[plus_di, minus_di, adx_s_sig] = adx(slow_dilen, slow_adxlen, slow_atrlen)
[_f_plus_di, _f_minus_di, adx_f_sig] = adx(fast_dilen, fast_adxlen, fast_atrlen)

trend = plus_di < minus_di
? color.new(color.red, 90)
: plus_di > minus_di
? color.new(color.green, 90)
: na
bgcolor(trend)

plot(plus_di, color=color.green, title="+DI", linewidth=1)
plot(minus_di, color=color.red, title="-DI", linewidth=1)
plot(adx_s_sig, color=color.blue, title="Slow ADX", linewidth=2)
plot(adx_f_sig, color=color.new(color.orange, 75), title="Fast ADX", linewidth=2)
plot(upper_treshold, color=color.new(color.gray, 10), title="Upper Treshold", linewidth=1, style=plot.style_circles)
plot(lower_treshold, color=color.new(color.gray, 10), title="Lower Treshold", linewidth=1, style=plot.style_circles)

distance = plus_di - minus_di
sg_distance = sign(distance)
abs_distance = abs(distance)
pullback_rate = (abs_distance + abs_distance[2]) / abs_distance[1]
pullback_out = abs_distance[1] < abs_distance and
((abs_distance[1] < abs_distance[2] and sg_distance[2] == sg_distance[1] and sg_distance[1] == sg_distance) or
(abs_distance[1] > abs_distance[2] and sg_distance[2] == sg_distance[1] and sg_distance[1] != sg_distance)) and
adx_s_sig > (adx_s_sig[1] - trend_sencivity) and
pullback_rate > pullback_out_sencivity and
((plus_di > minus_di and plus_di[1] < plus_di and minus_di[1] > minus_di) or
(plus_di < minus_di and plus_di[1] > plus_di and minus_di[1] < minus_di))
? color.new((plus_di < minus_di ? color.red : color.green), 60)
: na
plot(minus_di, color=pullback_out, title="Pullback Out", linewidth=5, style=plot.style_circles)

pullback_on = abs_distance[1] > abs_distance and abs_distance[1] > abs_distance[2] and
sg_distance[2] == sg_distance[1] and sg_distance[1] == sg_distance and
((adx_s_sig < (adx_s_sig[1] + trend_sencivity) and not (plus_di > adx_s_sig and minus_di > adx_s_sig)) or
(plus_di < adx_s_sig and minus_di < adx_s_sig)) and
((plus_di > minus_di and
plus_di[2] < plus_di[1] and plus_di[1] > plus_di and
minus_di[2] > minus_di[1] and minus_di[1] < minus_di) or
(plus_di < minus_di and
plus_di[2] > plus_di[1] and plus_di[1] < plus_di and
minus_di[2] < minus_di[1] and minus_di[1] > minus_di))
? color.new((plus_di > minus_di ? color.red : color.green), 80)
: na
plot(plus_di, color=pullback_on, title="Pullback On", linewidth=3, style=plot.style_circles)

pivots(adx_sig, transp) =>
adx_sig[2] < adx_sig[1] and adx_sig[1] > adx_sig and
plus_di[1] < adx_sig[1] and minus_di[1] < adx_sig[1]
? color.new((plus_di < minus_di ? color.green : color.red), transp)
: na

piv_dots(adx_sig, transp) =>
pivot = pivots(adx_sig, transp)
sig_over = adx_sig[1] >= upper_treshold ? adx_sig : na
sig_side = adx_sig[1] >= lower_treshold and adx_sig[1] < upper_treshold ? adx_sig : na
[pivot, sig_over, sig_side]

[s_pivot, sig_s_over, sig_s_side] = piv_dots(adx_s_sig, 30)
plot(sig_s_over, color=s_pivot, title="Slow Strong Pivot", linewidth=11, style=plot.style_circles)
plot(sig_s_side, color=s_pivot, title="Slow Weak Pivot", linewidth=7, style=plot.style_circles)

[f_pivot, sig_f_over, sig_f_side] = piv_dots(adx_f_sig, 65)
plot(sig_f_over, color=f_pivot, title="Fast Strong Pivot", linewidth=6, style=plot.style_circles)
plot(sig_f_side, color=f_pivot, title="Fast Weak Pivot", linewidth=4, style=plot.style_circles)
find below.
CSS:
#https://www.tradingview.com/script/VocSxIq4-excellent-adx/
#//@author=newmen
#/ This is the classic Average Directional Movement Index (ADX) indicator/oscilator that highlights the trend, pivot points and the close moment
#study("Excellent ADX", shorttitle="ADX")
# converted by Sam4Cok@Samer800        - 04/2023
declare lower;
input fast_adxlen = 5;#, title="Fast ADX Smoothing")
input slow_adxlen = 19;#, title="Slow ADX Smoothing")
input fast_dilen = 13;#, title="Fast DI Length")
input slow_dilen = 21;#, title="Slow DI Length")
input fast_atrlen = 14;#, title="Fast ATR Length")
input slow_atrlen = 21;#, title="Slow ATR Length")
input upper_treshold = 41;#, title="Upper Treshold")
input lower_treshold = 19;#, title="Lower Treshold")
input pullback_out_sencivity = 2.55;#, title="Pullback Sencivity")
input trend_sencivity = 0.13;#, title="Trend Sencivity")

def na = Double.NaN;
def last = isNaN(close);
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;

#piv_dots(adx_sig, transp) =>
Script piv_dots {
input adx_sig = close;
input plus_di = close;
input minus_di = close;
input upper_treshold = 0;
input lower_treshold = 0;
    def na = Double.NaN;
    def pivot = if adx_sig[2] < adx_sig[1] and adx_sig[1] > adx_sig and
     plus_di[1] < adx_sig[1] and minus_di[1] < adx_sig[1] then (if plus_di < minus_di then 1 else -1) else 0;
    def sig_over = if adx_sig[1] >= upper_treshold then adx_sig else na;
    def sig_side = if adx_sig[1] >= lower_treshold and adx_sig[1] < upper_treshold then adx_sig else na;
    plot pvt = pivot;
    plot SigOvr = sig_over;
    plot SigSide = sig_side;
}
#adx(dilen, adxlen, atrlen) =>
script adx {
    input dilen = 10;
    input adxlen = 14;
    input atrlen = 14;
    def up = high - high[1];
    def down = -(low - low[1]);
    def plus_dm = if IsNaN(up) then Double.NaN else (if up > down and up > 0 then up else 0);
    def minus_dm = if IsNaN(down) then Double.NaN else (if down > up and down > 0 then down else 0);
    def truerange = ATR(Length = atrlen);
    def pValue = 100 * WildersAverage(plus_dm, dilen) / truerange;
    def mValue = 100 * WildersAverage(minus_dm, dilen) / truerange;
    def plus =  if IsNaN(pValue) then plus[1] else pValue;
    def minus = if IsNaN(mValue) then minus[1] else mValue;
    def sum = plus + minus;
    def rate = AbsValue(plus - minus) / (if sum == 0 then 1 else sum);
    def adx_v = 100 * WildersAverage(rate, adxlen);
    plot p = plus;
    plot m = minus;
    plot adx_ = adx_v;
}
def plus_di = ADX(slow_dilen, slow_adxlen, slow_atrlen).p;
def minus_di = ADX(slow_dilen, slow_adxlen, slow_atrlen).m;
def adx_s_sig = ADX(slow_dilen, slow_adxlen, slow_atrlen).adx_;
def adx_f_sig = adx(fast_dilen, fast_adxlen, fast_atrlen).adx_;

def trend = if plus_di < minus_di then -1 else if plus_di > minus_di then 1 else 0;

AddCloud(if last then na else
         if trend>0 then pos else if trend<0 then neg else na, if trend>0 then neg else pos, Color.DARK_GREEN, Color.DARK_RED);


plot "+DI" = if last then na else plus_di;#, color=color.green, title="+DI", linewidth=1)
plot "-DI" = if last then na else minus_di;#, color=color.red, title="-DI", linewidth=1)
plot SlowADX = if last then na else adx_s_sig;#, color=color.blue, title="Slow ADX", linewidth=2)
plot FastADX = if last then na else adx_f_sig;#, color=color.new(color.orange, 75), title="Fast ADX", linewidth=2)
plot UpperTreshold  = if last then na else upper_treshold;#, color=color.new(color.gray, 10), title="Upper Treshold", linewidth=1, style=plot.style_circles)
plot LowerTreshold = if last then na else lower_treshold;#, color=color.new(color.gray, 10), title="Lower Treshold", linewidth=1, style=plot.style_circles)
"+DI".SetDefaultColor(Color.DARK_GREEN);
"-DI".SetDefaultColor(Color.DARK_RED);
SlowADX.SetDefaultColor(CreateColor(33,150,243));
FastADX.SetDefaultColor(Color.DARK_ORANGE);
UpperTreshold.SetDefaultColor(Color.GRAY);
LowerTreshold.SetDefaultColor(Color.GRAY);
UpperTreshold.SetPaintingStrategy(PaintingStrategy.DASHES);
LowerTreshold.SetPaintingStrategy(PaintingStrategy.DASHES);
SlowADX.SEtLineWeight(2);
FastADX.SetLineWeight(2);

def distance = plus_di - minus_di;
def sg_distance = sign(distance);
def abs_distance = AbsValue(distance);
def pullback_rate = (abs_distance + abs_distance[2]) / abs_distance[1];
def pullback_out = if abs_distance[1] < abs_distance and
             ((abs_distance[1] < abs_distance[2] and sg_distance[2] == sg_distance[1] and sg_distance[1] == sg_distance) or
             (abs_distance[1] > abs_distance[2] and sg_distance[2] == sg_distance[1] and sg_distance[1] != sg_distance)) and
             adx_s_sig > (adx_s_sig[1] - trend_sencivity) and pullback_rate > pullback_out_sencivity and
             ((plus_di > minus_di and plus_di[1] < plus_di and minus_di[1] > minus_di) or
             (plus_di < minus_di and plus_di[1] > plus_di and minus_di[1] < minus_di)) then
             (if plus_di < minus_di then -1 else 1) else 0;
plot PullbackOut = if pullback_out!=0 then minus_di else na; # "Pullback Out"
PullbackOut.SetPaintingStrategy(PaintingStrategy.POINTS);
PullbackOut.AssignValueColor(if pullback_out > 0 then Color.GREEN else Color.RED);
#PullbackOut.SetLineWeight(2);

def s_pivot = piv_dots(adx_s_sig, plus_di, minus_di, upper_treshold, lower_treshold).pvt;
def sig_s_over = piv_dots(adx_s_sig, plus_di, minus_di, upper_treshold, lower_treshold).SigOvr;
def sig_s_side = piv_dots(adx_s_sig, plus_di, minus_di, upper_treshold, lower_treshold).SigSide;

def f_pivot = piv_dots(adx_f_sig, plus_di, minus_di, upper_treshold, lower_treshold).pvt;
def sig_f_over = piv_dots(adx_f_sig, plus_di, minus_di, upper_treshold, lower_treshold).SigOvr;
def sig_f_side = piv_dots(adx_f_sig, plus_di, minus_di, upper_treshold, lower_treshold).SigSide;

plot SlowStrongPivot = if s_pivot==0 then na else sig_s_over;#, color=s_pivot, title="Slow Strong Pivot"
plot SlowWeakPivot = if s_pivot==0 then na else sig_s_side;#, color=s_pivot, title="Slow Weak Pivot"
SlowStrongPivot.SetPaintingStrategy(PaintingStrategy.POINTS);
SlowWeakPivot.SetPaintingStrategy(PaintingStrategy.POINTS);
SlowStrongPivot.SetLineWeight(5);
SlowWeakPivot.SetLineWeight(4);
SlowStrongPivot.AssignValueColor(if s_pivot>0 then Color.GREEN else Color.RED);
SlowWeakPivot.AssignValueColor(if s_pivot>0 then Color.GREEN else Color.RED);

plot FastStrongPivot = if f_pivot==0 then na else sig_f_over;#, color=f_pivot, title="Fast Strong Pivot"
plot FastWeakPivot = if f_pivot==0 then na else sig_f_side;#, color=f_pivot, title="Fast Weak Pivot"
FastStrongPivot.SetPaintingStrategy(PaintingStrategy.POINTS);
FastWeakPivot.SetPaintingStrategy(PaintingStrategy.POINTS);
FastStrongPivot.SetLineWeight(3);
FastWeakPivot.SetLineWeight(2);
FastStrongPivot.AssignValueColor(if f_pivot>0 then Color.GREEN else Color.RED);
FastWeakPivot.AssignValueColor(if f_pivot>0 then Color.GREEN else Color.RED);




#-- End OF CODe
 
find below.
CSS:
#https://www.tradingview.com/script/VocSxIq4-excellent-adx/
#//@author=newmen
#/ This is the classic Average Directional Movement Index (ADX) indicator/oscilator that highlights the trend, pivot points and the close moment
#study("Excellent ADX", shorttitle="ADX")
# converted by Sam4Cok@Samer800        - 04/2023
declare lower;
input fast_adxlen = 5;#, title="Fast ADX Smoothing")
input slow_adxlen = 19;#, title="Slow ADX Smoothing")
input fast_dilen = 13;#, title="Fast DI Length")
input slow_dilen = 21;#, title="Slow DI Length")
input fast_atrlen = 14;#, title="Fast ATR Length")
input slow_atrlen = 21;#, title="Slow ATR Length")
input upper_treshold = 41;#, title="Upper Treshold")
input lower_treshold = 19;#, title="Lower Treshold")
input pullback_out_sencivity = 2.55;#, title="Pullback Sencivity")
input trend_sencivity = 0.13;#, title="Trend Sencivity")

def na = Double.NaN;
def last = isNaN(close);
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;

#piv_dots(adx_sig, transp) =>
Script piv_dots {
input adx_sig = close;
input plus_di = close;
input minus_di = close;
input upper_treshold = 0;
input lower_treshold = 0;
    def na = Double.NaN;
    def pivot = if adx_sig[2] < adx_sig[1] and adx_sig[1] > adx_sig and
     plus_di[1] < adx_sig[1] and minus_di[1] < adx_sig[1] then (if plus_di < minus_di then 1 else -1) else 0;
    def sig_over = if adx_sig[1] >= upper_treshold then adx_sig else na;
    def sig_side = if adx_sig[1] >= lower_treshold and adx_sig[1] < upper_treshold then adx_sig else na;
    plot pvt = pivot;
    plot SigOvr = sig_over;
    plot SigSide = sig_side;
}
#adx(dilen, adxlen, atrlen) =>
script adx {
    input dilen = 10;
    input adxlen = 14;
    input atrlen = 14;
    def up = high - high[1];
    def down = -(low - low[1]);
    def plus_dm = if IsNaN(up) then Double.NaN else (if up > down and up > 0 then up else 0);
    def minus_dm = if IsNaN(down) then Double.NaN else (if down > up and down > 0 then down else 0);
    def truerange = ATR(Length = atrlen);
    def pValue = 100 * WildersAverage(plus_dm, dilen) / truerange;
    def mValue = 100 * WildersAverage(minus_dm, dilen) / truerange;
    def plus =  if IsNaN(pValue) then plus[1] else pValue;
    def minus = if IsNaN(mValue) then minus[1] else mValue;
    def sum = plus + minus;
    def rate = AbsValue(plus - minus) / (if sum == 0 then 1 else sum);
    def adx_v = 100 * WildersAverage(rate, adxlen);
    plot p = plus;
    plot m = minus;
    plot adx_ = adx_v;
}
def plus_di = ADX(slow_dilen, slow_adxlen, slow_atrlen).p;
def minus_di = ADX(slow_dilen, slow_adxlen, slow_atrlen).m;
def adx_s_sig = ADX(slow_dilen, slow_adxlen, slow_atrlen).adx_;
def adx_f_sig = adx(fast_dilen, fast_adxlen, fast_atrlen).adx_;

def trend = if plus_di < minus_di then -1 else if plus_di > minus_di then 1 else 0;

AddCloud(if last then na else
         if trend>0 then pos else if trend<0 then neg else na, if trend>0 then neg else pos, Color.DARK_GREEN, Color.DARK_RED);


plot "+DI" = if last then na else plus_di;#, color=color.green, title="+DI", linewidth=1)
plot "-DI" = if last then na else minus_di;#, color=color.red, title="-DI", linewidth=1)
plot SlowADX = if last then na else adx_s_sig;#, color=color.blue, title="Slow ADX", linewidth=2)
plot FastADX = if last then na else adx_f_sig;#, color=color.new(color.orange, 75), title="Fast ADX", linewidth=2)
plot UpperTreshold  = if last then na else upper_treshold;#, color=color.new(color.gray, 10), title="Upper Treshold", linewidth=1, style=plot.style_circles)
plot LowerTreshold = if last then na else lower_treshold;#, color=color.new(color.gray, 10), title="Lower Treshold", linewidth=1, style=plot.style_circles)
"+DI".SetDefaultColor(Color.DARK_GREEN);
"-DI".SetDefaultColor(Color.DARK_RED);
SlowADX.SetDefaultColor(CreateColor(33,150,243));
FastADX.SetDefaultColor(Color.DARK_ORANGE);
UpperTreshold.SetDefaultColor(Color.GRAY);
LowerTreshold.SetDefaultColor(Color.GRAY);
UpperTreshold.SetPaintingStrategy(PaintingStrategy.DASHES);
LowerTreshold.SetPaintingStrategy(PaintingStrategy.DASHES);
SlowADX.SEtLineWeight(2);
FastADX.SetLineWeight(2);

def distance = plus_di - minus_di;
def sg_distance = sign(distance);
def abs_distance = AbsValue(distance);
def pullback_rate = (abs_distance + abs_distance[2]) / abs_distance[1];
def pullback_out = if abs_distance[1] < abs_distance and
             ((abs_distance[1] < abs_distance[2] and sg_distance[2] == sg_distance[1] and sg_distance[1] == sg_distance) or
             (abs_distance[1] > abs_distance[2] and sg_distance[2] == sg_distance[1] and sg_distance[1] != sg_distance)) and
             adx_s_sig > (adx_s_sig[1] - trend_sencivity) and pullback_rate > pullback_out_sencivity and
             ((plus_di > minus_di and plus_di[1] < plus_di and minus_di[1] > minus_di) or
             (plus_di < minus_di and plus_di[1] > plus_di and minus_di[1] < minus_di)) then
             (if plus_di < minus_di then -1 else 1) else 0;
plot PullbackOut = if pullback_out!=0 then minus_di else na; # "Pullback Out"
PullbackOut.SetPaintingStrategy(PaintingStrategy.POINTS);
PullbackOut.AssignValueColor(if pullback_out > 0 then Color.GREEN else Color.RED);
#PullbackOut.SetLineWeight(2);

def s_pivot = piv_dots(adx_s_sig, plus_di, minus_di, upper_treshold, lower_treshold).pvt;
def sig_s_over = piv_dots(adx_s_sig, plus_di, minus_di, upper_treshold, lower_treshold).SigOvr;
def sig_s_side = piv_dots(adx_s_sig, plus_di, minus_di, upper_treshold, lower_treshold).SigSide;

def f_pivot = piv_dots(adx_f_sig, plus_di, minus_di, upper_treshold, lower_treshold).pvt;
def sig_f_over = piv_dots(adx_f_sig, plus_di, minus_di, upper_treshold, lower_treshold).SigOvr;
def sig_f_side = piv_dots(adx_f_sig, plus_di, minus_di, upper_treshold, lower_treshold).SigSide;

plot SlowStrongPivot = if s_pivot==0 then na else sig_s_over;#, color=s_pivot, title="Slow Strong Pivot"
plot SlowWeakPivot = if s_pivot==0 then na else sig_s_side;#, color=s_pivot, title="Slow Weak Pivot"
SlowStrongPivot.SetPaintingStrategy(PaintingStrategy.POINTS);
SlowWeakPivot.SetPaintingStrategy(PaintingStrategy.POINTS);
SlowStrongPivot.SetLineWeight(5);
SlowWeakPivot.SetLineWeight(4);
SlowStrongPivot.AssignValueColor(if s_pivot>0 then Color.GREEN else Color.RED);
SlowWeakPivot.AssignValueColor(if s_pivot>0 then Color.GREEN else Color.RED);

plot FastStrongPivot = if f_pivot==0 then na else sig_f_over;#, color=f_pivot, title="Fast Strong Pivot"
plot FastWeakPivot = if f_pivot==0 then na else sig_f_side;#, color=f_pivot, title="Fast Weak Pivot"
FastStrongPivot.SetPaintingStrategy(PaintingStrategy.POINTS);
FastWeakPivot.SetPaintingStrategy(PaintingStrategy.POINTS);
FastStrongPivot.SetLineWeight(3);
FastWeakPivot.SetLineWeight(2);
FastStrongPivot.AssignValueColor(if f_pivot>0 then Color.GREEN else Color.RED);
FastWeakPivot.AssignValueColor(if f_pivot>0 then Color.GREEN else Color.RED);




#-- End OF CODe
wow Great ty samer
 

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