MasaNakamura

ADX and DI

3436 4 1837
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)
JRG PRO
2 years ago
Very Nice...Thanks.
Reply
Shuuro
a year ago
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 .
Reply
liftedAnalytics.Lmt PRO Shuuro
8 months ago
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
8 months ago
Yes, ADX and DI were built in TradingView but I overlooked them that's why I wrote this script :)
Reply
Ideas Scripts Chart
United States
United Kingdom
India
España
Italia
Brasil
Россия
Türkiye
日本
한국
Home Stock Screener 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
Private Messages Chat Ideas Published Followers Following Priority Support Public Profile Profile Settings Billing Sign Out