ADX

//version=4
study("ADX and DI Improved", shorttitle="ADX and DI Improved", overlay=false)

len = input(title="Length", type=input.integer, defval=14)
th = input(title="threshold", type=input.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

float SmoothedTrueRange = na
float SmoothedDirectionalMovementPlus = na
float SmoothedDirectionalMovementMinus = na

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=color.green, title="DI+")
plot(DIMinus, color=color.red, title="DI-")
plot(ADX, color=color.black, title="ADX")
hline(th, color=color.black, linestyle=hline.style_dashed)

crossUpDiplusDiminus = crossover(DIPlus, DIMinus)
crossDownDiplusDiminus = crossunder(DIPlus, DIMinus)

bgcolor(color=crossUpDiplusDiminus ? color.green : na, title="Tenkan Sen cross over Kijun Sen", transp=90, offset=-1)
bgcolor(color=crossDownDiplusDiminus ? color.red : na, title="Tenkan Sen cross under Kijun Sen", transp=90, offset=-1)
Trend Analysis

Disclaimer