ADX DMI Indicator For ThinkOrSwim

Can you help me with an audible alert? I want to make an audible alert when the ADX crosses above the adxavg. Can that be done?
Thank you
Wayne
Code:
# ADX_DMI indicator
# cabe1332
# 20210814

# ADX code start
declare lower;

# You can modify ADX setting below to you liking

input ADXCutoff = 25;
input DMILength = 6;
input MaFastLength=9;
input DIRangeFilter=10;


#DMI, ADX plots
def 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), DMILength);
def "DI+" = 100 * MovingAverage(averageType, plusDM, DMILength) / ATR;
def "DI-" = 100 * MovingAverage(averageType, minusDM, DMILength) / ATR;
def DX = if ("DI+" + "DI-" > 0) then 100 * AbsValue("DI+" - "DI-") / ("DI+" + "DI-") else 0;
plot ADX = MovingAverage(averageType, DX, DMILength);

#DIline - small diff = sideways
def DIrange = AbsValue(AbsValue("DI+")-AbsValue("DI-"));
#dirange.setPaintingStrategy(paintingStrategy.HISTOGRAM);
def DIok=DIRange>DIRangeFilter;

#adx filters
plot adxavg = MovingAverage(AverageType.SIMPLE, ADX, DMILength);
def ADXOk = ADX > ADXCutoff;# and adx>adxavg;

def DMICutBull = ("DI-" < ADXCutoff and "DI+" > ADXCutoff) or ("DI+" > ADX and "DI-" < ADX) ;
def DMICutBear = ("DI+" < ADXCutoff and "DI-" > ADXCutoff) or ("DI+" < ADX and "DI-" > ADX);

def dxcrossBull = if IsNaN(dxcrossBull[1]) then "DI+" > "DI-" #for init -what it is on first bar
else if "DI+" crosses above "DI-" then 1
else if dxcrossBull[1] > 0 and "DI+" > "DI-" then 1
else 0;
#plot dxXBull=dxCrossBull;
def dxcrossBear = if IsNaN(dxcrossBear[1]) then "DI-" > "DI+"
else if "DI+" crosses below "DI-" then 1
else if dxcrossBear[1] > 0 and "DI+" < "DI-" then 1
else 0 ;
#plot dxXBear=dxCrossBear;
#==========Pivots
def pivotprice=close;

#pivots per sami. changed logic for watchlist so there is no [-1]
def engbull= close>high[1] and low<=low[1];
def engbear= close<low[1] and high>=high[1];
def pivotHigh=(low[2] >low[1] and low>low[1] and close>pivotprice[1]) or engbull ;
def pivotLow=(high[2] <high[1] and high<high[1] and close<pivotprice[1]) or engbear;

def lastPH= if isnan(close[1]) then low else if PivotHigh then low[1] else LastPH[1];
def lastPL= if isnan(close[1]) then high else if PivotLow then high[1] else LastPL[1];

def breakout=if close> lastPL and close[1]<= lastPL then 1 else 0 ;
def breakdown= if close< lastPH and close[1]>= lastPH then 1 else 0;
#=============================

def signalbull = if dxcrossBull and ADXOk and DIOk then 1 else 0;
def signalbear = if dxcrossBear and ADXOk and DIOk then 1 else 0;

# ignore the signal if prevsignal was same direction and had higher DI
def signal = if signalbull then 1 else if signalbear then -1 else 0;

def prevSignal = if IsNaN(prevSignal[1]) then signal[1]
else if (signal[1] <> signal) then signal[1]
else prevSignal[1];

def DAPEntry = if signalbull and !signalbull[1] and prevSignal <= 0 then 1
else if signalbear and !signalbear[1] and prevSignal >= 0 then -1
else 0;


# Entry based on mas
input ATRMult = 0.3;
def MAFast = ExpAverage(close, MaFastLength);

#vwap
def vwp = reference VWAP("time frame" = "DAY");
def ATRMod = ATRMult * ATR;

def uptrend = signalbull;
def downtrend = signalbear ;

def PivotEntry = if uptrend and pivothigh then 1
else if downtrend and pivotlow then -1
else 0 ;

def VWPPB = if uptrend and low <= vwp + ATRMod and close > vwp then 1
else if downtrend and high >= vwp - ATRMod and close < vwp then -1
else 0 ;
#significant cross
def sigcross = if MAFast crosses above vwp and uptrend then 1.5
else if MAFast crosses below vwp and downtrend then -1.5
else 0;

#=== combined entry signal
def entry =
if sigcross <> 0 then sigcross
else
if VWPPB > 0 and pivotEntry>0 then 2
else if VWPPB < 0 and pivotEntry<0 then- 2
else if pivotEntry>0 then 1
else if pivotEntry<0 then -1
else 0
;
#======study display

plot pDIPlus = "DI+";
plot pDIminus = "DI-";
pDIPlus.SetDefaultColor(Color.GREEN);
pDIminus.SetDefaultColor(Color.RED);
AddCloud(pDIPlus, pDIminus, Color.UPTICK);

#Clouds
def cond1 = if pDIPlus > pDIminus
then Double.POSITIVE_INFINITY
else Double.NEGATIVE_INFINITY;
def cond2 = if pDIPlus < pDIminus
then Double.POSITIVE_INFINITY
else Double.NEGATIVE_INFINITY;
input showclouds = yes;
AddCloud(if showclouds
then cond1
else Double.NaN,
cond2,
Color.Dark_Green, Color.Dark_Red);

#plot padxcutoff = ADXCutoff;
plot padxcutoff = if !isnan(close) then ADXCutoff else double.nan;
padxcutoff.assignValueColor(if (adx < adxCutoff) or (pDiminus > adxcutoff) or (pDiplus < adxCutoff) then color.light_red else Color.LIGHT_GREEN);
padxcutoff.SetLineWeight(1);
padxcutoff.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);

#adx cross plots
#pivots
def prange=2; #pivot range
def adxbull = ADX > lowest(ADX,prange)[1];
def adxbear = ADX < highest(ADX,prange)[1];

ADX.AssignValueColor(if adxbull then Color.GREEN else if adxbear then Color.RED else Color.GRAY);

def ptrend=adx;
def adxPH= if isnan(ptrend[-1]) then 0 else lowest(ptrend,prange)[1] > ptrend and lowest(ptrend,prange)[-prange]> ptrend ;
def adxPL= if isnan(ptrend[-1]) then 0 else highest(ptrend,prange)[1] < ptrend and highest(ptrend,prange)[-prange]< ptrend ;

# Trend Direction

def dmisprd = pdiPlus - pdiMinus;

AddLabel(yes, if DMICutBull then "Trend Status: UP | D +: " + round(pdiPlus,2) + " D -: " + round(pdiMinus,2) + " Spread: " + round(dmisprd,2) else "Trend Status: DOWN | D -: " + round(pdiMinus,2) + " D +: " + round(pdiPlus,2) + " Spread: " + round(dmisprd,2), if DMICutBull then color.Uptick else color.Downtick);


# ADX Dynamic Label
# Adds ADX value and context

input ADXLength = 6;
input ADXLower = 25;
input ADXMid = 40;
input ADXHigh = 75;
#input MALength = 10;
input MALength = 9;

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

# ADX Label
AddLabel(yes, if ADXlabel < ADXLower then " Strenght: " + Round(ADXlabel,2) + " SETTING UP - Watch/Wait " else if ADXlabel < ADXMid then " Strenght: " + Round(ADXlabel,2) + " CHOPPY - Watch/Wait " else if ADXlabel < ADXlabel[1] then " Strenght: " + Round(ADXlabel,2) + " TREND WEAKENING " else if ADXlabel > ADXlabel[1] and MA > MA[1] and ADXlabel < ADXHigh then " Strenght: " + Round(ADXlabel,2) + " UPTRENDING " else if ADXlabel > ADXlabel[1] and MA < MA[1] then " Strenght: " + Round(ADXlabel,2) + " DOWNTRENDING " else if ADXlabel > ADXHigh then " Strenght: " + Round(ADXlabel,2) + " HIGH/WAIT TO COOL OFF " else " ", if ADXlabel < ADXLower then Color.Violet else if ADXlabel < ADXMid then Color.RED else if (ADXlabel < ADXlabel[1]) then Color.YELLOW else if ADXlabel > ADXlabel[1] and MA > MA[1] and ADXlabel < ADXHigh then Color.GREEN else if ADXlabel > ADXlabel[1] and MA < MA[1] then Color.RED else if ADXlabel > ADXHigh then Color.MAGENTA else Color.light_gray);

AddLabel(yes, if Adx > Adxavg then "ADX " else "ADX", if Adx > Adxavg  then Color.Light_GREEN else Color.Light_RED) ;

AddLabel(yes, if PdiPlus > padxcutoff then "DMI" else "DMI", if PdiPlus > padxcutoff then Color.GREEN else Color.RED);

DefineGlobalColor("LabelGreen",  CreateColor(0,255, 0)) ;
DefineGlobalColor("LabelRed",  CreateColor(225, 0, 0)) ;
input paintbar = no ;
AssignPriceColor(if !paintbar then Color.CURRENT else
if pdiPlus > padxcutoff  then GlobalColor("LabelGreen") else
if pdiminus > padxcutoff then GlobalColor("LabelRed") else
Color.Gray);


def bull_cross = ADX crosses above ADXAVG;
def bear_cross = ADX crosses below ADXAVG;

# Alerts
Alert(bull_cross, "ADX above ADXAVG", Alert.BAR, Sound.Chimes);
Alert(bear_cross, "ADX below ADXAVG", Alert.BAR, Sound.Ring);
# end
 
Last edited:

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

Hi @gate122, try the BULLISH code below and add it as a study with your scan. I have recently updated the code. I pasted a CCI scan earlier by error, and you wanted a simple ADX simple scan. The code below will scan ADX trend status (UP or Down). Tested and verified. Let me know how this works for you.

Good luck! @cabe1332

Code:
# ADX scan
# The scan will provide tickers that ADX uptrend/downtrend
# Switch "#" for bullish or bearish
# add as a study on filter scan
# @cabe1332

# code start
# You can modify ADX setting below to your liking

input ADXCutoff = 25;
input DMILength =  6;
input MaFastLength=9;
input DIRangeFilter=10;

#DMI, ADX plots
def 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), DMILength);
def "DI+" = 100 * MovingAverage(averageType, plusDM, DMILength) / ATR;
def "DI-" = 100 * MovingAverage(averageType, minusDM, DMILength) / ATR;
def DX = if ("DI+" + "DI-" > 0) then 100 * AbsValue("DI+" - "DI-") / ("DI+" + "DI-") else 0;
def ADX = MovingAverage(averageType, DX, DMILength);

#adx  filters
def adxavg = MovingAverage(AverageType.SIMPLE, ADX, DMILength);
def ADXOk = ADX > ADXCutoff;# and adx>adxavg;

def DMICutBull = ("DI-" < ADXCutoff and "DI+" > ADXCutoff) or ("DI+" > ADX and "DI-" < ADX) ;
def DMICutBear = ("DI+" < ADXCutoff and "DI-" > ADXCutoff) or ("DI+" < ADX and "DI-" > ADX);

# Switch "#" for bullish or bearish scan
plot scan = dmiCutBull;
#plot scan = dmiCutBear;
How do I change your scan to show ADX BEARISH? < 25?
 
How do I change your scan to show ADX BEARISH? < 25?
ADX is a built-in study. You can just choose it. Set the middle column to 'less than' and the right column to 25
Here is a shared scan link: http://tos.mx/k53SXRU Click here for --> Easiest way to load shared links
Jrry4Ky.png
 
I've used this for quite some time. Helps keep me on my hands and when it's a good time to dive in. Anyway, thought I'd pass it on. I don't remember where I got it. I think it was sent to me through one of my trading partners. In any event, hope it helps someone.

Readings less than 25, I sit and wait. 25-50, I'm picking a spot and jumping in. +50, I'm in with both hands, the car , the dog and the house. (short or long)



Code:
#ADX Watchlist

input length = 14;
input averageType = AverageType.WILDERS;
input threshold = 20;
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 diPlus = 100 * MovingAverage(averageType, plusDM, length) / ATR;
def diMinus = 100 * MovingAverage(averageType, minusDM, length) / ATR;
def DX = if (diPlus + diMinus > 0) then 100 * AbsValue(diPlus - diMinus) / (diPlus + diMinus) else 0;
# the value of the ADX is shown in the custom column
plot ADX = MovingAverage(averageType, DX, length);
# The Colors
ADX.AssignValueColor(if diPlus > diMinus then Color.GREEN else if diMinus > diPlus then Color.RED else Color.BLACK);
AssignBackgroundColor(if adx > threshold then Color.BLUE else Color.BLACK);
Hey @bobomatic, what timeframe you select on the watch list and do you include premarket? Thank you in advance.
 
Code:
# ADX_DMI indicator
# cabe1332
# 20210814

# ADX code start
declare lower;

# You can modify ADX setting below to you liking

input ADXCutoff = 25;
input DMILength = 6;
input MaFastLength=9;
input DIRangeFilter=10;


#DMI, ADX plots
def 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), DMILength);
def "DI+" = 100 * MovingAverage(averageType, plusDM, DMILength) / ATR;
def "DI-" = 100 * MovingAverage(averageType, minusDM, DMILength) / ATR;
def DX = if ("DI+" + "DI-" > 0) then 100 * AbsValue("DI+" - "DI-") / ("DI+" + "DI-") else 0;
plot ADX = MovingAverage(averageType, DX, DMILength);

#DIline - small diff = sideways
def DIrange = AbsValue(AbsValue("DI+")-AbsValue("DI-"));
#dirange.setPaintingStrategy(paintingStrategy.HISTOGRAM);
def DIok=DIRange>DIRangeFilter;

#adx filters
plot adxavg = MovingAverage(AverageType.SIMPLE, ADX, DMILength);
def ADXOk = ADX > ADXCutoff;# and adx>adxavg;

def DMICutBull = ("DI-" < ADXCutoff and "DI+" > ADXCutoff) or ("DI+" > ADX and "DI-" < ADX) ;
def DMICutBear = ("DI+" < ADXCutoff and "DI-" > ADXCutoff) or ("DI+" < ADX and "DI-" > ADX);

def dxcrossBull = if IsNaN(dxcrossBull[1]) then "DI+" > "DI-" #for init -what it is on first bar
else if "DI+" crosses above "DI-" then 1
else if dxcrossBull[1] > 0 and "DI+" > "DI-" then 1
else 0;
#plot dxXBull=dxCrossBull;
def dxcrossBear = if IsNaN(dxcrossBear[1]) then "DI-" > "DI+"
else if "DI+" crosses below "DI-" then 1
else if dxcrossBear[1] > 0 and "DI+" < "DI-" then 1
else 0 ;
#plot dxXBear=dxCrossBear;
#==========Pivots
def pivotprice=close;

#pivots per sami. changed logic for watchlist so there is no [-1]
def engbull= close>high[1] and low<=low[1];
def engbear= close<low[1] and high>=high[1];
def pivotHigh=(low[2] >low[1] and low>low[1] and close>pivotprice[1]) or engbull ;
def pivotLow=(high[2] <high[1] and high<high[1] and close<pivotprice[1]) or engbear;

def lastPH= if isnan(close[1]) then low else if PivotHigh then low[1] else LastPH[1];
def lastPL= if isnan(close[1]) then high else if PivotLow then high[1] else LastPL[1];

def breakout=if close> lastPL and close[1]<= lastPL then 1 else 0 ;
def breakdown= if close< lastPH and close[1]>= lastPH then 1 else 0;
#=============================

def signalbull = if dxcrossBull and ADXOk and DIOk then 1 else 0;
def signalbear = if dxcrossBear and ADXOk and DIOk then 1 else 0;

# ignore the signal if prevsignal was same direction and had higher DI
def signal = if signalbull then 1 else if signalbear then -1 else 0;

def prevSignal = if IsNaN(prevSignal[1]) then signal[1]
else if (signal[1] <> signal) then signal[1]
else prevSignal[1];

def DAPEntry = if signalbull and !signalbull[1] and prevSignal <= 0 then 1
else if signalbear and !signalbear[1] and prevSignal >= 0 then -1
else 0;


# Entry based on mas
input ATRMult = 0.3;
def MAFast = ExpAverage(close, MaFastLength);

#vwap
def vwp = reference VWAP("time frame" = "DAY");
def ATRMod = ATRMult * ATR;

def uptrend = signalbull;
def downtrend = signalbear ;

def PivotEntry = if uptrend and pivothigh then 1
else if downtrend and pivotlow then -1
else 0 ;

def VWPPB = if uptrend and low <= vwp + ATRMod and close > vwp then 1
else if downtrend and high >= vwp - ATRMod and close < vwp then -1
else 0 ;
#significant cross
def sigcross = if MAFast crosses above vwp and uptrend then 1.5
else if MAFast crosses below vwp and downtrend then -1.5
else 0;

#=== combined entry signal
def entry =
if sigcross <> 0 then sigcross
else
if VWPPB > 0 and pivotEntry>0 then 2
else if VWPPB < 0 and pivotEntry<0 then- 2
else if pivotEntry>0 then 1
else if pivotEntry<0 then -1
else 0
;
#======study display

plot pDIPlus = "DI+";
plot pDIminus = "DI-";
pDIPlus.SetDefaultColor(Color.GREEN);
pDIminus.SetDefaultColor(Color.RED);
AddCloud(pDIPlus, pDIminus, Color.UPTICK);

#Clouds
def cond1 = if pDIPlus > pDIminus
then Double.POSITIVE_INFINITY
else Double.NEGATIVE_INFINITY;
def cond2 = if pDIPlus < pDIminus
then Double.POSITIVE_INFINITY
else Double.NEGATIVE_INFINITY;
input showclouds = yes;
AddCloud(if showclouds
then cond1
else Double.NaN,
cond2,
Color.Dark_Green, Color.Dark_Red);

#plot padxcutoff = ADXCutoff;
plot padxcutoff = if !isnan(close) then ADXCutoff else double.nan;
padxcutoff.assignValueColor(if (adx < adxCutoff) or (pDiminus > adxcutoff) or (pDiplus < adxCutoff) then color.light_red else Color.LIGHT_GREEN);
padxcutoff.SetLineWeight(1);
padxcutoff.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);

#adx cross plots
#pivots
def prange=2; #pivot range
def adxbull = ADX > lowest(ADX,prange)[1];
def adxbear = ADX < highest(ADX,prange)[1];

ADX.AssignValueColor(if adxbull then Color.GREEN else if adxbear then Color.RED else Color.GRAY);

def ptrend=adx;
def adxPH= if isnan(ptrend[-1]) then 0 else lowest(ptrend,prange)[1] > ptrend and lowest(ptrend,prange)[-prange]> ptrend ;
def adxPL= if isnan(ptrend[-1]) then 0 else highest(ptrend,prange)[1] < ptrend and highest(ptrend,prange)[-prange]< ptrend ;

# Trend Direction

def dmisprd = pdiPlus - pdiMinus;

AddLabel(yes, if DMICutBull then "Trend Status: UP | D +: " + round(pdiPlus,2) + " D -: " + round(pdiMinus,2) + " Spread: " + round(dmisprd,2) else "Trend Status: DOWN | D -: " + round(pdiMinus,2) + " D +: " + round(pdiPlus,2) + " Spread: " + round(dmisprd,2), if DMICutBull then color.Uptick else color.Downtick);


# ADX Dynamic Label
# Adds ADX value and context

input ADXLength = 6;
input ADXLower = 25;
input ADXMid = 40;
input ADXHigh = 75;
#input MALength = 10;
input MALength = 9;

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

# ADX Label
AddLabel(yes, if ADXlabel < ADXLower then " Strenght: " + Round(ADXlabel,2) + " SETTING UP - Watch/Wait " else if ADXlabel < ADXMid then " Strenght: " + Round(ADXlabel,2) + " CHOPPY - Watch/Wait " else if ADXlabel < ADXlabel[1] then " Strenght: " + Round(ADXlabel,2) + " TREND WEAKENING " else if ADXlabel > ADXlabel[1] and MA > MA[1] and ADXlabel < ADXHigh then " Strenght: " + Round(ADXlabel,2) + " UPTRENDING " else if ADXlabel > ADXlabel[1] and MA < MA[1] then " Strenght: " + Round(ADXlabel,2) + " DOWNTRENDING " else if ADXlabel > ADXHigh then " Strenght: " + Round(ADXlabel,2) + " HIGH/WAIT TO COOL OFF " else " ", if ADXlabel < ADXLower then Color.Violet else if ADXlabel < ADXMid then Color.RED else if (ADXlabel < ADXlabel[1]) then Color.YELLOW else if ADXlabel > ADXlabel[1] and MA > MA[1] and ADXlabel < ADXHigh then Color.GREEN else if ADXlabel > ADXlabel[1] and MA < MA[1] then Color.RED else if ADXlabel > ADXHigh then Color.MAGENTA else Color.light_gray);

AddLabel(yes, if Adx > Adxavg then "ADX " else "ADX", if Adx > Adxavg  then Color.Light_GREEN else Color.Light_RED) ;

AddLabel(yes, if PdiPlus > padxcutoff then "DMI" else "DMI", if PdiPlus > padxcutoff then Color.GREEN else Color.RED);

DefineGlobalColor("LabelGreen",  CreateColor(0,255, 0)) ;
DefineGlobalColor("LabelRed",  CreateColor(225, 0, 0)) ;
input paintbar = no ;
AssignPriceColor(if !paintbar then Color.CURRENT else
if pdiPlus > padxcutoff  then GlobalColor("LabelGreen") else
if pdiminus > padxcutoff then GlobalColor("LabelRed") else
Color.Gray);


def bull_cross = ADX crosses above ADXAVG;
def bear_cross = ADX crosses below ADXAVG;

# Alerts
Alert(bull_cross, "ADX above ADXAVG", Alert.BAR, Sound.Chimes);
Alert(bear_cross, "ADX below ADXAVG", Alert.BAR, Sound.Ring);
# end
Can you help me make an audible alert? I want to make an alert to indicate when the ADX, the ADXAVG and PdiPlus are all above the 25 line. Can that be done?
Thank you
 
Can you help me make an audible alert? I want to make an alert to indicate when the ADX, the ADXAVG and PdiPlus are all above the 25 line. Can that be done?
Thank you
Give this a try

Code:
# ADX_DMI indicator

# cabe1332

# 20210814



# ADX code start

declare lower;



# You can modify ADX setting below to you liking



input ADXCutoff = 25;

input DMILength = 6;

input MaFastLength=9;

input DIRangeFilter=10;





#DMI, ADX plots

def 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), DMILength);

def "DI+" = 100 * MovingAverage(averageType, plusDM, DMILength) / ATR;

def "DI-" = 100 * MovingAverage(averageType, minusDM, DMILength) / ATR;

def DX = if ("DI+" + "DI-" > 0) then 100 * AbsValue("DI+" - "DI-") / ("DI+" + "DI-") else 0;

plot ADX = MovingAverage(averageType, DX, DMILength);



#DIline - small diff = sideways

def DIrange = AbsValue(AbsValue("DI+")-AbsValue("DI-"));

#dirange.setPaintingStrategy(paintingStrategy.HISTOGRAM);

def DIok=DIRange>DIRangeFilter;



#adx filters

plot adxavg = MovingAverage(AverageType.SIMPLE, ADX, DMILength);

def ADXOk = ADX > ADXCutoff;# and adx>adxavg;



def DMICutBull = ("DI-" < ADXCutoff and "DI+" > ADXCutoff) or ("DI+" > ADX and "DI-" < ADX) ;

def DMICutBear = ("DI+" < ADXCutoff and "DI-" > ADXCutoff) or ("DI+" < ADX and "DI-" > ADX);



def dxcrossBull = if IsNaN(dxcrossBull[1]) then "DI+" > "DI-" #for init -what it is on first bar

else if "DI+" crosses above "DI-" then 1

else if dxcrossBull[1] > 0 and "DI+" > "DI-" then 1

else 0;

#plot dxXBull=dxCrossBull;

def dxcrossBear = if IsNaN(dxcrossBear[1]) then "DI-" > "DI+"

else if "DI+" crosses below "DI-" then 1

else if dxcrossBear[1] > 0 and "DI+" < "DI-" then 1

else 0 ;

#plot dxXBear=dxCrossBear;

#==========Pivots

def pivotprice=close;



#pivots per sami. changed logic for watchlist so there is no [-1]

def engbull= close>high[1] and low<=low[1];

def engbear= close<low[1] and high>=high[1];

def pivotHigh=(low[2] >low[1] and low>low[1] and close>pivotprice[1]) or engbull ;

def pivotLow=(high[2] <high[1] and high<high[1] and close<pivotprice[1]) or engbear;



def lastPH= if isnan(close[1]) then low else if PivotHigh then low[1] else LastPH[1];

def lastPL= if isnan(close[1]) then high else if PivotLow then high[1] else LastPL[1];



def breakout=if close> lastPL and close[1]<= lastPL then 1 else 0 ;

def breakdown= if close< lastPH and close[1]>= lastPH then 1 else 0;

#=============================



def signalbull = if dxcrossBull and ADXOk and DIOk then 1 else 0;

def signalbear = if dxcrossBear and ADXOk and DIOk then 1 else 0;



# ignore the signal if prevsignal was same direction and had higher DI

def signal = if signalbull then 1 else if signalbear then -1 else 0;



def prevSignal = if IsNaN(prevSignal[1]) then signal[1]

else if (signal[1] <> signal) then signal[1]

else prevSignal[1];



def DAPEntry = if signalbull and !signalbull[1] and prevSignal <= 0 then 1

else if signalbear and !signalbear[1] and prevSignal >= 0 then -1

else 0;





# Entry based on mas

input ATRMult = 0.3;

def MAFast = ExpAverage(close, MaFastLength);



#vwap

def vwp = reference VWAP("time frame" = "DAY");

def ATRMod = ATRMult * ATR;



def uptrend = signalbull;

def downtrend = signalbear ;



def PivotEntry = if uptrend and pivothigh then 1

else if downtrend and pivotlow then -1

else 0 ;



def VWPPB = if uptrend and low <= vwp + ATRMod and close > vwp then 1

else if downtrend and high >= vwp - ATRMod and close < vwp then -1

else 0 ;

#significant cross

def sigcross = if MAFast crosses above vwp and uptrend then 1.5

else if MAFast crosses below vwp and downtrend then -1.5

else 0;



#=== combined entry signal

def entry =

if sigcross <> 0 then sigcross

else

if VWPPB > 0 and pivotEntry>0 then 2

else if VWPPB < 0 and pivotEntry<0 then- 2

else if pivotEntry>0 then 1

else if pivotEntry<0 then -1

else 0

;

#======study display



plot pDIPlus = "DI+";

plot pDIminus = "DI-";

pDIPlus.SetDefaultColor(Color.GREEN);

pDIminus.SetDefaultColor(Color.RED);

AddCloud(pDIPlus, pDIminus, Color.UPTICK);



#Clouds

def cond1 = if pDIPlus > pDIminus

then Double.POSITIVE_INFINITY

else Double.NEGATIVE_INFINITY;

def cond2 = if pDIPlus < pDIminus

then Double.POSITIVE_INFINITY

else Double.NEGATIVE_INFINITY;

input showclouds = yes;

AddCloud(if showclouds

then cond1

else Double.NaN,

cond2,

Color.Dark_Green, Color.Dark_Red);



#plot padxcutoff = ADXCutoff;

plot padxcutoff = if !isnan(close) then ADXCutoff else double.nan;

padxcutoff.assignValueColor(if (adx < adxCutoff) or (pDiminus > adxcutoff) or (pDiplus < adxCutoff) then color.light_red else Color.LIGHT_GREEN);

padxcutoff.SetLineWeight(1);

padxcutoff.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);



#adx cross plots

#pivots

def prange=2; #pivot range

def adxbull = ADX > lowest(ADX,prange)[1];

def adxbear = ADX < highest(ADX,prange)[1];



ADX.AssignValueColor(if adxbull then Color.GREEN else if adxbear then Color.RED else Color.GRAY);



def ptrend=adx;

def adxPH= if isnan(ptrend[-1]) then 0 else lowest(ptrend,prange)[1] > ptrend and lowest(ptrend,prange)[-prange]> ptrend ;

def adxPL= if isnan(ptrend[-1]) then 0 else highest(ptrend,prange)[1] < ptrend and highest(ptrend,prange)[-prange]< ptrend ;



# Trend Direction



def dmisprd = pdiPlus - pdiMinus;



AddLabel(yes, if DMICutBull then "Trend Status: UP | D +: " + round(pdiPlus,2) + " D -: " + round(pdiMinus,2) + " Spread: " + round(dmisprd,2) else "Trend Status: DOWN | D -: " + round(pdiMinus,2) + " D +: " + round(pdiPlus,2) + " Spread: " + round(dmisprd,2), if DMICutBull then color.Uptick else color.Downtick);





# ADX Dynamic Label

# Adds ADX value and context



input ADXLength = 6;

input ADXLower = 25;

input ADXMid = 40;

input ADXHigh = 75;

#input MALength = 10;

input MALength = 9;



def ADXlabel = reference ADX(ADXLength).ADX;

def MA = reference movAvgExponential(close,MALength);



# ADX Label

AddLabel(yes, if ADXlabel < ADXLower then " Strenght: " + Round(ADXlabel,2) + " SETTING UP - Watch/Wait " else if ADXlabel < ADXMid then " Strenght: " + Round(ADXlabel,2) + " CHOPPY - Watch/Wait " else if ADXlabel < ADXlabel[1] then " Strenght: " + Round(ADXlabel,2) + " TREND WEAKENING " else if ADXlabel > ADXlabel[1] and MA > MA[1] and ADXlabel < ADXHigh then " Strenght: " + Round(ADXlabel,2) + " UPTRENDING " else if ADXlabel > ADXlabel[1] and MA < MA[1] then " Strenght: " + Round(ADXlabel,2) + " DOWNTRENDING " else if ADXlabel > ADXHigh then " Strenght: " + Round(ADXlabel,2) + " HIGH/WAIT TO COOL OFF " else " ", if ADXlabel < ADXLower then Color.Violet else if ADXlabel < ADXMid then Color.RED else if (ADXlabel < ADXlabel[1]) then Color.YELLOW else if ADXlabel > ADXlabel[1] and MA > MA[1] and ADXlabel < ADXHigh then Color.GREEN else if ADXlabel > ADXlabel[1] and MA < MA[1] then Color.RED else if ADXlabel > ADXHigh then Color.MAGENTA else Color.light_gray);



AddLabel(yes, if Adx > Adxavg then "ADX " else "ADX", if Adx > Adxavg  then Color.Light_GREEN else Color.Light_RED) ;



AddLabel(yes, if PdiPlus > padxcutoff then "DMI" else "DMI", if PdiPlus > padxcutoff then Color.GREEN else Color.RED);



DefineGlobalColor("LabelGreen",  CreateColor(0,255, 0)) ;

DefineGlobalColor("LabelRed",  CreateColor(225, 0, 0)) ;

input paintbar = no ;

AssignPriceColor(if !paintbar then Color.CURRENT else

if pdiPlus > padxcutoff  then GlobalColor("LabelGreen") else

if pdiminus > padxcutoff then GlobalColor("LabelRed") else

Color.Gray);

def bull_cross = ADX crosses above ADXAVG;
def bear_cross = ADX crosses below ADXAVG;

# Alerts
Alert(bull_cross, "ADX above ADXAVG", Alert.BAR, Sound.Chimes);
Alert(bear_cross, "ADX below ADXAVG", Alert.BAR, Sound.Ring);

def bull_cross1 = PdiPlus crosses above Padxcutoff;
def bear_cross1 = PdiMinus crosses above Padxcutoff;

# Alerts
Alert(bull_cross1, "PdiPlus above Padxcutoff", Alert.BAR, Sound.Chimes);
Alert(bear_cross1, "PdiMinus above Padxcutoff", Alert.BAR, Sound.Ring);

#END
 
Last edited:
I've used this for quite some time. Helps keep me on my hands and when it's a good time to dive in. Anyway, thought I'd pass it on. I don't remember where I got it. I think it was sent to me through one of my trading partners. In any event, hope it helps someone.

Readings less than 25, I sit and wait. 25-50, I'm picking a spot and jumping in. +50, I'm in with both hands, the car , the dog and the house. (short or long)



Code:
#ADX Watchlist

input length = 14;
input averageType = AverageType.WILDERS;
input threshold = 20;
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 diPlus = 100 * MovingAverage(averageType, plusDM, length) / ATR;
def diMinus = 100 * MovingAverage(averageType, minusDM, length) / ATR;
def DX = if (diPlus + diMinus > 0) then 100 * AbsValue(diPlus - diMinus) / (diPlus + diMinus) else 0;
# the value of the ADX is shown in the custom column
plot ADX = MovingAverage(averageType, DX, length);
# The Colors
ADX.AssignValueColor(if diPlus > diMinus then Color.GREEN else if diMinus > diPlus then Color.RED else Color.BLACK);
AssignBackgroundColor(if adx > threshold then Color.BLUE else Color.BLACK);
Anyone now how to add this to the upper chart as labels? I would like to review old charts and see how it performs.
 
Anyone now how to add this to the upper chart as labels? I would like to review old charts and see how it performs.
check this

CSS:
#ADX LABEL

input length = 14;
input averageType = AverageType.WILDERS;
input threshold = 20;
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 diPlus = 100 * MovingAverage(averageType, plusDM, length) / ATR;
def diMinus = 100 * MovingAverage(averageType, minusDM, length) / ATR;
def DX = if (diPlus + diMinus > 0) then 100 * AbsValue(diPlus - diMinus) / (diPlus + diMinus) else 0;
# the value of the ADX is shown in the custom column
def ADX = MovingAverage(averageType, DX, length);
# The Colors
def color = if diPlus > diMinus then 1 else if diMinus > diPlus then-1 else 0;
#AssignBackgroundColor(if adx > threshold then Color.BLUE else Color.BLACK);

addlabel ( adx > threshold,"ADX (" + ROUND(ADX,2) +")",if color> 0 then color.GREEN else
                                if color< 0 then Color.RED else color.BLACK);
 
check this

CSS:
#ADX LABEL

input length = 14;
input averageType = AverageType.WILDERS;
input threshold = 20;
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 diPlus = 100 * MovingAverage(averageType, plusDM, length) / ATR;
def diMinus = 100 * MovingAverage(averageType, minusDM, length) / ATR;
def DX = if (diPlus + diMinus > 0) then 100 * AbsValue(diPlus - diMinus) / (diPlus + diMinus) else 0;
# the value of the ADX is shown in the custom column
def ADX = MovingAverage(averageType, DX, length);
# The Colors
def color = if diPlus > diMinus then 1 else if diMinus > diPlus then-1 else 0;
#AssignBackgroundColor(if adx > threshold then Color.BLUE else Color.BLACK);

addlabel ( adx > threshold,"ADX (" + ROUND(ADX,2) +")",if color> 0 then color.GREEN else
                                if color< 0 then Color.RED else color.BLACK);
Thanks @samer800 i tried is but it shows 65.
On the WatchList column, it shows 32
 
I put it as 1 Day and it shows 22 instead of 32 like on the watchlist. Thanks for the effort @samer800 I will just use the Watchlist column. no big deal. I just wanted to back test the script to look at the history and i dont think this script does this.
 
I tried to use the code to view $VIX, but it doesn't work. It works for other tickers. Any idea why is that?
Hi All, below is the script I've put together coming/learning from this site. As a Trend Trader and holding pos longer are profitable. The quick scalp is a bit stressful and requires leverage, which I don't have at this time. The script provides conditions and a quick glance before you decide on pos entry or exit. For simplicity, the colored ADXCutoff dots. Please watch some youtube clips to better used ADX/DMI indicators. It is a lifesaver. Good luck! @cabe1332
Ruby:
# ADX_DMI indicator
# cabe1332
# 20210814

# ADX code start
declare lower;

# You can modify ADX setting below to you liking

input ADXCutoff = 25;
input DMILength = 6;
input MaFastLength=9;
input DIRangeFilter=10;


#DMI, ADX plots
def 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), DMILength);
def "DI+" = 100 * MovingAverage(averageType, plusDM, DMILength) / ATR;
def "DI-" = 100 * MovingAverage(averageType, minusDM, DMILength) / ATR;
def DX = if ("DI+" + "DI-" > 0) then 100 * AbsValue("DI+" - "DI-") / ("DI+" + "DI-") else 0;
plot ADX = MovingAverage(averageType, DX, DMILength);

#DIline - small diff = sideways
def DIrange = AbsValue(AbsValue("DI+")-AbsValue("DI-"));
#dirange.setPaintingStrategy(paintingStrategy.HISTOGRAM);
def DIok=DIRange>DIRangeFilter;

#adx filters
plot adxavg = MovingAverage(AverageType.SIMPLE, ADX, DMILength);
def ADXOk = ADX > ADXCutoff;# and adx>adxavg;

def DMICutBull = ("DI-" < ADXCutoff and "DI+" > ADXCutoff) or ("DI+" > ADX and "DI-" < ADX) ;
def DMICutBear = ("DI+" < ADXCutoff and "DI-" > ADXCutoff) or ("DI+" < ADX and "DI-" > ADX);

def dxcrossBull = if IsNaN(dxcrossBull[1]) then "DI+" > "DI-" #for init -what it is on first bar
else if "DI+" crosses above "DI-" then 1
else if dxcrossBull[1] > 0 and "DI+" > "DI-" then 1
else 0;
#plot dxXBull=dxCrossBull;
def dxcrossBear = if IsNaN(dxcrossBear[1]) then "DI-" > "DI+"
else if "DI+" crosses below "DI-" then 1
else if dxcrossBear[1] > 0 and "DI+" < "DI-" then 1
else 0 ;
#plot dxXBear=dxCrossBear;
#==========Pivots
def pivotprice=close;

#pivots per sami. changed logic for watchlist so there is no [-1]
def engbull= close>high[1] and low<=low[1];
def engbear= close<low[1] and high>=high[1];
def pivotHigh=(low[2] >low[1] and low>low[1] and close>pivotprice[1]) or engbull ;
def pivotLow=(high[2] <high[1] and high<high[1] and close<pivotprice[1]) or engbear;

def lastPH= if isnan(close[1]) then low else if PivotHigh then low[1] else LastPH[1];
def lastPL= if isnan(close[1]) then high else if PivotLow then high[1] else LastPL[1];

def breakout=if close> lastPL and close[1]<= lastPL then 1 else 0 ;
def breakdown= if close< lastPH and close[1]>= lastPH then 1 else 0;
#=============================

def signalbull = if dxcrossBull and ADXOk and DIOk then 1 else 0;
def signalbear = if dxcrossBear and ADXOk and DIOk then 1 else 0;

# ignore the signal if prevsignal was same direction and had higher DI
def signal = if signalbull then 1 else if signalbear then -1 else 0;

def prevSignal = if IsNaN(prevSignal[1]) then signal[1]
else if (signal[1] <> signal) then signal[1]
else prevSignal[1];

def DAPEntry = if signalbull and !signalbull[1] and prevSignal <= 0 then 1
else if signalbear and !signalbear[1] and prevSignal >= 0 then -1
else 0;


# Entry based on mas
input ATRMult = 0.3;
def MAFast = ExpAverage(close, MaFastLength);

#vwap
def vwp = reference VWAP("time frame" = "DAY");
def ATRMod = ATRMult * ATR;

def uptrend = signalbull;
def downtrend = signalbear ;

def PivotEntry = if uptrend and pivothigh then 1
else if downtrend and pivotlow then -1
else 0 ;

def VWPPB = if uptrend and low <= vwp + ATRMod and close > vwp then 1
else if downtrend and high >= vwp - ATRMod and close < vwp then -1
else 0 ;
#significant cross
def sigcross = if MAFast crosses above vwp and uptrend then 1.5
else if MAFast crosses below vwp and downtrend then -1.5
else 0;

#=== combined entry signal
def entry =
if sigcross <> 0 then sigcross
else
if VWPPB > 0 and pivotEntry>0 then 2
else if VWPPB < 0 and pivotEntry<0 then- 2
else if pivotEntry>0 then 1
else if pivotEntry<0 then -1
else 0
;
#======study display

plot pDIPlus = "DI+";
plot pDIminus = "DI-";
pDIPlus.SetDefaultColor(Color.GREEN);
pDIminus.SetDefaultColor(Color.RED);
AddCloud(pDIPlus, pDIminus, Color.UPTICK);

#plot padxcutoff = ADXCutoff;
plot padxcutoff = if !isnan(close) then ADXCutoff else double.nan;
padxcutoff.assignValueColor(if (adx < adxCutoff) or (pDiminus > adxcutoff) or (pDiplus < adxCutoff) then color.light_red else Color.green);
padxcutoff.SetLineWeight(1);
padxcutoff.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);

#adx cross plots
#pivots
def prange=2; #pivot range
def adxbull = ADX > lowest(ADX,prange)[1];
def adxbear = ADX < highest(ADX,prange)[1];

ADX.AssignValueColor(if adxbull then Color.cyan else if adxbear then Color.orange else Color.GRAY);

def ptrend=adx;
def adxPH= if isnan(ptrend[-1]) then 0 else lowest(ptrend,prange)[1] > ptrend and lowest(ptrend,prange)[-prange]> ptrend ;
def adxPL= if isnan(ptrend[-1]) then 0 else highest(ptrend,prange)[1] < ptrend and highest(ptrend,prange)[-prange]< ptrend ;

# Trend Direction

def dmisprd = pdiPlus - pdiMinus;

AddLabel(yes, if DMICutBull then "Trend Status: UP | D+: " + round(pdiPlus,2) + " D-: " + round(pdiMinus,2) + " Spread: " + round(dmisprd,2) else "Trend Status: DOWN | D-: " + round(pdiMinus,2) + " D+: " + round(pdiPlus,2) + " Spread: " + round(dmisprd,2), if DMICutBull then color.green else color.red);


# ADX Dynamic Label
# Adds ADX value and context

input ADXLength = 6;
input ADXLower = 25;
input ADXMid = 40;
input ADXHigh = 75;
#input MALength = 10;
input MALength = 9;

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

# ADX Label
AddLabel(yes, if ADXlabel < ADXLower then " Strenght: " + Round(ADXlabel,2) + " SETTING UP - Watch/Wait " else if ADXlabel < ADXMid then " Strenght: " + Round(ADXlabel,2) + " CHOPPY - Watch/Wait " else if ADXlabel < ADXlabel[1] then " Strenght: " + Round(ADXlabel,2) + " TREND WEAKENING " else if ADXlabel > ADXlabel[1] and MA > MA[1] and ADXlabel < ADXHigh then " Strenght: " + Round(ADXlabel,2) + " UPTRENDING " else if ADXlabel > ADXlabel[1] and MA < MA[1] then " Strenght: " + Round(ADXlabel,2) + " DOWNTRENDING " else if ADXlabel > ADXHigh then " Strenght: " + Round(ADXlabel,2) + " HIGH/WAIT TO COOL OFF " else " ", if ADXlabel < ADXLower then Color.CYAN else if ADXlabel < ADXMid then Color.RED else if (ADXlabel < ADXlabel[1]) then Color.YELLOW else if ADXlabel > ADXlabel[1] and MA > MA[1] and ADXlabel < ADXHigh then Color.GREEN else if ADXlabel > ADXlabel[1] and MA < MA[1] then Color.RED else if ADXlabel > ADXHigh then Color.MAGENTA else Color.light_gray);

# end of ADX
Thank you! I love this ADX indicator. I tried to use the code to view $VIX, but it doesn't work. It works for other stocks. Do you have any idea why is that?
 
I tried to use the code to view $VIX, but it doesn't work. It works for other tickers. Any idea why is that?

Thank you! I love this ADX indicator. I tried to use the code to view $VIX, but it doesn't work. It works for other stocks. Do you have any idea why is that?
VWAP don't work volume weighted average don't work on VIX.
 
I tried to use the code to view $VIX, but it doesn't work. It works for other tickers. Any idea why is that?

Thank you! I love this ADX indicator. I tried to use the code to view $VIX, but it doesn't work. It works for other stocks. Do you have any idea why is that?
I removed the VWAP signal. Try it now

CSS:
# ADX_DMI indicator
# cabe1332
# 20210814

# ADX code start
declare lower;

# You can modify ADX setting below to you liking

input ADXCutoff = 25;
input DMILength = 6;
input MaFastLength=9;
input DIRangeFilter=10;


#DMI, ADX plots
def 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), DMILength);
def "DI+" = 100 * MovingAverage(averageType, plusDM, DMILength) / ATR;
def "DI-" = 100 * MovingAverage(averageType, minusDM, DMILength) / ATR;
def DX = if ("DI+" + "DI-" > 0) then 100 * AbsValue("DI+" - "DI-") / ("DI+" + "DI-") else 0;
plot ADX = MovingAverage(averageType, DX, DMILength);

#DIline - small diff = sideways
def DIrange = AbsValue(AbsValue("DI+")-AbsValue("DI-"));
#dirange.setPaintingStrategy(paintingStrategy.HISTOGRAM);
def DIok=DIRange>DIRangeFilter;

#adx filters
plot adxavg = MovingAverage(AverageType.SIMPLE, ADX, DMILength);
def ADXOk = ADX > ADXCutoff;# and adx>adxavg;

def DMICutBull = ("DI-" < ADXCutoff and "DI+" > ADXCutoff) or ("DI+" > ADX and "DI-" < ADX) ;
def DMICutBear = ("DI+" < ADXCutoff and "DI-" > ADXCutoff) or ("DI+" < ADX and "DI-" > ADX);

def dxcrossBull = if IsNaN(dxcrossBull[1]) then "DI+" > "DI-" #for init -what it is on first bar
else if "DI+" crosses above "DI-" then 1
else if dxcrossBull[1] > 0 and "DI+" > "DI-" then 1
else 0;
#plot dxXBull=dxCrossBull;
def dxcrossBear = if IsNaN(dxcrossBear[1]) then "DI-" > "DI+"
else if "DI+" crosses below "DI-" then 1
else if dxcrossBear[1] > 0 and "DI+" < "DI-" then 1
else 0 ;
#plot dxXBear=dxCrossBear;
#==========Pivots
def pivotprice=close;

#pivots per sami. changed logic for watchlist so there is no [-1]
def engbull= close>high[1] and low<=low[1];
def engbear= close<low[1] and high>=high[1];
def pivotHigh=(low[2] >low[1] and low>low[1] and close>pivotprice[1]) or engbull ;
def pivotLow=(high[2] <high[1] and high<high[1] and close<pivotprice[1]) or engbear;

def lastPH= if isnan(close[1]) then low else if PivotHigh then low[1] else LastPH[1];
def lastPL= if isnan(close[1]) then high else if PivotLow then high[1] else LastPL[1];

def breakout=if close> lastPL and close[1]<= lastPL then 1 else 0 ;
def breakdown= if close< lastPH and close[1]>= lastPH then 1 else 0;
#=============================

def signalbull = if dxcrossBull and ADXOk and DIOk then 1 else 0;
def signalbear = if dxcrossBear and ADXOk and DIOk then 1 else 0;

# ignore the signal if prevsignal was same direction and had higher DI
def signal = if signalbull then 1 else if signalbear then -1 else 0;

def prevSignal = if IsNaN(prevSignal[1]) then signal[1]
else if (signal[1] <> signal) then signal[1]
else prevSignal[1];

def DAPEntry = if signalbull and !signalbull[1] and prevSignal <= 0 then 1
else if signalbear and !signalbear[1] and prevSignal >= 0 then -1
else 0;


# Entry based on mas
input ATRMult = 0.3;
def MAFast = ExpAverage(close, MaFastLength);


#======study display

plot pDIPlus = "DI+";
plot pDIminus = "DI-";
pDIPlus.SetDefaultColor(Color.GREEN);
pDIminus.SetDefaultColor(Color.RED);
AddCloud(pDIPlus, pDIminus, Color.UPTICK);

#plot padxcutoff = ADXCutoff;
plot padxcutoff = if !isnan(close) then ADXCutoff else double.nan;
padxcutoff.assignValueColor(if (adx < adxCutoff) or (pDiminus > adxcutoff) or (pDiplus < adxCutoff) then color.light_red else Color.green);
padxcutoff.SetLineWeight(1);
padxcutoff.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);

#adx cross plots
#pivots
def prange=2; #pivot range
def adxbull = ADX > lowest(ADX,prange)[1];
def adxbear = ADX < highest(ADX,prange)[1];

ADX.AssignValueColor(if adxbull then Color.cyan else if adxbear then Color.orange else Color.GRAY);

def ptrend=adx;
def adxPH= if isnan(ptrend[-1]) then 0 else lowest(ptrend,prange)[1] > ptrend and lowest(ptrend,prange)[-prange]> ptrend ;
def adxPL= if isnan(ptrend[-1]) then 0 else highest(ptrend,prange)[1] < ptrend and highest(ptrend,prange)[-prange]< ptrend ;

# Trend Direction

def dmisprd = pdiPlus - pdiMinus;

AddLabel(yes, if DMICutBull then "Trend Status: UP | D+: " + round(pdiPlus,2) + " D-: " + round(pdiMinus,2) + " Spread: " + round(dmisprd,2) else "Trend Status: DOWN | D-: " + round(pdiMinus,2) + " D+: " + round(pdiPlus,2) + " Spread: " + round(dmisprd,2), if DMICutBull then color.green else color.red);


# ADX Dynamic Label
# Adds ADX value and context

input ADXLength = 6;
input ADXLower = 25;
input ADXMid = 40;
input ADXHigh = 75;
#input MALength = 10;
input MALength = 9;

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

# ADX Label
AddLabel(yes, if ADXlabel < ADXLower then " Strenght: " + Round(ADXlabel,2) + " SETTING UP - Watch/Wait " else if ADXlabel < ADXMid then " Strenght: " + Round(ADXlabel,2) + " CHOPPY - Watch/Wait " else if ADXlabel < ADXlabel[1] then " Strenght: " + Round(ADXlabel,2) + " TREND WEAKENING " else if ADXlabel > ADXlabel[1] and MA > MA[1] and ADXlabel < ADXHigh then " Strenght: " + Round(ADXlabel,2) + " UPTRENDING " else if ADXlabel > ADXlabel[1] and MA < MA[1] then " Strenght: " + Round(ADXlabel,2) + " DOWNTRENDING " else if ADXlabel > ADXHigh then " Strenght: " + Round(ADXlabel,2) + " HIGH/WAIT TO COOL OFF " else " ", if ADXlabel < ADXLower then Color.CYAN else if ADXlabel < ADXMid then Color.RED else if (ADXlabel < ADXlabel[1]) then Color.YELLOW else if ADXlabel > ADXlabel[1] and MA > MA[1] and ADXlabel < ADXHigh then Color.GREEN else if ADXlabel > ADXlabel[1] and MA < MA[1] then Color.RED else if ADXlabel > ADXHigh then Color.MAGENTA else Color.light_gray);

# end of ADX
 
I removed the VWAP signal. Try it now

CSS:
# ADX_DMI indicator
# cabe1332
# 20210814

# ADX code start
declare lower;

# You can modify ADX setting below to you liking

input ADXCutoff = 25;
input DMILength = 6;
input MaFastLength=9;
input DIRangeFilter=10;


#DMI, ADX plots
def 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), DMILength);
def "DI+" = 100 * MovingAverage(averageType, plusDM, DMILength) / ATR;
def "DI-" = 100 * MovingAverage(averageType, minusDM, DMILength) / ATR;
def DX = if ("DI+" + "DI-" > 0) then 100 * AbsValue("DI+" - "DI-") / ("DI+" + "DI-") else 0;
plot ADX = MovingAverage(averageType, DX, DMILength);

#DIline - small diff = sideways
def DIrange = AbsValue(AbsValue("DI+")-AbsValue("DI-"));
#dirange.setPaintingStrategy(paintingStrategy.HISTOGRAM);
def DIok=DIRange>DIRangeFilter;

#adx filters
plot adxavg = MovingAverage(AverageType.SIMPLE, ADX, DMILength);
def ADXOk = ADX > ADXCutoff;# and adx>adxavg;

def DMICutBull = ("DI-" < ADXCutoff and "DI+" > ADXCutoff) or ("DI+" > ADX and "DI-" < ADX) ;
def DMICutBear = ("DI+" < ADXCutoff and "DI-" > ADXCutoff) or ("DI+" < ADX and "DI-" > ADX);

def dxcrossBull = if IsNaN(dxcrossBull[1]) then "DI+" > "DI-" #for init -what it is on first bar
else if "DI+" crosses above "DI-" then 1
else if dxcrossBull[1] > 0 and "DI+" > "DI-" then 1
else 0;
#plot dxXBull=dxCrossBull;
def dxcrossBear = if IsNaN(dxcrossBear[1]) then "DI-" > "DI+"
else if "DI+" crosses below "DI-" then 1
else if dxcrossBear[1] > 0 and "DI+" < "DI-" then 1
else 0 ;
#plot dxXBear=dxCrossBear;
#==========Pivots
def pivotprice=close;

#pivots per sami. changed logic for watchlist so there is no [-1]
def engbull= close>high[1] and low<=low[1];
def engbear= close<low[1] and high>=high[1];
def pivotHigh=(low[2] >low[1] and low>low[1] and close>pivotprice[1]) or engbull ;
def pivotLow=(high[2] <high[1] and high<high[1] and close<pivotprice[1]) or engbear;

def lastPH= if isnan(close[1]) then low else if PivotHigh then low[1] else LastPH[1];
def lastPL= if isnan(close[1]) then high else if PivotLow then high[1] else LastPL[1];

def breakout=if close> lastPL and close[1]<= lastPL then 1 else 0 ;
def breakdown= if close< lastPH and close[1]>= lastPH then 1 else 0;
#=============================

def signalbull = if dxcrossBull and ADXOk and DIOk then 1 else 0;
def signalbear = if dxcrossBear and ADXOk and DIOk then 1 else 0;

# ignore the signal if prevsignal was same direction and had higher DI
def signal = if signalbull then 1 else if signalbear then -1 else 0;

def prevSignal = if IsNaN(prevSignal[1]) then signal[1]
else if (signal[1] <> signal) then signal[1]
else prevSignal[1];

def DAPEntry = if signalbull and !signalbull[1] and prevSignal <= 0 then 1
else if signalbear and !signalbear[1] and prevSignal >= 0 then -1
else 0;


# Entry based on mas
input ATRMult = 0.3;
def MAFast = ExpAverage(close, MaFastLength);


#======study display

plot pDIPlus = "DI+";
plot pDIminus = "DI-";
pDIPlus.SetDefaultColor(Color.GREEN);
pDIminus.SetDefaultColor(Color.RED);
AddCloud(pDIPlus, pDIminus, Color.UPTICK);

#plot padxcutoff = ADXCutoff;
plot padxcutoff = if !isnan(close) then ADXCutoff else double.nan;
padxcutoff.assignValueColor(if (adx < adxCutoff) or (pDiminus > adxcutoff) or (pDiplus < adxCutoff) then color.light_red else Color.green);
padxcutoff.SetLineWeight(1);
padxcutoff.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);

#adx cross plots
#pivots
def prange=2; #pivot range
def adxbull = ADX > lowest(ADX,prange)[1];
def adxbear = ADX < highest(ADX,prange)[1];

ADX.AssignValueColor(if adxbull then Color.cyan else if adxbear then Color.orange else Color.GRAY);

def ptrend=adx;
def adxPH= if isnan(ptrend[-1]) then 0 else lowest(ptrend,prange)[1] > ptrend and lowest(ptrend,prange)[-prange]> ptrend ;
def adxPL= if isnan(ptrend[-1]) then 0 else highest(ptrend,prange)[1] < ptrend and highest(ptrend,prange)[-prange]< ptrend ;

# Trend Direction

def dmisprd = pdiPlus - pdiMinus;

AddLabel(yes, if DMICutBull then "Trend Status: UP | D+: " + round(pdiPlus,2) + " D-: " + round(pdiMinus,2) + " Spread: " + round(dmisprd,2) else "Trend Status: DOWN | D-: " + round(pdiMinus,2) + " D+: " + round(pdiPlus,2) + " Spread: " + round(dmisprd,2), if DMICutBull then color.green else color.red);


# ADX Dynamic Label
# Adds ADX value and context

input ADXLength = 6;
input ADXLower = 25;
input ADXMid = 40;
input ADXHigh = 75;
#input MALength = 10;
input MALength = 9;

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

# ADX Label
AddLabel(yes, if ADXlabel < ADXLower then " Strenght: " + Round(ADXlabel,2) + " SETTING UP - Watch/Wait " else if ADXlabel < ADXMid then " Strenght: " + Round(ADXlabel,2) + " CHOPPY - Watch/Wait " else if ADXlabel < ADXlabel[1] then " Strenght: " + Round(ADXlabel,2) + " TREND WEAKENING " else if ADXlabel > ADXlabel[1] and MA > MA[1] and ADXlabel < ADXHigh then " Strenght: " + Round(ADXlabel,2) + " UPTRENDING " else if ADXlabel > ADXlabel[1] and MA < MA[1] then " Strenght: " + Round(ADXlabel,2) + " DOWNTRENDING " else if ADXlabel > ADXHigh then " Strenght: " + Round(ADXlabel,2) + " HIGH/WAIT TO COOL OFF " else " ", if ADXlabel < ADXLower then Color.CYAN else if ADXlabel < ADXMid then Color.RED else if (ADXlabel < ADXlabel[1]) then Color.YELLOW else if ADXlabel > ADXlabel[1] and MA > MA[1] and ADXlabel < ADXHigh then Color.GREEN else if ADXlabel > ADXlabel[1] and MA < MA[1] then Color.RED else if ADXlabel > ADXHigh then Color.MAGENTA else Color.light_gray);

# end of ADX
I removed the VWAP signal. Try it now

CSS:
# ADX_DMI indicator
# cabe1332
# 20210814

# ADX code start
declare lower;

# You can modify ADX setting below to you liking

input ADXCutoff = 25;
input DMILength = 6;
input MaFastLength=9;
input DIRangeFilter=10;


#DMI, ADX plots
def 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), DMILength);
def "DI+" = 100 * MovingAverage(averageType, plusDM, DMILength) / ATR;
def "DI-" = 100 * MovingAverage(averageType, minusDM, DMILength) / ATR;
def DX = if ("DI+" + "DI-" > 0) then 100 * AbsValue("DI+" - "DI-") / ("DI+" + "DI-") else 0;
plot ADX = MovingAverage(averageType, DX, DMILength);

#DIline - small diff = sideways
def DIrange = AbsValue(AbsValue("DI+")-AbsValue("DI-"));
#dirange.setPaintingStrategy(paintingStrategy.HISTOGRAM);
def DIok=DIRange>DIRangeFilter;

#adx filters
plot adxavg = MovingAverage(AverageType.SIMPLE, ADX, DMILength);
def ADXOk = ADX > ADXCutoff;# and adx>adxavg;

def DMICutBull = ("DI-" < ADXCutoff and "DI+" > ADXCutoff) or ("DI+" > ADX and "DI-" < ADX) ;
def DMICutBear = ("DI+" < ADXCutoff and "DI-" > ADXCutoff) or ("DI+" < ADX and "DI-" > ADX);

def dxcrossBull = if IsNaN(dxcrossBull[1]) then "DI+" > "DI-" #for init -what it is on first bar
else if "DI+" crosses above "DI-" then 1
else if dxcrossBull[1] > 0 and "DI+" > "DI-" then 1
else 0;
#plot dxXBull=dxCrossBull;
def dxcrossBear = if IsNaN(dxcrossBear[1]) then "DI-" > "DI+"
else if "DI+" crosses below "DI-" then 1
else if dxcrossBear[1] > 0 and "DI+" < "DI-" then 1
else 0 ;
#plot dxXBear=dxCrossBear;
#==========Pivots
def pivotprice=close;

#pivots per sami. changed logic for watchlist so there is no [-1]
def engbull= close>high[1] and low<=low[1];
def engbear= close<low[1] and high>=high[1];
def pivotHigh=(low[2] >low[1] and low>low[1] and close>pivotprice[1]) or engbull ;
def pivotLow=(high[2] <high[1] and high<high[1] and close<pivotprice[1]) or engbear;

def lastPH= if isnan(close[1]) then low else if PivotHigh then low[1] else LastPH[1];
def lastPL= if isnan(close[1]) then high else if PivotLow then high[1] else LastPL[1];

def breakout=if close> lastPL and close[1]<= lastPL then 1 else 0 ;
def breakdown= if close< lastPH and close[1]>= lastPH then 1 else 0;
#=============================

def signalbull = if dxcrossBull and ADXOk and DIOk then 1 else 0;
def signalbear = if dxcrossBear and ADXOk and DIOk then 1 else 0;

# ignore the signal if prevsignal was same direction and had higher DI
def signal = if signalbull then 1 else if signalbear then -1 else 0;

def prevSignal = if IsNaN(prevSignal[1]) then signal[1]
else if (signal[1] <> signal) then signal[1]
else prevSignal[1];

def DAPEntry = if signalbull and !signalbull[1] and prevSignal <= 0 then 1
else if signalbear and !signalbear[1] and prevSignal >= 0 then -1
else 0;


# Entry based on mas
input ATRMult = 0.3;
def MAFast = ExpAverage(close, MaFastLength);


#======study display

plot pDIPlus = "DI+";
plot pDIminus = "DI-";
pDIPlus.SetDefaultColor(Color.GREEN);
pDIminus.SetDefaultColor(Color.RED);
AddCloud(pDIPlus, pDIminus, Color.UPTICK);

#plot padxcutoff = ADXCutoff;
plot padxcutoff = if !isnan(close) then ADXCutoff else double.nan;
padxcutoff.assignValueColor(if (adx < adxCutoff) or (pDiminus > adxcutoff) or (pDiplus < adxCutoff) then color.light_red else Color.green);
padxcutoff.SetLineWeight(1);
padxcutoff.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);

#adx cross plots
#pivots
def prange=2; #pivot range
def adxbull = ADX > lowest(ADX,prange)[1];
def adxbear = ADX < highest(ADX,prange)[1];

ADX.AssignValueColor(if adxbull then Color.cyan else if adxbear then Color.orange else Color.GRAY);

def ptrend=adx;
def adxPH= if isnan(ptrend[-1]) then 0 else lowest(ptrend,prange)[1] > ptrend and lowest(ptrend,prange)[-prange]> ptrend ;
def adxPL= if isnan(ptrend[-1]) then 0 else highest(ptrend,prange)[1] < ptrend and highest(ptrend,prange)[-prange]< ptrend ;

# Trend Direction

def dmisprd = pdiPlus - pdiMinus;

AddLabel(yes, if DMICutBull then "Trend Status: UP | D+: " + round(pdiPlus,2) + " D-: " + round(pdiMinus,2) + " Spread: " + round(dmisprd,2) else "Trend Status: DOWN | D-: " + round(pdiMinus,2) + " D+: " + round(pdiPlus,2) + " Spread: " + round(dmisprd,2), if DMICutBull then color.green else color.red);


# ADX Dynamic Label
# Adds ADX value and context

input ADXLength = 6;
input ADXLower = 25;
input ADXMid = 40;
input ADXHigh = 75;
#input MALength = 10;
input MALength = 9;

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

# ADX Label
AddLabel(yes, if ADXlabel < ADXLower then " Strenght: " + Round(ADXlabel,2) + " SETTING UP - Watch/Wait " else if ADXlabel < ADXMid then " Strenght: " + Round(ADXlabel,2) + " CHOPPY - Watch/Wait " else if ADXlabel < ADXlabel[1] then " Strenght: " + Round(ADXlabel,2) + " TREND WEAKENING " else if ADXlabel > ADXlabel[1] and MA > MA[1] and ADXlabel < ADXHigh then " Strenght: " + Round(ADXlabel,2) + " UPTRENDING " else if ADXlabel > ADXlabel[1] and MA < MA[1] then " Strenght: " + Round(ADXlabel,2) + " DOWNTRENDING " else if ADXlabel > ADXHigh then " Strenght: " + Round(ADXlabel,2) + " HIGH/WAIT TO COOL OFF " else " ", if ADXlabel < ADXLower then Color.CYAN else if ADXlabel < ADXMid then Color.RED else if (ADXlabel < ADXlabel[1]) then Color.YELLOW else if ADXlabel > ADXlabel[1] and MA > MA[1] and ADXlabel < ADXHigh then Color.GREEN else if ADXlabel > ADXlabel[1] and MA < MA[1] then Color.RED else if ADXlabel > ADXHigh then Color.MAGENTA else Color.light_gray);

# end of ADX
Wow...thank you very much for your help! Learned something new today. Deeply appreciate your help.
 
I'm trying to create an adx/dmi lower to work with the ADXcellence book. he uses DMI 13 and ADX 8 for his settings. In TOS the default DMI lower only lets you set 1 time frame ie. 14 days and applies it to both the DMI and ADX.
 
Last edited by a moderator:
I'm trying to create an adx/dmi lower to work with the ADXcellence book. he uses DMI 13 and ADX 8 for his settings. In TOS the default DMI lower only lets you set 1 time frame ie. 14 days and applies it to both the DMI and ADX.

Try this

Screenshot-2022-10-30-174319.png
Ruby:
declare lower;

input lengthDi = 13;
input lengthADX = 8;
input line = 20;

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 = WildersAverage(TrueRange(high, close, low), lengthDi);
plot "DI+" = 100 * WildersAverage(plusDM, lengthDi) / ATR;
plot "DI-" = 100 * WildersAverage(minusDM, lengthDi) / ATR;
def DX = if ("DI+" + "DI-" > 0) then 100 * AbsValue("DI+" - "DI-") / ("DI+" + "DI-") else 0;

def ATR1 = WildersAverage(TrueRange(high, close, low), lengthADX);
def "DI1+" = 100 * WildersAverage(plusDM, lengthADX) / ATR1;
def "DI1-" = 100 * WildersAverage(minusDM, lengthADX) / ATR1;
def DX1 = if ("DI1+" + "DI1-" > 0) then 100 * AbsValue("DI1+" - "DI1-") / ("DI1+" + "DI1-") else 0;
plot lineplot=line;
plot ADX = WildersAverage(DX1, lengthADX);
ADX.assignvalueColor(if adx[1]<adx then color.greeN else color.red);
adx.setlineWeight(3);
"DI+".SetDefaultColor(GetColor(1));
"DI-".SetDefaultColor(GetColor(8));
rec adxcount = if adxcount[1]==0 then 1 else if adx<line then adxcount[1]+1 else 0;
plot adxarrow = if adxcount==20 then adx else double.nan;
adxarrow.setpaintingStrategy(paintingStrategy.ARROW_UP);
addlabel(yes,"ADX below 20 count " + adxcount);
 
Hi All, below is the script I've put together coming/learning from this site. As a Trend Trader and holding pos longer are profitable. The quick scalp is a bit stressful and requires leverage, which I don't have at this time. The script provides conditions and a quick glance before you decide on pos entry or exit. For simplicity, the colored ADXCutoff dots. Please watch some youtube clips to better used ADX/DMI indicators. It is a lifesaver. Good luck! @cabe1332
Ruby:
# ADX_DMI indicator
# cabe1332
# 20210814

# ADX code start
declare lower;

# You can modify ADX setting below to you liking

input ADXCutoff = 25;
input DMILength = 6;
input MaFastLength=9;
input DIRangeFilter=10;


#DMI, ADX plots
def 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), DMILength);
def "DI+" = 100 * MovingAverage(averageType, plusDM, DMILength) / ATR;
def "DI-" = 100 * MovingAverage(averageType, minusDM, DMILength) / ATR;
def DX = if ("DI+" + "DI-" > 0) then 100 * AbsValue("DI+" - "DI-") / ("DI+" + "DI-") else 0;
plot ADX = MovingAverage(averageType, DX, DMILength);

#DIline - small diff = sideways
def DIrange = AbsValue(AbsValue("DI+")-AbsValue("DI-"));
#dirange.setPaintingStrategy(paintingStrategy.HISTOGRAM);
def DIok=DIRange>DIRangeFilter;

#adx filters
plot adxavg = MovingAverage(AverageType.SIMPLE, ADX, DMILength);
def ADXOk = ADX > ADXCutoff;# and adx>adxavg;

def DMICutBull = ("DI-" < ADXCutoff and "DI+" > ADXCutoff) or ("DI+" > ADX and "DI-" < ADX) ;
def DMICutBear = ("DI+" < ADXCutoff and "DI-" > ADXCutoff) or ("DI+" < ADX and "DI-" > ADX);

def dxcrossBull = if IsNaN(dxcrossBull[1]) then "DI+" > "DI-" #for init -what it is on first bar
else if "DI+" crosses above "DI-" then 1
else if dxcrossBull[1] > 0 and "DI+" > "DI-" then 1
else 0;
#plot dxXBull=dxCrossBull;
def dxcrossBear = if IsNaN(dxcrossBear[1]) then "DI-" > "DI+"
else if "DI+" crosses below "DI-" then 1
else if dxcrossBear[1] > 0 and "DI+" < "DI-" then 1
else 0 ;
#plot dxXBear=dxCrossBear;
#==========Pivots
def pivotprice=close;

#pivots per sami. changed logic for watchlist so there is no [-1]
def engbull= close>high[1] and low<=low[1];
def engbear= close<low[1] and high>=high[1];
def pivotHigh=(low[2] >low[1] and low>low[1] and close>pivotprice[1]) or engbull ;
def pivotLow=(high[2] <high[1] and high<high[1] and close<pivotprice[1]) or engbear;

def lastPH= if isnan(close[1]) then low else if PivotHigh then low[1] else LastPH[1];
def lastPL= if isnan(close[1]) then high else if PivotLow then high[1] else LastPL[1];

def breakout=if close> lastPL and close[1]<= lastPL then 1 else 0 ;
def breakdown= if close< lastPH and close[1]>= lastPH then 1 else 0;
#=============================

def signalbull = if dxcrossBull and ADXOk and DIOk then 1 else 0;
def signalbear = if dxcrossBear and ADXOk and DIOk then 1 else 0;

# ignore the signal if prevsignal was same direction and had higher DI
def signal = if signalbull then 1 else if signalbear then -1 else 0;

def prevSignal = if IsNaN(prevSignal[1]) then signal[1]
else if (signal[1] <> signal) then signal[1]
else prevSignal[1];

def DAPEntry = if signalbull and !signalbull[1] and prevSignal <= 0 then 1
else if signalbear and !signalbear[1] and prevSignal >= 0 then -1
else 0;


# Entry based on mas
input ATRMult = 0.3;
def MAFast = ExpAverage(close, MaFastLength);

#vwap
def vwp = reference VWAP("time frame" = "DAY");
def ATRMod = ATRMult * ATR;

def uptrend = signalbull;
def downtrend = signalbear ;

def PivotEntry = if uptrend and pivothigh then 1
else if downtrend and pivotlow then -1
else 0 ;

def VWPPB = if uptrend and low <= vwp + ATRMod and close > vwp then 1
else if downtrend and high >= vwp - ATRMod and close < vwp then -1
else 0 ;
#significant cross
def sigcross = if MAFast crosses above vwp and uptrend then 1.5
else if MAFast crosses below vwp and downtrend then -1.5
else 0;

#=== combined entry signal
def entry =
if sigcross <> 0 then sigcross
else
if VWPPB > 0 and pivotEntry>0 then 2
else if VWPPB < 0 and pivotEntry<0 then- 2
else if pivotEntry>0 then 1
else if pivotEntry<0 then -1
else 0
;
#======study display

plot pDIPlus = "DI+";
plot pDIminus = "DI-";
pDIPlus.SetDefaultColor(Color.GREEN);
pDIminus.SetDefaultColor(Color.RED);
AddCloud(pDIPlus, pDIminus, Color.UPTICK);

#plot padxcutoff = ADXCutoff;
plot padxcutoff = if !isnan(close) then ADXCutoff else double.nan;
padxcutoff.assignValueColor(if (adx < adxCutoff) or (pDiminus > adxcutoff) or (pDiplus < adxCutoff) then color.light_red else Color.green);
padxcutoff.SetLineWeight(1);
padxcutoff.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);

#adx cross plots
#pivots
def prange=2; #pivot range
def adxbull = ADX > lowest(ADX,prange)[1];
def adxbear = ADX < highest(ADX,prange)[1];

ADX.AssignValueColor(if adxbull then Color.cyan else if adxbear then Color.orange else Color.GRAY);

def ptrend=adx;
def adxPH= if isnan(ptrend[-1]) then 0 else lowest(ptrend,prange)[1] > ptrend and lowest(ptrend,prange)[-prange]> ptrend ;
def adxPL= if isnan(ptrend[-1]) then 0 else highest(ptrend,prange)[1] < ptrend and highest(ptrend,prange)[-prange]< ptrend ;

# Trend Direction

def dmisprd = pdiPlus - pdiMinus;

AddLabel(yes, if DMICutBull then "Trend Status: UP | D+: " + round(pdiPlus,2) + " D-: " + round(pdiMinus,2) + " Spread: " + round(dmisprd,2) else "Trend Status: DOWN | D-: " + round(pdiMinus,2) + " D+: " + round(pdiPlus,2) + " Spread: " + round(dmisprd,2), if DMICutBull then color.green else color.red);


# ADX Dynamic Label
# Adds ADX value and context

input ADXLength = 6;
input ADXLower = 25;
input ADXMid = 40;
input ADXHigh = 75;
#input MALength = 10;
input MALength = 9;

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

# ADX Label
AddLabel(yes, if ADXlabel < ADXLower then " Strenght: " + Round(ADXlabel,2) + " SETTING UP - Watch/Wait " else if ADXlabel < ADXMid then " Strenght: " + Round(ADXlabel,2) + " CHOPPY - Watch/Wait " else if ADXlabel < ADXlabel[1] then " Strenght: " + Round(ADXlabel,2) + " TREND WEAKENING " else if ADXlabel > ADXlabel[1] and MA > MA[1] and ADXlabel < ADXHigh then " Strenght: " + Round(ADXlabel,2) + " UPTRENDING " else if ADXlabel > ADXlabel[1] and MA < MA[1] then " Strenght: " + Round(ADXlabel,2) + " DOWNTRENDING " else if ADXlabel > ADXHigh then " Strenght: " + Round(ADXlabel,2) + " HIGH/WAIT TO COOL OFF " else " ", if ADXlabel < ADXLower then Color.CYAN else if ADXlabel < ADXMid then Color.RED else if (ADXlabel < ADXlabel[1]) then Color.YELLOW else if ADXlabel > ADXlabel[1] and MA > MA[1] and ADXlabel < ADXHigh then Color.GREEN else if ADXlabel > ADXlabel[1] and MA < MA[1] then Color.RED else if ADXlabel > ADXHigh then Color.MAGENTA else Color.light_gray);

# end of ADX
@cabe1332 thanks for creating this script, it is a favorite of mine. I have a couple questions I'd like to ask you about this script.
 
Last edited by a moderator:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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