ADX DMI Indicator For ThinkOrSwim

bobomatic

Member
I've used this for quite some time. Helps know to sit on my hands and when it's a good time to dive in.

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);
 
Last edited by a moderator:
Hi everybody,
my programming skills are limited and I fail to adjust the ADX with (High+Low+Close/3) as a basis.
Woulkd someone be so kind to help me out to solve that.
I think I have nice easy to follow strategy and I want to share it with th ecommunity with the right setups.
Thanks:

Here is the code for the ADX to adjust

declare lower;

input length = 14;
input averageType = AverageType.Wilders;


plot ADX = DMI(length, averageType).ADX;
ADX.setDefaultColor(GetColor(5));
plot zeroline = 22;

plot Level70 = 75;
plot Level30 = 40;

Level70.SetDefaultColor(GetColor(3));
Level30.SetDefaultColor(GetColor(3));
 
Hi everybody,
my programming skills are limited and I fail to adjust the ADX with (High+Low+Close/3) as a basis.
Woulkd someone be so kind to help me out to solve that.
I think I have nice easy to follow strategy and I want to share it with th ecommunity with the right setups.

Take a look at where the ADX value is coming from. The ADX study calls the DMI study to get the ADX value.
plot ADX = DMI(length, averageType).ADX;

So let's take a look at DMI. Here's TOS's code.

Ruby:
declare lower;

input length = 14;
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);
plot "DI+" = 100 * MovingAverage(averageType, plusDM, length) / ATR;
plot "DI-" = 100 * MovingAverage(averageType, minusDM, length) / ATR;

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

We can see ADX is defined on the last line. We have to work our way backwards to find out how it is calculated.
ADX is an average of DX. DX is based on DI+ and DI-, which are based on other calculations.

There's no place here to plug in a single HLC/3 value unless you want to use that in place of DX. Then you can skip all of that code and just use:

Ruby:
plot ADX = MovingAverage(averageType, hlc3(), length);
 
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
 
Last edited by a moderator:
@MerryDay I agree with you. IMO, ADX/DMI is a good indicator for trend strength, not entry/exit. ADX shows the strength of the trend UP or DOWN trend. It is best for anyone interested to search youtube for how this indicator best use.

From the scripts and codes I've gathered here, I've combined a lower ADX/DMI indicator and added additional labels that I feel I needed. I find it works best with 15min and 1hr timeframe with DMILength = 6; MaFastLength=9; DIRangeFilter=10; ADXCutoff = 25;. Screenshot below. Let me know if you would like the ADX/DMI script/code, not the workspace, and I can post it here. Good luck! @cabe1332
Hi All, I am also sharing the ADX Dynamic watchlist column script. This will provide you real-time ADX Strenght value of the trend for each stock on your watchlist. The colored strength value easily identifies the following trend GREEN = UP, RED = DOWN or CHOPPY, YELLOW = WEAKENING, CYAN = SETTING UP, and MAGENTA = HIGH/WAIT TO COOL OFF. I hope you will find the share useful. Please do let me know how it works out for you. Not asking much, a thank you will bring a smile or two. Good luck! @cabe1332

# ADX Dynamic Watchlist Column
# cabe1332

# code start
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);

plot data = round(ADXlabel,1);
data.assignValueColor(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);

# code end
 
Last edited by a moderator:
@cabe1332. I am trying to do a simple scan using your indicator, and tos wouldn't do it. Screenshot of error is attached. What can I do?

https://ibb.co/z6PHKCG
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;
 
Last edited:
@cabe1332 . Thank you so much for this DMI script. I'm not a coder but I can copy-paste to make a few indicators. I moded DMI to how I wanted but I couldn't get to make good labels and set up for color changing line for 25. I stumble upon this DMI script yesterday and this is exactly what I wanted. Your hard work and sharing will result in you being aligned with the divine, in divine timing you will be blessed with wealth and success.

I've been playing around with MACD settings. I found great results with these settings so I like to contribute. I use this MACD script, here is the setting I use, give it a try and see what kind of success you will receive.
https://usethinkscript.com/threads/macd-and-squeeze-indicator-for-thinkorswim.8706/
.
 
Last edited by a moderator:
Hi, @cabe1332. Help, I'm trying to add arrows when plusdm/minusdm cross 25 to the upper chart. I tried but fail. Thanks in advance
@s1111, why would you want to clutter your upper charts with arrows while you have a clean lower indicator that works and provides you to stay long with the trade? What are you trying to accomplish, if I may ask? @cabe1332
 
Hi @cabe1332. This morning I had an idea of my problem. Instead of arrows, I added color candles. Problem solved. Happy weekend, can't wait to test it out on monday.

Green = strong uptrend
Red = strong downtrend
Gray = weakness ( both directions)

Code:
DefineGlobalColor("LabelGreen",  CreateColor(0,255, 0)) ;
DefineGlobalColor("LabelRed",  CreateColor(225, 0, 0)) ;
input paintbar = yes ;

AssignPriceColor(if !paintbar then Color.CURRENT else
if pdiPlus > padxcutoff  then GlobalColor("LabelGreen") else
if pdiminus > padxcutoff then GlobalColor("LabelRed") else
Color.GRAY);
 
Last edited:
@s1111, add the code below to your scan filter to cut down your wait. It will scan trending and bullish securities. Give this a shot to improve trading. Good luck and good trading! @cabe1332

#ADX_DMI scan study for Trending bullish stocks filter
# @cabe1332

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

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

def adxscan = round(ADXlabel,1) > 25;

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);

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

plot scan = DMICutBull and adxscan;

# code end
 
Hi @cabe1332. This morning I had an idea of my problem. Instead of arrows, I added color candles. Problem solved. Happy weekend, can't wait to test it out on monday.

Green = strong uptrend
Red = strong downtrend
Gray = weakness ( both directions)

Code:
DefineGlobalColor("LabelGreen",  CreateColor(0,255, 0)) ;
DefineGlobalColor("LabelRed",  CreateColor(225, 0, 0)) ;
input paintbar = yes ;

AssignPriceColor(if !paintbar then Color.CURRENT else
if pdiPlus > padxcutoff  then GlobalColor("LabelGreen") else
if pdiminus > padxcutoff then GlobalColor("LabelRed") else
Color.GRAY);
for this code TOS says that their is no such variable for pdiPlus > padxcutoff and pdiminus > padxcutoff
 
@cabe1332 check this code out, I modded a few things for visual, the cloud can be turned on or off in settings.
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 = Pdiplus crosses above Padxcutoff;
def bear_cross = Pdiminus crosses below Padxcutoff;

# Alerts
Alert(bull_cross, "UP arrow alert", Alert.BAR, Sound.Chimes);
Alert(bear_cross, "DOWN arrow alert", Alert.BAR, Sound.Ring);
# end
 
@s1111, add the code below to your scan filter to cut down your wait. It will scan trending and bullish securities. Give this a shot to improve trading. Good luck and good trading! @cabe1332

#ADX_DMI scan study for Trending bullish stocks filter
# @cabe1332

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

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

def adxscan = round(ADXlabel,1) > 25;

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);

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

plot scan = DMICutBull and adxscan;

# code end
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
 

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