MasaNakamura

ADX and DI

Average Directional Index ( ADX )
See https://stockcharts.com/school/doku.php?st=adx&id=chart_school:technical_indicators:average_directional_index_adx for detail.
Remove from Favorite Scripts Add to Favorite Scripts
study("ADX and DI")
len = input(title="Length", type=integer, defval=14)
th = input(title="threshold", type=integer, defval=20)

TrueRange = max(max(high-low, abs(high-nz(close[1]))), abs(low-nz(close[1])))
DirectionalMovementPlus = high-nz(high[1]) > nz(low[1])-low ? max(high-nz(high[1]), 0): 0
DirectionalMovementMinus = nz(low[1])-low > high-nz(high[1]) ? max(nz(low[1])-low, 0): 0


SmoothedTrueRange = nz(SmoothedTrueRange[1]) - (nz(SmoothedTrueRange[1])/len) + TrueRange
SmoothedDirectionalMovementPlus = nz(SmoothedDirectionalMovementPlus[1]) - (nz(SmoothedDirectionalMovementPlus[1])/len) + DirectionalMovementPlus
SmoothedDirectionalMovementMinus = nz(SmoothedDirectionalMovementMinus[1]) - (nz(SmoothedDirectionalMovementMinus[1])/len) + DirectionalMovementMinus

DIPlus = SmoothedDirectionalMovementPlus / SmoothedTrueRange * 100
DIMinus = SmoothedDirectionalMovementMinus / SmoothedTrueRange * 100
DX = abs(DIPlus-DIMinus) / (DIPlus+DIMinus)*100
ADX = sma(DX, len)

plot(DIPlus, color=green, title="DI+")
plot(DIMinus, color=red, title="DI-")
plot(ADX, color=black, title="ADX")
hline(th, color=black, linestyle=dashed)
Will you please tell me which packages are required for the functions study(), input()?
Thanking you in anticipation
Reply
How to build exponential ADX?
Reply
Hi, is it possible to test the performance with trading view strategy tester? Would be very interesting. Thanks for your help!
Reply
Hi, good one. Thank You. Can you guide how can we scan the stocks using this whenever +DI / -DI crosses some levels ? Thanks in advance.
Reply
Nicely done,thanks for this.
Was surprised ADX was not included as one of the 'Built-in' indicators. To add to this, would it be possible to include additional threshold levels in-line with the ADX article http://www.investopedia.com/articles/trading/07/adx-trend-indicator.asp .
+2 Reply
it is, its part of the directional movement indicator which kindas throws me off because this is exactly the same as the built in one?
Reply
MasaNakamura liftedAnalytics.Lmt
Yes, ADX and DI were built in TradingView but I overlooked them that's why I wrote this script :)
Reply
Very Nice...Thanks.
Reply
United States
United Kingdom
India
Deutschland
España
France
Italia
Polska
Brasil
Россия
Türkiye
Indonesia
Malaysia
日本
한국
Home Stock Screener Forex Signal Finder Economic Calendar How It Works Chart Features House Rules Moderators For the WEB Widgets Stock Charting Library Priority Support Feature Request Blog & News FAQ Help & Wiki Twitter
Profile Profile Settings Account and Billing Priority Support Ideas Published Followers Following Private Messages Chat Sign Out