• Get $40 off VIP by signing up for a free account! Sign Up

Trend Strength/ADX Leaf_West style For ThinkOrSwim

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

Any chance we could get a conversion of this ADX indicator? It's a solid representation of momentum advance/decline if anyone wishes to attempt it.

https://www.tradingview.com/v/MgcmUYd4/
find out below. I added bar colors as well.

9b8Gakk.png


CSS:
#// This is a different way of plotting ADX used by Leaf_West at http://tradingwithleafwest.net/.
#// The criteria for plotting ADX are described in the educational info.
# https://www.tradingview.com/script/MgcmUYd4-ADX-Trend-Strength-Leaf-West-style/
#// This is my attempt to replicate Leaf_West's indicator.
#// The BATS data feed has the usual issues.  Realtime data is the way to go.
#study("Trend Strength/ADX Leaf_West style"
# Converted and mod by Sam4Cok@Samer800 - 11/2022
declare lower;
input ColorBars = yes;
input ColorSignalBar = yes;
input adxLength = 8;#, title="ADX period")
input dmiLength = 9;#(9, title="DMI Length")
input MendozaLimit = 20;

def na = Double.NaN;
#fixnan(data)
script fixnan {
 input data1 = 0;
 def data2;
if barnumber() == 1 then {data2 = 0;} else if IsNaN(data1)
                    then {data2 = data2[1];} else {data2 = data1;}
plot valid = data2;
}
#dirmov(len) =>
script dirmov {
    input len = 8;
    def up = high - high[1];
    def down = -(low - low[1]);
    def tr = TrueRange(high, close, low);
    def truerange = WildersAverage(tr, len);
    def plus1 = fixnan(100 * WildersAverage(If(up > down and up > 0, up, 0), len) / truerange);
    def minus = fixnan(100 * WildersAverage(If(down > up and down > 0, down, 0), len) / truerange);
    plot plus = plus1;
    plot min = minus;
}
#adx(LWdilength, LWadxlength) =>
script adx {
    input LWdilength = 8;
    input LWadxlength = 9;
    def plus = dirmov(LWdilength).plus;
    def minus = dirmov(LWdilength).min;
    def sum = plus + minus;
    def adx = 100 * WildersAverage(AbsValue(plus - minus) / (If(sum == 0, 1, sum)), LWadxlength);
    plot ad = adx;
    plot pls = plus;
    plot mins = minus;
}
def ADX = ADX(dmiLength, adxLength).ad;
def up = ADX(dmiLength, adxLength).pls;
def down = ADX(dmiLength, adxLength).mins;
def LWADX = (ADX - 15) * 2.5;
def adxcolor = if up > down and LWADX>=100 then 2 else
               if up > down and LWADX<100 then 1 else
               if up <= down and LWADX>=100 then -2 else
               if up <= down and LWADX<100 then -1 else 0;

plot ZeroLine = if IsNaN(close) then na else 0;   # "Chop Zone"
ZeroLine.SetDefaultColor(Color.DARK_GRAY);
plot MendozaLine = if IsNaN(close) then na else MendozaLimit; # "Mendoza Line"
MendozaLine.SetDefaultColor(Color.GREEN);
plot Threshold = if IsNaN(close) then na else 100; # "Extreme Zone"
Threshold.SetDefaultColor(Color.RED);
plot TrendStrength = if IsNaN(close) then na else LWADX; # "Trend Strength"
TrendStrength.AssignValueColor(if adxcolor==2 then color.GREEN else
                               if adxcolor==1 then Color.DARK_GREEN else
                               if adxcolor==-2 then Color.RED else Color.DARK_RED);
plot histogram = if IsNaN(close) then na else LWADX;
histogram.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
histogram.AssignValueColor(if LWADX<MendozaLimit then Color.GRAY else
                           if adxcolor==2 then color.GREEN else
                           if adxcolor==1 then Color.DARK_GREEN else
                           if adxcolor==-2 then Color.RED else Color.DARK_RED);
histogram.SetLineWeight(3);
#--- Bar Color
AssignPriceColor(if !ColorBars then Color.CURRENT else
                 if LWADX<MendozaLimit then Color.GRAY else
                 if adxcolor==2 then color.GREEN else
                 if adxcolor==1 then Color.DARK_GREEN else
                 if adxcolor==-2 then Color.RED else Color.DARK_RED);
AssignPriceColor(if !ColorSignalBar then Color.CURRENT else
                 if LWADX crosses above MendozaLimit and LWADX[1]>LWADX[2] then Color.CYAN else
                 if LWADX crosses below MendozaLimit and LWADX[1]<LWADX[2] then Color.MAGENTA else
                    Color.CURRENT);

#---END Code
 
is there a way to create an alert if the color of the plot changes from red to green ? vise-verse
 
is there a way to create an alert if the color of the plot changes from red to green ? vise-verse
check the below.

CSS:
#// This is a different way of plotting ADX used by Leaf_West at http://tradingwithleafwest.net/. 
#// The criteria for plotting ADX are described in the educational info.
# https://www.tradingview.com/script/MgcmUYd4-ADX-Trend-Strength-Leaf-West-style/
#// This is my attempt to replicate Leaf_West's indicator.
#// The BATS data feed has the usual issues.  Realtime data is the way to go.
#study("Trend Strength/ADX Leaf_West style"
# Converted and mod by Sam4Cok@Samer800 - 11/2022
# Update, added alerts Sam4Cok@Samer800 - 11/2022;
declare lower;
input ColorBars = yes;
input ColorSignalBar = yes;
input alerts   = no;
input sound    = {default "NoSound", "Ding", "Bell", "Chimes", "Ring"};
input adxLength = 8;#, title="ADX period")
input dmiLength = 9;#(9, title="DMI Length")
input MendozaLimit = 20;

def na = Double.NaN;
#fixnan(data)
script fixnan {
    input data1 = 0;
    def data2;
    if BarNumber() == 1
    then {
        data2 = 0;
    } else if IsNaN(data1)
    then {
        data2 = data2[1];
    } else {
        data2 = data1;
    }
    plot valid = data2;
}
#dirmov(len) =>
script dirmov {
    input len = 8;
    def up = high - high[1];
    def down = -(low - low[1]);
    def tr = TrueRange(high, close, low);
    def truerange = WildersAverage(tr, len);
    def plus1 = fixnan(100 * WildersAverage(If(up > down and up > 0, up, 0), len) / truerange);
    def minus = fixnan(100 * WildersAverage(If(down > up and down > 0, down, 0), len) / truerange);
    plot plus = plus1;
    plot min = minus;
}
#adx(LWdilength, LWadxlength) =>
script adx {
    input LWdilength = 8;
    input LWadxlength = 9;
    def plus = dirmov(LWdilength).plus;
    def minus = dirmov(LWdilength).min;
    def sum = plus + minus;
    def adx = 100 * WildersAverage(AbsValue(plus - minus) / (If(sum == 0, 1, sum)), LWadxlength);
    plot ad = adx;
    plot pls = plus;
    plot mins = minus;
}
def ADX = ADX(dmiLength, adxLength).ad;
def up = ADX(dmiLength, adxLength).pls;
def down = ADX(dmiLength, adxLength).mins;
def LWADX = (ADX - 15) * 2.5;
def adxcolor = if up > down and LWADX >= 100 then 2 else
               if up > down and LWADX < 100 then 1 else
               if up <= down and LWADX >= 100 then -2 else
               if up <= down and LWADX < 100 then -1 else 0;

plot ZeroLine = if IsNaN(close) then na else 0;   # "Chop Zone"
ZeroLine.SetDefaultColor(Color.DARK_GRAY);
plot MendozaLine = if IsNaN(close) then na else MendozaLimit; # "Mendoza Line"
MendozaLine.SetDefaultColor(Color.GREEN);
plot Threshold = if IsNaN(close) then na else 100; # "Extreme Zone"
Threshold.SetDefaultColor(Color.RED);
plot TrendStrength = if IsNaN(close) then na else LWADX; # "Trend Strength"
TrendStrength.AssignValueColor(if adxcolor == 2 then Color.GREEN else
                               if adxcolor == 1 then Color.DARK_GREEN else
                               if adxcolor == -2 then Color.RED else Color.DARK_RED);
TrendStrength.SetLineWeight(2);
plot histogram = if IsNaN(close) then na else LWADX;
histogram.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
histogram.AssignValueColor(if LWADX < MendozaLimit then Color.GRAY else
                           if adxcolor == 2 then Color.GREEN else
                           if adxcolor == 1 then Color.DARK_GREEN else
                           if adxcolor == -2 then Color.RED else Color.DARK_RED);
histogram.SetLineWeight(3);
#--- Bar Color
AssignPriceColor(if !ColorBars then Color.CURRENT else
                 if LWADX < MendozaLimit then Color.GRAY else
                 if adxcolor == 2 then Color.GREEN else
                 if adxcolor == 1 then Color.DARK_GREEN else
                 if adxcolor == -2 then Color.RED else Color.DARK_RED);
AssignPriceColor(if !ColorSignalBar then Color.CURRENT else
                 if LWADX crosses above MendozaLimit and LWADX[1] > LWADX[2] then Color.CYAN else
                 if LWADX crosses below MendozaLimit and LWADX[1] < LWADX[2] then Color.MAGENTA else
                    Color.CURRENT);

#---- Alerts
def green = adxcolor>0;
def red = adxcolor<0;
Alert(alerts and green and !green[1], "Trending Up!", Alert.BAR, sound);
Alert(alerts and red and !red[1], "Trending Down!", Alert.BAR, sound);

#---END Code
 
I had to look up the meaning of "Mendoza Line" so I think I get that. Can anyone elaborate how it should be used in this indicator? Is it actionable? Or just a frame of reference for the underlying's momentum?
 
I had to look up the meaning of "Mendoza Line" so I think I get that. Can anyone elaborate how it should be used in this indicator? Is it actionable? Or just a frame of reference for the underlying's momentum?
usually trade when the trend above the threshold. I.e mendoza line. It is like a trend confirmation indicator
 
  • Like
Reactions: ALV
find out below. I added bar colors as well.

9b8Gakk.png


CSS:
#// This is a different way of plotting ADX used by Leaf_West at http://tradingwithleafwest.net/.
#// The criteria for plotting ADX are described in the educational info.
# https://www.tradingview.com/script/MgcmUYd4-ADX-Trend-Strength-Leaf-West-style/
#// This is my attempt to replicate Leaf_West's indicator.
#// The BATS data feed has the usual issues.  Realtime data is the way to go.
#study("Trend Strength/ADX Leaf_West style"
# Converted and mod by Sam4Cok@Samer800 - 11/2022
declare lower;
input ColorBars = yes;
input ColorSignalBar = yes;
input adxLength = 8;#, title="ADX period")
input dmiLength = 9;#(9, title="DMI Length")
input MendozaLimit = 20;

def na = Double.NaN;
#fixnan(data)
script fixnan {
 input data1 = 0;
 def data2;
if barnumber() == 1 then {data2 = 0;} else if IsNaN(data1)
                    then {data2 = data2[1];} else {data2 = data1;}
plot valid = data2;
}
#dirmov(len) =>
script dirmov {
    input len = 8;
    def up = high - high[1];
    def down = -(low - low[1]);
    def tr = TrueRange(high, close, low);
    def truerange = WildersAverage(tr, len);
    def plus1 = fixnan(100 * WildersAverage(If(up > down and up > 0, up, 0), len) / truerange);
    def minus = fixnan(100 * WildersAverage(If(down > up and down > 0, down, 0), len) / truerange);
    plot plus = plus1;
    plot min = minus;
}
#adx(LWdilength, LWadxlength) =>
script adx {
    input LWdilength = 8;
    input LWadxlength = 9;
    def plus = dirmov(LWdilength).plus;
    def minus = dirmov(LWdilength).min;
    def sum = plus + minus;
    def adx = 100 * WildersAverage(AbsValue(plus - minus) / (If(sum == 0, 1, sum)), LWadxlength);
    plot ad = adx;
    plot pls = plus;
    plot mins = minus;
}
def ADX = ADX(dmiLength, adxLength).ad;
def up = ADX(dmiLength, adxLength).pls;
def down = ADX(dmiLength, adxLength).mins;
def LWADX = (ADX - 15) * 2.5;
def adxcolor = if up > down and LWADX>=100 then 2 else
               if up > down and LWADX<100 then 1 else
               if up <= down and LWADX>=100 then -2 else
               if up <= down and LWADX<100 then -1 else 0;

plot ZeroLine = if IsNaN(close) then na else 0;   # "Chop Zone"
ZeroLine.SetDefaultColor(Color.DARK_GRAY);
plot MendozaLine = if IsNaN(close) then na else MendozaLimit; # "Mendoza Line"
MendozaLine.SetDefaultColor(Color.GREEN);
plot Threshold = if IsNaN(close) then na else 100; # "Extreme Zone"
Threshold.SetDefaultColor(Color.RED);
plot TrendStrength = if IsNaN(close) then na else LWADX; # "Trend Strength"
TrendStrength.AssignValueColor(if adxcolor==2 then color.GREEN else
                               if adxcolor==1 then Color.DARK_GREEN else
                               if adxcolor==-2 then Color.RED else Color.DARK_RED);
plot histogram = if IsNaN(close) then na else LWADX;
histogram.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
histogram.AssignValueColor(if LWADX<MendozaLimit then Color.GRAY else
                           if adxcolor==2 then color.GREEN else
                           if adxcolor==1 then Color.DARK_GREEN else
                           if adxcolor==-2 then Color.RED else Color.DARK_RED);
histogram.SetLineWeight(3);
#--- Bar Color
AssignPriceColor(if !ColorBars then Color.CURRENT else
                 if LWADX<MendozaLimit then Color.GRAY else
                 if adxcolor==2 then color.GREEN else
                 if adxcolor==1 then Color.DARK_GREEN else
                 if adxcolor==-2 then Color.RED else Color.DARK_RED);
AssignPriceColor(if !ColorSignalBar then Color.CURRENT else
                 if LWADX crosses above MendozaLimit and LWADX[1]>LWADX[2] then Color.CYAN else
                 if LWADX crosses below MendozaLimit and LWADX[1]<LWADX[2] then Color.MAGENTA else
                    Color.CURRENT);

#---END Code
As usual, excellent port Samer - thank you.
 
Code:
##### Begin Code #####

# SD_ADXLabel
# Scott XXX
# Version: 01
# Original: November 17, 2020
# Last Mod: November 18, 2020

declare upper;

input ADXLength = 8;
input ADXLower = 15;
input ADXMid = 35;
input ADXHigh = 100;
input MALength = 10;

def ADXlabel = reference ADX(ADXLength).ADX;
def MA = reference HullMovingAvg(close,MALength);

AddLabel(yes, "                     ADX SETTING UP                     ", if ADXlabel < ADXLower then Color.CYAN else Color.BLACK);

AddLabel(yes, " ADX WATCH ", if ADXlabel < ADXMid then Color.WHITE else Color.BLACK);

AddLabel(yes, " ADX TREND WEAKENING ", if (ADXlabel < ADXlabel[1]) then Color.YELLOW else Color.BLACK);

AddLabel(yes, "           UP TREND           ", if ADXlabel > ADXlabel[1] and MA > MA[1] then Color.GREEN else Color.BLACK);

AddLabel(yes, "           DOWN TREND           ", if ADXlabel > ADXlabel[1] and MA < MA[1] then Color.RED else Color.BLACK);

AddLabel(yes, " ADX HIGH ", if ADXlabel > ADXHigh then Color.MAGENTA else Color.BLACK);

##### End Code #####

I'm curious if anyone would be willing to take a stab at merging this indicator into the Leaf West build as it would allow for a minimalist style for anyone who prefers it that way. Could also provide the same information at a glance without taking over the candle paint slot.
 
  • Love
Reactions: IPA
check the below.

CSS:
#// This is a different way of plotting ADX used by Leaf_West at http://tradingwithleafwest.net/.
#// The criteria for plotting ADX are described in the educational info.
# https://www.tradingview.com/script/MgcmUYd4-ADX-Trend-Strength-Leaf-West-style/
#// This is my attempt to replicate Leaf_West's indicator.
#// The BATS data feed has the usual issues.  Realtime data is the way to go.
#study("Trend Strength/ADX Leaf_West style"
# Converted and mod by Sam4Cok@Samer800 - 11/2022
# Update, added alerts Sam4Cok@Samer800 - 11/2022;
declare lower;
input ColorBars = yes;
input ColorSignalBar = yes;
input alerts   = no;
input sound    = {default "NoSound", "Ding", "Bell", "Chimes", "Ring"};
input adxLength = 8;#, title="ADX period")
input dmiLength = 9;#(9, title="DMI Length")
input MendozaLimit = 20;

def na = Double.NaN;
#fixnan(data)
script fixnan {
    input data1 = 0;
    def data2;
    if BarNumber() == 1
    then {
        data2 = 0;
    } else if IsNaN(data1)
    then {
        data2 = data2[1];
    } else {
        data2 = data1;
    }
    plot valid = data2;
}
#dirmov(len) =>
script dirmov {
    input len = 8;
    def up = high - high[1];
    def down = -(low - low[1]);
    def tr = TrueRange(high, close, low);
    def truerange = WildersAverage(tr, len);
    def plus1 = fixnan(100 * WildersAverage(If(up > down and up > 0, up, 0), len) / truerange);
    def minus = fixnan(100 * WildersAverage(If(down > up and down > 0, down, 0), len) / truerange);
    plot plus = plus1;
    plot min = minus;
}
#adx(LWdilength, LWadxlength) =>
script adx {
    input LWdilength = 8;
    input LWadxlength = 9;
    def plus = dirmov(LWdilength).plus;
    def minus = dirmov(LWdilength).min;
    def sum = plus + minus;
    def adx = 100 * WildersAverage(AbsValue(plus - minus) / (If(sum == 0, 1, sum)), LWadxlength);
    plot ad = adx;
    plot pls = plus;
    plot mins = minus;
}
def ADX = ADX(dmiLength, adxLength).ad;
def up = ADX(dmiLength, adxLength).pls;
def down = ADX(dmiLength, adxLength).mins;
def LWADX = (ADX - 15) * 2.5;
def adxcolor = if up > down and LWADX >= 100 then 2 else
               if up > down and LWADX < 100 then 1 else
               if up <= down and LWADX >= 100 then -2 else
               if up <= down and LWADX < 100 then -1 else 0;

plot ZeroLine = if IsNaN(close) then na else 0;   # "Chop Zone"
ZeroLine.SetDefaultColor(Color.DARK_GRAY);
plot MendozaLine = if IsNaN(close) then na else MendozaLimit; # "Mendoza Line"
MendozaLine.SetDefaultColor(Color.GREEN);
plot Threshold = if IsNaN(close) then na else 100; # "Extreme Zone"
Threshold.SetDefaultColor(Color.RED);
plot TrendStrength = if IsNaN(close) then na else LWADX; # "Trend Strength"
TrendStrength.AssignValueColor(if adxcolor == 2 then Color.GREEN else
                               if adxcolor == 1 then Color.DARK_GREEN else
                               if adxcolor == -2 then Color.RED else Color.DARK_RED);
TrendStrength.SetLineWeight(2);
plot histogram = if IsNaN(close) then na else LWADX;
histogram.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
histogram.AssignValueColor(if LWADX < MendozaLimit then Color.GRAY else
                           if adxcolor == 2 then Color.GREEN else
                           if adxcolor == 1 then Color.DARK_GREEN else
                           if adxcolor == -2 then Color.RED else Color.DARK_RED);
histogram.SetLineWeight(3);
#--- Bar Color
AssignPriceColor(if !ColorBars then Color.CURRENT else
                 if LWADX < MendozaLimit then Color.GRAY else
                 if adxcolor == 2 then Color.GREEN else
                 if adxcolor == 1 then Color.DARK_GREEN else
                 if adxcolor == -2 then Color.RED else Color.DARK_RED);
AssignPriceColor(if !ColorSignalBar then Color.CURRENT else
                 if LWADX crosses above MendozaLimit and LWADX[1] > LWADX[2] then Color.CYAN else
                 if LWADX crosses below MendozaLimit and LWADX[1] < LWADX[2] then Color.MAGENTA else
                    Color.CURRENT);

#---- Alerts
def green = adxcolor>0;
def red = adxcolor<0;
Alert(alerts and green and !green[1], "Trending Up!", Alert.BAR, sound);
Alert(alerts and red and !red[1], "Trending Down!", Alert.BAR, sound);

#---END Code
Hi Samer
Thank you so much for your work and contribution to this community. I love this indicator which helps me a lot when combined with other indicators. I tried adding a cloud and using it as an upper indicator to see the results as the chart is being constructed. I am not a coder, just added cloud statements from another indicator and tried to make it work. There are some spaces when the cloud is missing the corresponding color (see arrows in upper and boxes in lower studies). I am not sure what is missing. I went over different posts related to clouds here but couldn't solve the issue.
Kindly request your help to fix this, if possible.
Thank you!!

1689882677855.png

The code is the same as above except for the cloud addition.



Code:
input ColorBars = no;
input ColorSignalBar = no;
input alerts   = no;
input sound    = {default "NoSound", "Ding", "Bell", "Chimes", "Ring"};
input adxLength = 8;#, title="ADX period")
input dmiLength = 9;#(9, title="DMI Length")
input MendozaLimit = 20;

def na = Double.NaN;
#fixnan(data)
script fixnan {
    input data1 = 0;
    def data2;
    if BarNumber() == 1
    then {
        data2 = 0;
    } else if IsNaN(data1)
    then {
        data2 = data2[1];
    } else {
        data2 = data1;
    }
    plot valid = data2;
}
#dirmov(len) =>
script dirmov {
    input len = 8;
    def up = high - high[1];
    def down = -(low - low[1]);
    def tr = TrueRange(high, close, low);
    def truerange = WildersAverage(tr, len);
    def plus1 = fixnan(100 * WildersAverage(If(up > down and up > 0, up, 0), len) / truerange);
    def minus = fixnan(100 * WildersAverage(If(down > up and down > 0, down, 0), len) / truerange);
    plot plus = plus1;
    plot min = minus;
}
#adx(LWdilength, LWadxlength) =>
script adx {
    input LWdilength = 8;
    input LWadxlength = 9;
    def plus = dirmov(LWdilength).plus;
    def minus = dirmov(LWdilength).min;
    def sum = plus + minus;
    def adx = 100 * WildersAverage(AbsValue(plus - minus) / (If(sum == 0, 1, sum)), LWadxlength);
    plot ad = adx;
    plot pls = plus;
    plot mins = minus;
}
def ADX = ADX(dmiLength, adxLength).ad;
def up = ADX(dmiLength, adxLength).pls;
def down = ADX(dmiLength, adxLength).mins;
def LWADX = (ADX - 15) * 2.5;
def adxcolor = if up > down and LWADX >= 100 then 2 else
               if up > down and LWADX < 100 then 1 else
               if up <= down and LWADX >= 100 then -2 else
               if up <= down and LWADX < 100 then -1 else 0;

plot ZeroLine = if IsNaN(close) then na else 0;   # "Chop Zone"
ZeroLine.SetDefaultColor(Color.DARK_GRAY);
plot MendozaLine = if IsNaN(close) then na else MendozaLimit; # "Mendoza Line"
MendozaLine.SetDefaultColor(Color.GREEN);
plot Threshold = if IsNaN(close) then na else 100; # "Extreme Zone"
Threshold.SetDefaultColor(Color.RED);
plot TrendStrength = if IsNaN(close) then na else LWADX; # "Trend Strength"
TrendStrength.AssignValueColor(if adxcolor == 2 then Color.GREEN else
                               if adxcolor == 1 then Color.DARK_GREEN else
                               if adxcolor == -2 then Color.RED else Color.DARK_RED);
TrendStrength.SetLineWeight(2);
plot histogram = if IsNaN(close) then na else LWADX;
histogram.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
histogram.AssignValueColor(if LWADX < MendozaLimit then Color.GRAY else
                           if adxcolor == 2 then Color.GREEN else
                           if adxcolor == 1 then Color.DARK_GREEN else
                           if adxcolor == -2 then Color.RED else Color.ORANGE);
histogram.SetLineWeight(3);
#--- Bar Color
AssignPriceColor(if !ColorBars then Color.CURRENT else
                 if LWADX < MendozaLimit then Color.Light_GRAY else
                 if adxcolor == 2 then Color.DARK_GREEN else
                 if adxcolor == 1 then Color.GREEN else
                 if adxcolor == -2 then Color.RED else Color.MAGENTA);
AssignPriceColor(if !ColorSignalBar then Color.CURRENT else
                 if LWADX crosses above MendozaLimit and LWADX[1] > LWADX[2] then Color.CYAN else
                 if LWADX crosses below MendozaLimit and LWADX[1] < LWADX[2] then Color.MAGENTA else
                    Color.CURRENT);
#ALV ADDED CLOUD
AddCloud(
    if LWADX >= MendozaLimit and adxcolor > 0 then  Double.POSITIVE_INFINITY else Double.NaN,
    if LWADX >= MendozaLimit and adxcolor > 0 then Double.NEGATIVE_INFINITY else Double.NaN, Color.CYAN
);
AddCloud(
    if LWADX >= MendozaLimit and adxcolor < 0 then Double.POSITIVE_INFINITY else Double.NaN,
    if LWADX >= MendozaLimit and adxcolor < 0 then Double.NEGATIVE_INFINITY else Double.NaN, Color.PINK
);

#---- Alerts
def green = adxcolor > 0;
def red = adxcolor < 0;
Alert(alerts and green and !green[1], "Trending Up!", Alert.BAR, sound);
Alert(alerts and red and !red[1], "Trending Down!", Alert.BAR, sound);

#---END Code
 
  • Love
Reactions: IPA
Hi Samer
Thank you so much for your work and contribution to this community. I love this indicator which helps me a lot when combined with other indicators. I tried adding a cloud and using it as an upper indicator to see the results as the chart is being constructed. I am not a coder, just added cloud statements from another indicator and tried to make it work. There are some spaces when the cloud is missing the corresponding color (see arrows in upper and boxes in lower studies). I am not sure what is missing. I went over different posts related to clouds here but couldn't solve the issue.
Kindly request your help to fix this, if possible.
Thank you!!

View attachment 19218
The code is the same as above except for the cloud addition.



Code:
input ColorBars = no;
input ColorSignalBar = no;
input alerts   = no;
input sound    = {default "NoSound", "Ding", "Bell", "Chimes", "Ring"};
input adxLength = 8;#, title="ADX period")
input dmiLength = 9;#(9, title="DMI Length")
input MendozaLimit = 20;

def na = Double.NaN;
#fixnan(data)
script fixnan {
    input data1 = 0;
    def data2;
    if BarNumber() == 1
    then {
        data2 = 0;
    } else if IsNaN(data1)
    then {
        data2 = data2[1];
    } else {
        data2 = data1;
    }
    plot valid = data2;
}
#dirmov(len) =>
script dirmov {
    input len = 8;
    def up = high - high[1];
    def down = -(low - low[1]);
    def tr = TrueRange(high, close, low);
    def truerange = WildersAverage(tr, len);
    def plus1 = fixnan(100 * WildersAverage(If(up > down and up > 0, up, 0), len) / truerange);
    def minus = fixnan(100 * WildersAverage(If(down > up and down > 0, down, 0), len) / truerange);
    plot plus = plus1;
    plot min = minus;
}
#adx(LWdilength, LWadxlength) =>
script adx {
    input LWdilength = 8;
    input LWadxlength = 9;
    def plus = dirmov(LWdilength).plus;
    def minus = dirmov(LWdilength).min;
    def sum = plus + minus;
    def adx = 100 * WildersAverage(AbsValue(plus - minus) / (If(sum == 0, 1, sum)), LWadxlength);
    plot ad = adx;
    plot pls = plus;
    plot mins = minus;
}
def ADX = ADX(dmiLength, adxLength).ad;
def up = ADX(dmiLength, adxLength).pls;
def down = ADX(dmiLength, adxLength).mins;
def LWADX = (ADX - 15) * 2.5;
def adxcolor = if up > down and LWADX >= 100 then 2 else
               if up > down and LWADX < 100 then 1 else
               if up <= down and LWADX >= 100 then -2 else
               if up <= down and LWADX < 100 then -1 else 0;

plot ZeroLine = if IsNaN(close) then na else 0;   # "Chop Zone"
ZeroLine.SetDefaultColor(Color.DARK_GRAY);
plot MendozaLine = if IsNaN(close) then na else MendozaLimit; # "Mendoza Line"
MendozaLine.SetDefaultColor(Color.GREEN);
plot Threshold = if IsNaN(close) then na else 100; # "Extreme Zone"
Threshold.SetDefaultColor(Color.RED);
plot TrendStrength = if IsNaN(close) then na else LWADX; # "Trend Strength"
TrendStrength.AssignValueColor(if adxcolor == 2 then Color.GREEN else
                               if adxcolor == 1 then Color.DARK_GREEN else
                               if adxcolor == -2 then Color.RED else Color.DARK_RED);
TrendStrength.SetLineWeight(2);
plot histogram = if IsNaN(close) then na else LWADX;
histogram.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
histogram.AssignValueColor(if LWADX < MendozaLimit then Color.GRAY else
                           if adxcolor == 2 then Color.GREEN else
                           if adxcolor == 1 then Color.DARK_GREEN else
                           if adxcolor == -2 then Color.RED else Color.ORANGE);
histogram.SetLineWeight(3);
#--- Bar Color
AssignPriceColor(if !ColorBars then Color.CURRENT else
                 if LWADX < MendozaLimit then Color.Light_GRAY else
                 if adxcolor == 2 then Color.DARK_GREEN else
                 if adxcolor == 1 then Color.GREEN else
                 if adxcolor == -2 then Color.RED else Color.MAGENTA);
AssignPriceColor(if !ColorSignalBar then Color.CURRENT else
                 if LWADX crosses above MendozaLimit and LWADX[1] > LWADX[2] then Color.CYAN else
                 if LWADX crosses below MendozaLimit and LWADX[1] < LWADX[2] then Color.MAGENTA else
                    Color.CURRENT);
#ALV ADDED CLOUD
AddCloud(
    if LWADX >= MendozaLimit and adxcolor > 0 then  Double.POSITIVE_INFINITY else Double.NaN,
    if LWADX >= MendozaLimit and adxcolor > 0 then Double.NEGATIVE_INFINITY else Double.NaN, Color.CYAN
);
AddCloud(
    if LWADX >= MendozaLimit and adxcolor < 0 then Double.POSITIVE_INFINITY else Double.NaN,
    if LWADX >= MendozaLimit and adxcolor < 0 then Double.NEGATIVE_INFINITY else Double.NaN, Color.PINK
);

#---- Alerts
def green = adxcolor > 0;
def red = adxcolor < 0;
Alert(alerts and green and !green[1], "Trending Up!", Alert.BAR, sound);
Alert(alerts and red and !red[1], "Trending Down!", Alert.BAR, sound);

#---END Code
Cloud plot after confirmed condition in TOS.

try to replace the added cloud with the below. It won't resolve the issue but may fill the gaps.

CSS:
def limit = LWADX >= MendozaLimit;
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;
def posUp = if limit and adxcolor > 0 then pos else
         if limit and adxcolor < 0 then neg else posUp[1];
plot posUp1 = if IsNaN(close) then na else posUp;

def posDn = if limit and adxcolor < 0 then pos else
            if limit and adxcolor > 0 then neg else posDn[1];
plot posDn1 = if IsNaN(close) then na else posDn;


AddCloud(posUp1, posDn1, Color.DARK_GREEN, Color.DARK_RED);
 
  • Love
Reactions: IPA
Cloud plot after confirmed condition in TOS.

try to replace the added cloud with the below. It won't resolve the issue but may fill the gaps.

CSS:
def limit = LWADX >= MendozaLimit;
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;
def posUp = if limit and adxcolor > 0 then pos else
         if limit and adxcolor < 0 then neg else posUp[1];
plot posUp1 = if IsNaN(close) then na else posUp;

def posDn = if limit and adxcolor < 0 then pos else
            if limit and adxcolor > 0 then neg else posDn[1];
plot posDn1 = if IsNaN(close) then na else posDn;


AddCloud(posUp1, posDn1, Color.DARK_GREEN, Color.DARK_RED);
Excellent! I'll try it. Thank you very much sir.
 
check the below.

CSS:
#// This is a different way of plotting ADX used by Leaf_West at http://tradingwithleafwest.net/.
#// The criteria for plotting ADX are described in the educational info.
# https://www.tradingview.com/script/MgcmUYd4-ADX-Trend-Strength-Leaf-West-style/
#// This is my attempt to replicate Leaf_West's indicator.
#// The BATS data feed has the usual issues.  Realtime data is the way to go.
#study("Trend Strength/ADX Leaf_West style"
# Converted and mod by Sam4Cok@Samer800 - 11/2022
# Update, added alerts Sam4Cok@Samer800 - 11/2022;
declare lower;
input ColorBars = yes;
input ColorSignalBar = yes;
input alerts   = no;
input sound    = {default "NoSound", "Ding", "Bell", "Chimes", "Ring"};
input adxLength = 8;#, title="ADX period")
input dmiLength = 9;#(9, title="DMI Length")
input MendozaLimit = 20;

def na = Double.NaN;
#fixnan(data)
script fixnan {
    input data1 = 0;
    def data2;
    if BarNumber() == 1
    then {
        data2 = 0;
    } else if IsNaN(data1)
    then {
        data2 = data2[1];
    } else {
        data2 = data1;
    }
    plot valid = data2;
}
#dirmov(len) =>
script dirmov {
    input len = 8;
    def up = high - high[1];
    def down = -(low - low[1]);
    def tr = TrueRange(high, close, low);
    def truerange = WildersAverage(tr, len);
    def plus1 = fixnan(100 * WildersAverage(If(up > down and up > 0, up, 0), len) / truerange);
    def minus = fixnan(100 * WildersAverage(If(down > up and down > 0, down, 0), len) / truerange);
    plot plus = plus1;
    plot min = minus;
}
#adx(LWdilength, LWadxlength) =>
script adx {
    input LWdilength = 8;
    input LWadxlength = 9;
    def plus = dirmov(LWdilength).plus;
    def minus = dirmov(LWdilength).min;
    def sum = plus + minus;
    def adx = 100 * WildersAverage(AbsValue(plus - minus) / (If(sum == 0, 1, sum)), LWadxlength);
    plot ad = adx;
    plot pls = plus;
    plot mins = minus;
}
def ADX = ADX(dmiLength, adxLength).ad;
def up = ADX(dmiLength, adxLength).pls;
def down = ADX(dmiLength, adxLength).mins;
def LWADX = (ADX - 15) * 2.5;
def adxcolor = if up > down and LWADX >= 100 then 2 else
               if up > down and LWADX < 100 then 1 else
               if up <= down and LWADX >= 100 then -2 else
               if up <= down and LWADX < 100 then -1 else 0;

plot ZeroLine = if IsNaN(close) then na else 0;   # "Chop Zone"
ZeroLine.SetDefaultColor(Color.DARK_GRAY);
plot MendozaLine = if IsNaN(close) then na else MendozaLimit; # "Mendoza Line"
MendozaLine.SetDefaultColor(Color.GREEN);
plot Threshold = if IsNaN(close) then na else 100; # "Extreme Zone"
Threshold.SetDefaultColor(Color.RED);
plot TrendStrength = if IsNaN(close) then na else LWADX; # "Trend Strength"
TrendStrength.AssignValueColor(if adxcolor == 2 then Color.GREEN else
                               if adxcolor == 1 then Color.DARK_GREEN else
                               if adxcolor == -2 then Color.RED else Color.DARK_RED);
TrendStrength.SetLineWeight(2);
plot histogram = if IsNaN(close) then na else LWADX;
histogram.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
histogram.AssignValueColor(if LWADX < MendozaLimit then Color.GRAY else
                           if adxcolor == 2 then Color.GREEN else
                           if adxcolor == 1 then Color.DARK_GREEN else
                           if adxcolor == -2 then Color.RED else Color.DARK_RED);
histogram.SetLineWeight(3);
#--- Bar Color
AssignPriceColor(if !ColorBars then Color.CURRENT else
                 if LWADX < MendozaLimit then Color.GRAY else
                 if adxcolor == 2 then Color.GREEN else
                 if adxcolor == 1 then Color.DARK_GREEN else
                 if adxcolor == -2 then Color.RED else Color.DARK_RED);
AssignPriceColor(if !ColorSignalBar then Color.CURRENT else
                 if LWADX crosses above MendozaLimit and LWADX[1] > LWADX[2] then Color.CYAN else
                 if LWADX crosses below MendozaLimit and LWADX[1] < LWADX[2] then Color.MAGENTA else
                    Color.CURRENT);

#---- Alerts
def green = adxcolor>0;
def red = adxcolor<0;
Alert(alerts and green and !green[1], "Trending Up!", Alert.BAR, sound);
Alert(alerts and red and !red[1], "Trending Down!", Alert.BAR, sound);

#---END Code
Is there a way to plot and up and down arrow for only the first green bar and the first red bar (not the dark_green and dark_red) of this part of the code:


plot TrendStrength = if IsNaN(close) then na else LWADX; # "Trend Strength"
TrendStrength.AssignValueColor(if adxcolor == 2 then Color.GREEN else
if adxcolor == 1 then Color.DARK_GREEN else
if adxcolor == -2 then Color.RED else Color.DARK_RED);
 
Is there a way to plot and up and down arrow for only the first green bar and the first red bar (not the dark_green and dark_red) of this part of the code:


plot TrendStrength = if IsNaN(close) then na else LWADX; # "Trend Strength"
TrendStrength.AssignValueColor(if adxcolor == 2 then Color.GREEN else
if adxcolor == 1 then Color.DARK_GREEN else
if adxcolor == -2 then Color.RED else Color.DARK_RED);
add this at the end of the code

CSS:
def sigUp = adxcolor == 2 and adxcolor[1] != 2;
def sigDn = adxcolor == -2 and adxcolor[1] != -2;

plot arrowUp = if sigUp then LWADX else na;
plot arrowDn = if sigDn then LWADX else na;
arrowUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
arrowDn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
arrowUp.SetDefaultColor(Color.CYAN);
arrowDn.SetDefaultColor(Color.MAGENTA);
 
add this at the end of the code

CSS:
def sigUp = adxcolor == 2 and adxcolor[1] != 2;
def sigDn = adxcolor == -2 and adxcolor[1] != -2;

plot arrowUp = if sigUp then LWADX else na;
plot arrowDn = if sigDn then LWADX else na;
arrowUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
arrowDn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
arrowUp.SetDefaultColor(Color.CYAN);
arrowDn.SetDefaultColor(Color.MAGENTA);
Thank you!!!
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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