Hammond B3's ADX for ThinkorSwim

tomsk

Well-known member
VIP
To enable easier search, I have relocated this cool ADX label indicator from Hammond B3 here. Merry Xmas folks

Code:
## HAMMOND B3'S "B3_ADX"
##
## This study is based on several ADX theories by several traders combined.
## HAMMOND B3 didn't come up with the methodology for the formula,
## merely combined the logic of several others into one easy to use study.
#---
### DIRECTIONS FOR USE ::
## 1) LABEL BOXES POPUP AND TELL YOU WHAT TO DO (or think about), THOUGH TWO BOXES PERMANENTLY EXIST
##        a. A MODE BOX THAT TELLS YOU THE STUDY'S CURRENT DIRECTIONAL BIAS, IF ANY
##        b. TREND DECAY IS TELLING YOU HOW MUCH THE TREND HAS WEAKEND
##            (0% = STRONGLY TRENDING & -100% = TREND IS OVER & NO TREND IS POSSIBLE)
##            (Brighter the Box = Stronger the Trend)
## 2) BIG ARROWS MEAN THE SAFEST "WITH THE TREND" ENTRIES (DURING LONG/SHORT MODES) (no gaurantees)
## 3) SMALL GRAY ARROWS DURING SCALP MODE FOR WEAK TRENDS OR NO CONFIRMED TREND (riskier but sometimes trend starters)
## 4) SQUARES MEAN SCALE OR EXIT IF YOU WISH NOT TO BE GREEDY OR DO NOTHING (profit early and often method)
## 5) MAGENTA TRIANGLES ARE A POINT OF DECISION, CHOOSE:
##        a. EXIT (AGAIN FOR THE NOT SO GREEDY AND IS THE RISK ADVERSE CHOICE)
##        b. ADD (TRENDS TEND TO CONTINUE RATHER THAN REVERSE, FOR THE AGGRESSIVE POSSITION BUILDERS)
##        c. BET AGAINST THE TREND (FOR EARLIEST REVERSAL ENTRY, !ADVANCED TRADERS ONLY!)
##        d. DO NOTHING (WAIT FOR NEXT EXIT DECISION)
## 6) BOXES POPUP SOMETIMES GIVING INFORMATION:
##        a. WHEN DIRECTIONAL DOMINANCE IS CHANGING
##            (if staying on trend is important, this is an exit if the signal goes against you)
##        b. WHEN REVERSAL RISK IS HIGH (be cautious as no definite directional dominance exists)
##        c. DURING DIRECTIONAL BREAKOUT OF THE INDICATOR
##            (breakout of trend; trade entry if price is also breaking the corresponding new Hi or Lo)
##        d. WHEN A TREND COMES TO AN END  (yellow dot)
##          (the risk adverse trader would want to exit here, others begin considering scalp mode)
## 7) THE 20 BAR EXPONENTIAL MOVING AVERAGE IS USED TO GIVE A POSSIBLE BETTER VALUED ENTRY
##        BOX APPEARS WHEN THE DOMINANCE OF ONE DIRECTION IS PRESENT BUT PRICE IS ON OPPOSITE SIDE OF EMA (or touching)
##        (ADVANCED TRADERS WILL WAIT FOR THE TOUCH OF 20ema BEFORE ENTRY, YOU CAN MISS OPPORTUNIES WAITING)
##        (By this method, enter trade upon popup of 20ema box AFTER & IF the MATCHING red/green arrow LAST signaled)
#---
## /ENJOY!


declare upper;

## DMI/ADX ::
input ADXMA = 13;
input length = 8;
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;
def DX = if ("DI+" + "DI-" > 0) then 100 * AbsValue("DI+" - "DI-") / ("DI+" + "DI-") else 0;
def ADX = MovingAverage(averageType, DX, ADXma);
def ADXHIGH = Highest(ADX, 50);
## /END DMI/ADX

## / BEGIN TREND CONSTITUTE ::
input trendconstitute = 25;
def xline = trendconstitute;

## /END TREND CONSTITUTE

## BEGIN MODE SETTINGS ::
def longmode = ADX > trendconstitute and "DI+" > "DI-";
def shortmode = ADX > trendconstitute and "DI+" < "DI-";
def scalplong = ADX <= trendconstitute and "DI+" > "DI-" and "DI+" > trendconstitute;
def scalpshort = ADX <= trendconstitute and "DI+" < "DI-" and "DI-" > trendconstitute;
AddLabel( yes , if longmode then "ADXBullMode" else
                    if shortmode then "ADXBearMode" else
                    if scalplong then "ADXScalp-LMode" else
                    if scalpshort then "ADXScalp-SMode" else
                    "No-Man's Land",
                        if longmode and ((1 - (ADX - trendconstitute) / (ADXHIGH - trendconstitute)) * -100) > -50 then Color.UPTICK else
                        if longmode and ((1 - (ADX - trendconstitute) / (ADXHIGH - trendconstitute)) * -100) <= -50 then Color.dark_green else
                        if shortmode and ((1 - (ADX - trendconstitute) / (ADXHIGH - trendconstitute)) * -100) > -50 then Color.DOWNTICK else 
                        if shortmode and ((1 - (ADX - trendconstitute) / (ADXHIGH - trendconstitute)) * -100) <= -50 then Color.dark_red else 
                        if scalplong then Color.LIGHT_GREEN else
                        if scalpshort then Color.PINK else Color.GRAY);
## /END MODES

## BEGIN SIGNALS
input noisefilter = 20.1;
input scaling = 45;
input countertrend = 10;
plot longsafe = if (ADX > trendconstitute and "DI+" > "DI-" and  "DI+"[1] <= "DI-"[1] and "DI-" <= noisefilter
                                          and AbsValue("DI+" - "DI-") > 5.5)
                or (ADX > trendconstitute and ADX[1] <= trendconstitute and "DI+" > "DI-" and "DI-" <= noisefilter
                                          and AbsValue("DI+" - "DI-") > 5.5)
                or ("DI+" > trendconstitute and "DI+"[1] <= trendconstitute and ADX > trendconstitute
                                            and "DI-" <= noisefilter and AbsValue("DI+" - "DI-") > 5.5)
                or (ADX > trendconstitute and "DI+"[1] > "DI-"[1] and "DI+"[2] <= "DI-"[2] and "DI-"[1] >= noisefilter
                                          and AbsValue("DI+" - "DI-") > 5.5 and "DI+" > trendconstitute)
                then Low else Double.NaN;
plot longscalp = if  ADX <= trendconstitute and "DI+" > "DI-" and "DI+" > trendconstitute and "DI+"[1] <= trendconstitute
                 then Low else Double.NaN;
plot shortsafe = if (ADX > trendconstitute and "DI+" < "DI-" and  "DI+"[1] >= "DI-"[1]
                                           and "DI+" <= noisefilter and AbsValue("DI+" - "DI-") > 5.5)
                 or (ADX > trendconstitute and ADX[1] <= trendconstitute and "DI+" < "DI-" and "DI+" <= noisefilter
                                           and AbsValue("DI+" - "DI-") > 5.5)
                 or ("DI-" > trendconstitute and "DI-"[1] <= trendconstitute and ADX > trendconstitute
                                             and "DI+" <= noisefilter and AbsValue("DI+" - "DI-") > 5.5)
                 or (ADX > trendconstitute and "DI+"[1] < "DI-"[1] and "DI+"[2] >= "DI-"[2] and "DI+"[1] >= noisefilter
                                           and AbsValue("DI+" - "DI-") > 5.5 and "DI-" > trendconstitute)
                 then High else Double.NaN;
plot shortscalp = if ADX <= trendconstitute and "DI+" < "DI-" and "DI-" > trendconstitute
                                            and "DI-"[1] <= trendconstitute then High else Double.NaN;
plot counterlong = if "DI+" crosses above countertrend then Low else Double.NaN;
plot countershort = if "DI-" crosses above countertrend then High else Double.NaN;
plot scalelong = if "DI+" crosses below scaling then high else Double.NaN;
plot scaleshort = if "DI-" crosses below scaling then low else Double.NaN;
plot trendend = if ADX crosses below trendconstitute then Open else double.nan;
longsafe.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
longsafe.setdefaultColor(Color.UPTICK);
longsafe.SetLineWeight(2);
longscalp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
longscalp.setdefaultColor(Color.GRAY);
longscalp.SetLineWeight(1);
shortsafe.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
shortsafe.setdefaultColor(Color.DOWNTICK);
shortsafe.SetLineWeight(2);
shortscalp.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
shortscalp.setdefaultColor(Color.GRAY);
shortscalp.SetLineWeight(1);
counterlong.SetPaintingStrategy(PaintingStrategy.LINE_VS_TRIANGLES);
counterlong.setdefaultColor(Color.MAGENTA);
counterlong.SetLineWeight(5);
countershort.SetPaintingStrategy(PaintingStrategY.LINE_VS_TRIANGLES);
countershort.setdefaultColor(Color.MAGENTA);
countershort.SetLineWeight(5);
scalelong.SetPaintingStrategy(PaintingStrategy.SQUARES);
scalelong.setdefaultColor(Color.LIGHT_GREEN);
scalelong.SetLineWeight(5);
scaleshort.SetPaintingStrategy(PaintingStrategy.SQUARES);
scaleshort.setdefaultColor(Color.PINK);
scaleshort.SetLineWeight(5);
trendend.SetPaintingStrategy(PaintingStrategy.points);
trendend.setdefaultColor(createColor(206, 207, 0));
trendend.SetLineWeight(5);
AddCloud(if "DI+" > "DI-" and ADX > trendconstitute then high else Double.NaN, high + ATR, Color.GREEN, Color.green);
AddCloud(if "DI+" < "DI-" and ADX > trendconstitute then low else Double.NaN, low - ATR, Color.RED, Color.red);
AddLabel( yes , if (ADX > trendconstitute and "DI+" > "DI-" and  "DI+"[1] <= "DI-"[1] and "DI-" <= noisefilter
                                          and AbsValue("DI+" - "DI-") > 5.5)
                or (ADX > trendconstitute and ADX[1] <= trendconstitute and "DI+" > "DI-" and "DI-" <= noisefilter
                                          and AbsValue("DI+" - "DI-") > 5.5)
                or ("DI+" > trendconstitute and "DI+"[1] <= trendconstitute and ADX > trendconstitute
                                            and "DI-" <= noisefilter and AbsValue("DI+" - "DI-") > 5.5)
                or (ADX > trendconstitute and "DI+"[1] > "DI-"[1] and "DI+"[2] <= "DI-"[2] and "DI-"[1] >= noisefilter
                                          and AbsValue("DI+" - "DI-") > 5.5 and "DI+" > trendconstitute) then "ADX L-Entry"
            else if ADX <= trendconstitute and "DI+" > "DI-" and "DI+" > trendconstitute and "DI+"[1] <= trendconstitute then "ADX L-Scalp"
            else if (ADX > trendconstitute and "DI+" < "DI-" and  "DI+"[1] >= "DI-"[1]
                                           and "DI+" <= noisefilter and AbsValue("DI+" - "DI-") > 5.5)
                 or (ADX > trendconstitute and ADX[1] <= trendconstitute and "DI+" < "DI-" and "DI+" <= noisefilter
                                           and AbsValue("DI+" - "DI-") > 5.5)
                 or ("DI-" > trendconstitute and "DI-"[1] <= trendconstitute and ADX > trendconstitute
                                             and "DI+" <= noisefilter and AbsValue("DI+" - "DI-") > 5.5)
                 or (ADX > trendconstitute and "DI+"[1] < "DI-"[1] and "DI+"[2] >= "DI-"[2] and "DI+"[1] >= noisefilter
                                           and AbsValue("DI+" - "DI-") > 5.5 and "DI-" > trendconstitute) then "ADX S-Entry"
            else if ADX <= trendconstitute and "DI+" < "DI-" and "DI-" > trendconstitute
                                            and "DI-"[1] <= trendconstitute then "ADX S-Scalp"
            else if "DI+" crosses above countertrend then "ADX Countertrend+ Exit, Add Short or Counter Long"
            else if "DI-" crosses above countertrend then "ADX Countertrend- Exit, Add Long or Counter Short"
            else if "DI+" crosses below scaling then "ADX Scale Long"
            else if "DI-" crosses below scaling then "ADX Scale Short"
            else "ADX Hold",
            if (ADX > trendconstitute and "DI+" > "DI-" and  "DI+"[1] <= "DI-"[1] and "DI-" <= noisefilter
                                          and AbsValue("DI+" - "DI-") > 5.5)
                or (ADX > trendconstitute and ADX[1] <= trendconstitute and "DI+" > "DI-" and "DI-" <= noisefilter
                                          and AbsValue("DI+" - "DI-") > 5.5)
                or ("DI+" > trendconstitute and "DI+"[1] <= trendconstitute and ADX > trendconstitute
                                            and "DI-" <= noisefilter and AbsValue("DI+" - "DI-") > 5.5)
                or (ADX > trendconstitute and "DI+"[1] > "DI-"[1] and "DI+"[2] <= "DI-"[2] and "DI-"[1] >= noisefilter
                                          and AbsValue("DI+" - "DI-") > 5.5 and "DI+" > trendconstitute) then color.green
            else if ADX <= trendconstitute and "DI+" > "DI-" and "DI+" > trendconstitute and "DI+"[1] <= trendconstitute then color.light_green
            else if (ADX > trendconstitute and "DI+" < "DI-" and  "DI+"[1] >= "DI-"[1]
                                           and "DI+" <= noisefilter and AbsValue("DI+" - "DI-") > 5.5)
                 or (ADX > trendconstitute and ADX[1] <= trendconstitute and "DI+" < "DI-" and "DI+" <= noisefilter
                                           and AbsValue("DI+" - "DI-") > 5.5)
                 or ("DI-" > trendconstitute and "DI-"[1] <= trendconstitute and ADX > trendconstitute
                                             and "DI+" <= noisefilter and AbsValue("DI+" - "DI-") > 5.5)
                 or (ADX > trendconstitute and "DI+"[1] < "DI-"[1] and "DI+"[2] >= "DI-"[2] and "DI+"[1] >= noisefilter
                                           and AbsValue("DI+" - "DI-") > 5.5 and "DI-" > trendconstitute) then color.red
            else if ADX <= trendconstitute and "DI+" < "DI-" and "DI-" > trendconstitute
                                            and "DI-"[1] <= trendconstitute then color.pink
            else if "DI+" crosses above countertrend then color.magenta
            else if "DI-" crosses above countertrend then color.magenta
            else if "DI+" crosses below scaling then color.Dark_Green
            else if "DI-" crosses below scaling then color.dark_red
            else createcolor(30, 110, 190));

def reversal = if highest(adx, adxma) < 25 then 1 else 0;
AddLabel( if reversal > 0 then yes else no, if reversal > 0 then "Reversal Warning!" else ":",
                if reversal > 0 then color.YELLOW else color.gray);
AddLabel( if trendend then yes else no, if trendend then "End of Trend!" else ":",
                if trendend then color.YELLOW else color.gray);
## /END SIGNALS

## BEGIN HIGH PASSING ::
def diuphi = Highest("DI+", 30);
def didnhi = Highest("DI-", 30);
# moved up :: def ADXHIGH = Highest(ADX, 50);

def decay = (1 - (ADX - trendconstitute) / (ADXHIGH - trendconstitute)) * 100;
AddLabel( yes , if ADX > 25 and decay <= 0 then "TRENDING!"
            else if ADX > 25 then
            AsText((1 - (ADX - trendconstitute) / (ADXHIGH - trendconstitute)) * -100, NumberFormat.TWO_DECIMAL_PLACES) + "%TrendDecay" 
            else "No Trend",
            if ADX <= 25 then createcolor(90, 90, 90)
            else if decay <= 1 then createcolor(0, 233, 254)
            else if decay <= 23.6 then  createcolor(0, 195, 220)
            else if decay <= 38.2 then  createcolor(0, 163, 200)
            else if decay <= 50 then  createcolor(20, 147, 170)
            else if decay <= 61.8 then  createcolor(45, 132, 160)
            else if decay <= 78.6 then  createcolor(70, 120, 150)
            else if decay > 61.8 then  createcolor(100, 110, 140)     
            else Color.GRAY);
AddLabel( yes , if "DI+" - diuphi >= 0 and "DI+" > trendconstitute then "DMI +Break+"
            else if "DI-" - didnhi >= 0 and "DI-" > trendconstitute then "DMI -Break-"
            else if "DI+" > didnhi and "DI+"[1] <= didnhi[1] then "+Dominance+"
            else if "DI-" > diuphi and "DI-"[1] <= diuphi[1] then "-Dominance-"
            else ":",
            if "DI+" - diuphi >= 0 and "DI+" > trendconstitute then Color.GREEN
            else if "DI-" - didnhi >= 0 and "DI-" > trendconstitute then Color.RED
            else if "DI+" > didnhi and "DI+"[1] <= didnhi[1] then Color.uptick
            else if "DI-" > diuphi and "DI-"[1] <= diuphi[1] then color.downtick
            else Color.dark_Gray);
## /END HIGH PASSING

## BEGIN EXPONENTIAL MA BIAS ::
def x = close;
def twentyema = expAverage(close, 20);
AddLabel( YES , if AbsValue(close - twentyema) <= .0149 then "Touching EMA @" + round(twentyema,2)
                      else if ADX > trendconstitute and "DI+" > "DI-" and close <= twentyema then "L-Value @" + round(twentyema,2)
                      else if ADX > trendconstitute and "DI+" < "DI-" and close >= twentyema then "S-Value @" + round(twentyema,2)
                      else "20ema=" + astext(twentyema),
                      if ADX > trendconstitute and "DI+" > "DI-" and close <= twentyema then createcolor(10, 220, 43)
                      else if ADX > trendconstitute and "DI+" < "DI-" and close >= twentyema then createcolor(220, 10, 43)
                      else if ADX > trendconstitute and "DI+" > "DI-" then createcolor(50, 100, 53)
                      else if ADX > trendconstitute and "DI+" < "DI-" then createcolor(100, 50, 53)
                      else color.gray);
## /END EXPONENTIAL MA BIAS
## /END STUDY
 
Last edited:
I understand tom is away for now, does anyone knows what does Point 6 "BOXES POPUP" mean?
 
Last edited:
To enable easier search, I have relocated this cool ADX label indicator from Hammond B3 here. Merry Xmas folks

Code:
## HAMMOND B3'S "B3_ADX"
##
## This study is based on several ADX theories by several traders combined.
## HAMMOND B3 didn't come up with the methodology for the formula,
## merely combined the logic of several others into one easy to use study.
#---
### DIRECTIONS FOR USE ::
## 1) LABEL BOXES POPUP AND TELL YOU WHAT TO DO (or think about), THOUGH TWO BOXES PERMANENTLY EXIST
##        a. A MODE BOX THAT TELLS YOU THE STUDY'S CURRENT DIRECTIONAL BIAS, IF ANY
##        b. TREND DECAY IS TELLING YOU HOW MUCH THE TREND HAS WEAKEND
##            (0% = STRONGLY TRENDING & -100% = TREND IS OVER & NO TREND IS POSSIBLE)
##            (Brighter the Box = Stronger the Trend)
## 2) BIG ARROWS MEAN THE SAFEST "WITH THE TREND" ENTRIES (DURING LONG/SHORT MODES) (no gaurantees)
## 3) SMALL GRAY ARROWS DURING SCALP MODE FOR WEAK TRENDS OR NO CONFIRMED TREND (riskier but sometimes trend starters)
## 4) SQUARES MEAN SCALE OR EXIT IF YOU WISH NOT TO BE GREEDY OR DO NOTHING (profit early and often method)
## 5) MAGENTA TRIANGLES ARE A POINT OF DECISION, CHOOSE:
##        a. EXIT (AGAIN FOR THE NOT SO GREEDY AND IS THE RISK ADVERSE CHOICE)
##        b. ADD (TRENDS TEND TO CONTINUE RATHER THAN REVERSE, FOR THE AGGRESSIVE POSSITION BUILDERS)
##        c. BET AGAINST THE TREND (FOR EARLIEST REVERSAL ENTRY, !ADVANCED TRADERS ONLY!)
##        d. DO NOTHING (WAIT FOR NEXT EXIT DECISION)
## 6) BOXES POPUP SOMETIMES GIVING INFORMATION:
##        a. WHEN DIRECTIONAL DOMINANCE IS CHANGING
##            (if staying on trend is important, this is an exit if the signal goes against you)
##        b. WHEN REVERSAL RISK IS HIGH (be cautious as no definite directional dominance exists)
##        c. DURING DIRECTIONAL BREAKOUT OF THE INDICATOR
##            (breakout of trend; trade entry if price is also breaking the corresponding new Hi or Lo)
##        d. WHEN A TREND COMES TO AN END  (yellow dot)
##          (the risk adverse trader would want to exit here, others begin considering scalp mode)
## 7) THE 20 BAR EXPONENTIAL MOVING AVERAGE IS USED TO GIVE A POSSIBLE BETTER VALUED ENTRY
##        BOX APPEARS WHEN THE DOMINANCE OF ONE DIRECTION IS PRESENT BUT PRICE IS ON OPPOSITE SIDE OF EMA (or touching)
##        (ADVANCED TRADERS WILL WAIT FOR THE TOUCH OF 20ema BEFORE ENTRY, YOU CAN MISS OPPORTUNIES WAITING)
##        (By this method, enter trade upon popup of 20ema box AFTER & IF the MATCHING red/green arrow LAST signaled)
#---
## /ENJOY!


declare upper;

## DMI/ADX ::
input ADXMA = 13;
input length = 8;
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;
def DX = if ("DI+" + "DI-" > 0) then 100 * AbsValue("DI+" - "DI-") / ("DI+" + "DI-") else 0;
def ADX = MovingAverage(averageType, DX, ADXma);
def ADXHIGH = Highest(ADX, 50);
## /END DMI/ADX

## / BEGIN TREND CONSTITUTE ::
input trendconstitute = 25;
def xline = trendconstitute;

## /END TREND CONSTITUTE

## BEGIN MODE SETTINGS ::
def longmode = ADX > trendconstitute and "DI+" > "DI-";
def shortmode = ADX > trendconstitute and "DI+" < "DI-";
def scalplong = ADX <= trendconstitute and "DI+" > "DI-" and "DI+" > trendconstitute;
def scalpshort = ADX <= trendconstitute and "DI+" < "DI-" and "DI-" > trendconstitute;
AddLabel( yes , if longmode then "ADXBullMode" else
                    if shortmode then "ADXBearMode" else
                    if scalplong then "ADXScalp-LMode" else
                    if scalpshort then "ADXScalp-SMode" else
                    "No-Man's Land",
                        if longmode and ((1 - (ADX - trendconstitute) / (ADXHIGH - trendconstitute)) * -100) > -50 then Color.UPTICK else
                        if longmode and ((1 - (ADX - trendconstitute) / (ADXHIGH - trendconstitute)) * -100) <= -50 then Color.dark_green else
                        if shortmode and ((1 - (ADX - trendconstitute) / (ADXHIGH - trendconstitute)) * -100) > -50 then Color.DOWNTICK else
                        if shortmode and ((1 - (ADX - trendconstitute) / (ADXHIGH - trendconstitute)) * -100) <= -50 then Color.dark_red else
                        if scalplong then Color.LIGHT_GREEN else
                        if scalpshort then Color.PINK else Color.GRAY);
## /END MODES

## BEGIN SIGNALS
input noisefilter = 20.1;
input scaling = 45;
input countertrend = 10;
plot longsafe = if (ADX > trendconstitute and "DI+" > "DI-" and  "DI+"[1] <= "DI-"[1] and "DI-" <= noisefilter
                                          and AbsValue("DI+" - "DI-") > 5.5)
                or (ADX > trendconstitute and ADX[1] <= trendconstitute and "DI+" > "DI-" and "DI-" <= noisefilter
                                          and AbsValue("DI+" - "DI-") > 5.5)
                or ("DI+" > trendconstitute and "DI+"[1] <= trendconstitute and ADX > trendconstitute
                                            and "DI-" <= noisefilter and AbsValue("DI+" - "DI-") > 5.5)
                or (ADX > trendconstitute and "DI+"[1] > "DI-"[1] and "DI+"[2] <= "DI-"[2] and "DI-"[1] >= noisefilter
                                          and AbsValue("DI+" - "DI-") > 5.5 and "DI+" > trendconstitute)
                then Low else Double.NaN;
plot longscalp = if  ADX <= trendconstitute and "DI+" > "DI-" and "DI+" > trendconstitute and "DI+"[1] <= trendconstitute
                 then Low else Double.NaN;
plot shortsafe = if (ADX > trendconstitute and "DI+" < "DI-" and  "DI+"[1] >= "DI-"[1]
                                           and "DI+" <= noisefilter and AbsValue("DI+" - "DI-") > 5.5)
                 or (ADX > trendconstitute and ADX[1] <= trendconstitute and "DI+" < "DI-" and "DI+" <= noisefilter
                                           and AbsValue("DI+" - "DI-") > 5.5)
                 or ("DI-" > trendconstitute and "DI-"[1] <= trendconstitute and ADX > trendconstitute
                                             and "DI+" <= noisefilter and AbsValue("DI+" - "DI-") > 5.5)
                 or (ADX > trendconstitute and "DI+"[1] < "DI-"[1] and "DI+"[2] >= "DI-"[2] and "DI+"[1] >= noisefilter
                                           and AbsValue("DI+" - "DI-") > 5.5 and "DI-" > trendconstitute)
                 then High else Double.NaN;
plot shortscalp = if ADX <= trendconstitute and "DI+" < "DI-" and "DI-" > trendconstitute
                                            and "DI-"[1] <= trendconstitute then High else Double.NaN;
plot counterlong = if "DI+" crosses above countertrend then Low else Double.NaN;
plot countershort = if "DI-" crosses above countertrend then High else Double.NaN;
plot scalelong = if "DI+" crosses below scaling then high else Double.NaN;
plot scaleshort = if "DI-" crosses below scaling then low else Double.NaN;
plot trendend = if ADX crosses below trendconstitute then Open else double.nan;
longsafe.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
longsafe.setdefaultColor(Color.UPTICK);
longsafe.SetLineWeight(2);
longscalp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
longscalp.setdefaultColor(Color.GRAY);
longscalp.SetLineWeight(1);
shortsafe.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
shortsafe.setdefaultColor(Color.DOWNTICK);
shortsafe.SetLineWeight(2);
shortscalp.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
shortscalp.setdefaultColor(Color.GRAY);
shortscalp.SetLineWeight(1);
counterlong.SetPaintingStrategy(PaintingStrategy.LINE_VS_TRIANGLES);
counterlong.setdefaultColor(Color.MAGENTA);
counterlong.SetLineWeight(5);
countershort.SetPaintingStrategy(PaintingStrategY.LINE_VS_TRIANGLES);
countershort.setdefaultColor(Color.MAGENTA);
countershort.SetLineWeight(5);
scalelong.SetPaintingStrategy(PaintingStrategy.SQUARES);
scalelong.setdefaultColor(Color.LIGHT_GREEN);
scalelong.SetLineWeight(5);
scaleshort.SetPaintingStrategy(PaintingStrategy.SQUARES);
scaleshort.setdefaultColor(Color.PINK);
scaleshort.SetLineWeight(5);
trendend.SetPaintingStrategy(PaintingStrategy.points);
trendend.setdefaultColor(createColor(206, 207, 0));
trendend.SetLineWeight(5);
AddCloud(if "DI+" > "DI-" and ADX > trendconstitute then high else Double.NaN, high + ATR, Color.GREEN, Color.green);
AddCloud(if "DI+" < "DI-" and ADX > trendconstitute then low else Double.NaN, low - ATR, Color.RED, Color.red);
AddLabel( yes , if (ADX > trendconstitute and "DI+" > "DI-" and  "DI+"[1] <= "DI-"[1] and "DI-" <= noisefilter
                                          and AbsValue("DI+" - "DI-") > 5.5)
                or (ADX > trendconstitute and ADX[1] <= trendconstitute and "DI+" > "DI-" and "DI-" <= noisefilter
                                          and AbsValue("DI+" - "DI-") > 5.5)
                or ("DI+" > trendconstitute and "DI+"[1] <= trendconstitute and ADX > trendconstitute
                                            and "DI-" <= noisefilter and AbsValue("DI+" - "DI-") > 5.5)
                or (ADX > trendconstitute and "DI+"[1] > "DI-"[1] and "DI+"[2] <= "DI-"[2] and "DI-"[1] >= noisefilter
                                          and AbsValue("DI+" - "DI-") > 5.5 and "DI+" > trendconstitute) then "ADX L-Entry"
            else if ADX <= trendconstitute and "DI+" > "DI-" and "DI+" > trendconstitute and "DI+"[1] <= trendconstitute then "ADX L-Scalp"
            else if (ADX > trendconstitute and "DI+" < "DI-" and  "DI+"[1] >= "DI-"[1]
                                           and "DI+" <= noisefilter and AbsValue("DI+" - "DI-") > 5.5)
                 or (ADX > trendconstitute and ADX[1] <= trendconstitute and "DI+" < "DI-" and "DI+" <= noisefilter
                                           and AbsValue("DI+" - "DI-") > 5.5)
                 or ("DI-" > trendconstitute and "DI-"[1] <= trendconstitute and ADX > trendconstitute
                                             and "DI+" <= noisefilter and AbsValue("DI+" - "DI-") > 5.5)
                 or (ADX > trendconstitute and "DI+"[1] < "DI-"[1] and "DI+"[2] >= "DI-"[2] and "DI+"[1] >= noisefilter
                                           and AbsValue("DI+" - "DI-") > 5.5 and "DI-" > trendconstitute) then "ADX S-Entry"
            else if ADX <= trendconstitute and "DI+" < "DI-" and "DI-" > trendconstitute
                                            and "DI-"[1] <= trendconstitute then "ADX S-Scalp"
            else if "DI+" crosses above countertrend then "ADX Countertrend+ Exit, Add Short or Counter Long"
            else if "DI-" crosses above countertrend then "ADX Countertrend- Exit, Add Long or Counter Short"
            else if "DI+" crosses below scaling then "ADX Scale Long"
            else if "DI-" crosses below scaling then "ADX Scale Short"
            else "ADX Hold",
            if (ADX > trendconstitute and "DI+" > "DI-" and  "DI+"[1] <= "DI-"[1] and "DI-" <= noisefilter
                                          and AbsValue("DI+" - "DI-") > 5.5)
                or (ADX > trendconstitute and ADX[1] <= trendconstitute and "DI+" > "DI-" and "DI-" <= noisefilter
                                          and AbsValue("DI+" - "DI-") > 5.5)
                or ("DI+" > trendconstitute and "DI+"[1] <= trendconstitute and ADX > trendconstitute
                                            and "DI-" <= noisefilter and AbsValue("DI+" - "DI-") > 5.5)
                or (ADX > trendconstitute and "DI+"[1] > "DI-"[1] and "DI+"[2] <= "DI-"[2] and "DI-"[1] >= noisefilter
                                          and AbsValue("DI+" - "DI-") > 5.5 and "DI+" > trendconstitute) then color.green
            else if ADX <= trendconstitute and "DI+" > "DI-" and "DI+" > trendconstitute and "DI+"[1] <= trendconstitute then color.light_green
            else if (ADX > trendconstitute and "DI+" < "DI-" and  "DI+"[1] >= "DI-"[1]
                                           and "DI+" <= noisefilter and AbsValue("DI+" - "DI-") > 5.5)
                 or (ADX > trendconstitute and ADX[1] <= trendconstitute and "DI+" < "DI-" and "DI+" <= noisefilter
                                           and AbsValue("DI+" - "DI-") > 5.5)
                 or ("DI-" > trendconstitute and "DI-"[1] <= trendconstitute and ADX > trendconstitute
                                             and "DI+" <= noisefilter and AbsValue("DI+" - "DI-") > 5.5)
                 or (ADX > trendconstitute and "DI+"[1] < "DI-"[1] and "DI+"[2] >= "DI-"[2] and "DI+"[1] >= noisefilter
                                           and AbsValue("DI+" - "DI-") > 5.5 and "DI-" > trendconstitute) then color.red
            else if ADX <= trendconstitute and "DI+" < "DI-" and "DI-" > trendconstitute
                                            and "DI-"[1] <= trendconstitute then color.pink
            else if "DI+" crosses above countertrend then color.magenta
            else if "DI-" crosses above countertrend then color.magenta
            else if "DI+" crosses below scaling then color.Dark_Green
            else if "DI-" crosses below scaling then color.dark_red
            else createcolor(30, 110, 190));

def reversal = if highest(adx, adxma) < 25 then 1 else 0;
AddLabel( if reversal > 0 then yes else no, if reversal > 0 then "Reversal Warning!" else ":",
                if reversal > 0 then color.YELLOW else color.gray);
AddLabel( if trendend then yes else no, if trendend then "End of Trend!" else ":",
                if trendend then color.YELLOW else color.gray);
## /END SIGNALS

## BEGIN HIGH PASSING ::
def diuphi = Highest("DI+", 30);
def didnhi = Highest("DI-", 30);
# moved up :: def ADXHIGH = Highest(ADX, 50);

def decay = (1 - (ADX - trendconstitute) / (ADXHIGH - trendconstitute)) * 100;
AddLabel( yes , if ADX > 25 and decay <= 0 then "TRENDING!"
            else if ADX > 25 then
            AsText((1 - (ADX - trendconstitute) / (ADXHIGH - trendconstitute)) * -100, NumberFormat.TWO_DECIMAL_PLACES) + "%TrendDecay"
            else "No Trend",
            if ADX <= 25 then createcolor(90, 90, 90)
            else if decay <= 1 then createcolor(0, 233, 254)
            else if decay <= 23.6 then  createcolor(0, 195, 220)
            else if decay <= 38.2 then  createcolor(0, 163, 200)
            else if decay <= 50 then  createcolor(20, 147, 170)
            else if decay <= 61.8 then  createcolor(45, 132, 160)
            else if decay <= 78.6 then  createcolor(70, 120, 150)
            else if decay > 61.8 then  createcolor(100, 110, 140)    
            else Color.GRAY);
AddLabel( yes , if "DI+" - diuphi >= 0 and "DI+" > trendconstitute then "DMI +Break+"
            else if "DI-" - didnhi >= 0 and "DI-" > trendconstitute then "DMI -Break-"
            else if "DI+" > didnhi and "DI+"[1] <= didnhi[1] then "+Dominance+"
            else if "DI-" > diuphi and "DI-"[1] <= diuphi[1] then "-Dominance-"
            else ":",
            if "DI+" - diuphi >= 0 and "DI+" > trendconstitute then Color.GREEN
            else if "DI-" - didnhi >= 0 and "DI-" > trendconstitute then Color.RED
            else if "DI+" > didnhi and "DI+"[1] <= didnhi[1] then Color.uptick
            else if "DI-" > diuphi and "DI-"[1] <= diuphi[1] then color.downtick
            else Color.dark_Gray);
## /END HIGH PASSING

## BEGIN EXPONENTIAL MA BIAS ::
def x = close;
def twentyema = expAverage(close, 20);
AddLabel( YES , if AbsValue(close - twentyema) <= .0149 then "Touching EMA @" + round(twentyema,2)
                      else if ADX > trendconstitute and "DI+" > "DI-" and close <= twentyema then "L-Value @" + round(twentyema,2)
                      else if ADX > trendconstitute and "DI+" < "DI-" and close >= twentyema then "S-Value @" + round(twentyema,2)
                      else "20ema=" + astext(twentyema),
                      if ADX > trendconstitute and "DI+" > "DI-" and close <= twentyema then createcolor(10, 220, 43)
                      else if ADX > trendconstitute and "DI+" < "DI-" and close >= twentyema then createcolor(220, 10, 43)
                      else if ADX > trendconstitute and "DI+" > "DI-" then createcolor(50, 100, 53)
                      else if ADX > trendconstitute and "DI+" < "DI-" then createcolor(100, 50, 53)
                      else color.gray);
## /END EXPONENTIAL MA BIAS
## /END STUDY


Just had a question in regards to this. I'm new to coding.. was looking for where it is in this script where the green and red cloud like areas appear. I just wanted to remove that from the script and have everything else. Thank you.
 
Just had a question in regards to this. I'm new to coding.. was looking for where it is in this script where the green and red cloud like areas appear. I just wanted to remove that from the script and have everything else. Thank you.
@EnV-T
Are you asking to eliminate clouds from your chart?
This can be done by finding every statement that starts with:
And place a # hashtag in the front of each statement. This changes it from a functional statement into a nonworking comment.
#AddCloud
 
Been playing with this indicator some and it is great. Can someone tell me what the clouds are supposed to be telling us? Is it simply a visual heads up of the price's relation to the 20 EMA? Just not sure what it's tracking, or how it's doing so!

Also just wondering, would it be possible to make the clouds a yes/no input, rather than commenting out the lines of code? I recently found out about that approach and not sure when it can or cannot be applied to a set of code.
 
Last edited:
Been playing with this indicator some and it is great. Can someone tell me what the clouds are supposed to be telling us? Is it simply a visual heads up of the price's relation to the 20 EMA? Just not sure what it's tracking, or how it's doing so!

Also just wondering, would it be possible to make the clouds a yes/no input, rather than commenting out the lines of code? I recently found out about that approach and not sure when it can or cannot be applied to a set of code.
second that ^^^
The Cloud logic:
"DI+" > "DI-" then green
"DI+" < "DI-" then red

The above logic is the basic premise of reading the DI ADX indicators.
IE: when DI Plus is greater than DI Minus then momentum is up otherwise down.
https://www.investopedia.com/terms/...Indicator (DI+,current price momentum is down.

Turning clouds off: Labels, Arrows, Plots can all be easily toggled on and off. Clouds need more in-depth conditional logic to achieve a toggle.
These clouds already have conditional logic, adding more will make the logic less transparent to new users of this indicator.

Therefore, the best answer to eliminating the clouds:
https://usethinkscript.com/threads/hammond-b3s-adx-for-thinkorswim.1358/#post-82845
 
Can we get some more insight for the Trend Decay. I see that it changes colors with brighter the box meaning stronger the trend but what does the percentage mean exactly? Looking through the code I see it might have something to do with fibonacci?
 
Can we get some more insight for the Trend Decay. I see that it changes colors with brighter the box meaning stronger the trend but what does the percentage mean exactly? Looking through the code I see it might have something to do with fibonacci?

Trend Decay by Hammond
is defined by what percentage the ADX is off of its 50bar high thus utilizing a dynamic range of the current trend instead of setting arbitrary OB/OS-type points.
Fibonacci's numbers are commonly used in statistics as a convenient way to segment analysis into thirds and quarters.
 
Last edited:
Howdy all! I've been trying to add some alerts to this code and unfortunately I'm not talented enough (ha). Can somebody share the code but also add an alert for conditions of "DI +BREAK+" and "DI -BREAK-"? Thanks so much!

While I'm asking, is there any way to change the color of the background screen when these same two conditions are active?
 
  • Howdy all! I've been trying to add some alerts to this code and unfortunately I'm not talented enough (ha). Can somebody share the code but also add an alert for conditions of "DI +BREAK+" and "DI -BREAK-"? Thanks so much!

While I'm asking, is there any way to change the color of the background screen when these same two conditions are active?
For the alerts add this to the bottom of your script:
Ruby:
Alert( "DI+" - diuphi >= 0 and "DI+" > trendconstitute, "DMI +Break+", Alert.Bar, Sound.ding);
Alert( "DI-" - didnhi >= 0 and "DI-" > trendconstitute, "DMI -Break-", Alert.Bar, Sound.bell);

For the Background change, add this to the bottom of your script:
Ruby:
DefineGlobalColor("BackgroundNeutral", CreateColor(240, 240, 240)) ;
DefineGlobalColor("Background_diPlus", CreateColor(225, 255, 255)) ;
DefineGlobalColor("Background_diMinus", CreateColor(225, 225, 200)) ;
AssignBackgroundColor(
if "DI+" - diuphi >= 0 and "DI+" > trendconstitute then GlobalColor("Background_diPlus") else
if !"DI-" - didnhi >= 0 and "DI-" > trendconstitute then GlobalColor("Background_diMinus") else GlobalColor("BackgroundNeutral"));
To change the background colors:
  1. click on the gear icon to the right of where you applied the studies to your chart.
  2. scroll down to the bottom of the window
  3. click on globals
  4. click on the color you want to change and change it.
 
For the alerts add this to the bottom of your script:
Ruby:
Alert( "DI+" - diuphi >= 0 and "DI+" > trendconstitute, "DMI +Break+", Alert.Bar, Sound.ding);
Alert( "DI-" - didnhi >= 0 and "DI-" > trendconstitute, "DMI -Break-", Alert.Bar, Sound.bell);

For the Background change, add this to the bottom of your script:
Ruby:
DefineGlobalColor("BackgroundNeutral", CreateColor(240, 240, 240)) ;
DefineGlobalColor("Background_diPlus", CreateColor(225, 255, 255)) ;
DefineGlobalColor("Background_diMinus", CreateColor(225, 225, 200)) ;
AssignBackgroundColor(
if "DI+" - diuphi >= 0 and "DI+" > trendconstitute then GlobalColor("Background_diPlus") else
if !"DI-" - didnhi >= 0 and "DI-" > trendconstitute then GlobalColor("Background_diMinus") else GlobalColor("BackgroundNeutral"));
To change the background colors:
  1. click on the gear icon to the right of where you applied the studies to your chart.
  2. scroll down to the bottom of the window
  3. click on globals
  4. click on the color you want to change and change it.
Thank you. What’s the secret to sending an alert text message to my phone?
 

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