my adx di improved
study("ADX and DI improved") len1 = input(title="Length", type=integer, defval=20) th1 = input(title="threshold", type=integer, defval=20) TrueRange1 = max(max(high-low, abs(high-nz(close[1]))), abs(low-nz(close[1]))) DirectionalMovementPlus1 = high-nz(high[1]) > nz(low[1])-low ? max(high-nz(high[1]), 0): 0 DirectionalMovementMinus1 = nz(low[1])-low > high-nz(high[1]) ? max(nz(low[1])-low, 0): 0 SmoothedTrueRange1 = nz(SmoothedTrueRange1[1]) - (nz(SmoothedTrueRange1[1])/len1) + TrueRange1 SmoothedDirectionalMovementPlus1 = nz(SmoothedDirectionalMovementPlus1[1]) - (nz(SmoothedDirectionalMovementPlus1[1])/len1) + DirectionalMovementPlus1 SmoothedDirectionalMovementMinus1 = nz(SmoothedDirectionalMovementMinus1[1]) - (nz(SmoothedDirectionalMovementMinus1[1])/len1) + DirectionalMovementMinus1 DIPlus1 = SmoothedDirectionalMovementPlus1 / SmoothedTrueRange1 * 100 DIMinus1 = SmoothedDirectionalMovementMinus1 / SmoothedTrueRange1 * 100 DX1 = abs(DIPlus1-DIMinus1) / (DIPlus1+DIMinus1)*100 //ADX1 = sma(DX1, len1) // TEMA ema1 = ema(DX1, 14) ema2 = ema(ema1, 14) ema3 = ema(ema2, 14) ADX1 = 3 * (ema1 - ema2) + ema3 plot(DIPlus1, color=green, title="DI+") plot(DIMinus1, color=red, title="DI-") plot(ADX1, color=black, title="ADX") hline(th1, color=black, linestyle=dashed) // --- len2 = input(title="Length", type=integer, defval=18) th2 = input(title="threshold", type=integer, defval=20) TrueRange2 = max(max(high-low, abs(high-nz(close[1]))), abs(low-nz(close[1]))) DirectionalMovementPlus2 = high-nz(high[1]) > nz(low[1])-low ? max(high-nz(high[1]), 0): 0 DirectionalMovementMinus2 = nz(low[1])-low > high-nz(high[1]) ? max(nz(low[1])-low, 0): 0 SmoothedTrueRange2 = nz(SmoothedTrueRange2[1]) - (nz(SmoothedTrueRange2[1])/len2) + TrueRange2 SmoothedDirectionalMovementPlus2 = nz(SmoothedDirectionalMovementPlus2[1]) - (nz(SmoothedDirectionalMovementPlus2[1])/len2) + DirectionalMovementPlus2 SmoothedDirectionalMovementMinus2 = nz(SmoothedDirectionalMovementMinus2[1]) - (nz(SmoothedDirectionalMovementMinus2[1])/len2) + DirectionalMovementMinus2 DIPlus2 = SmoothedDirectionalMovementPlus2 / SmoothedTrueRange2 * 100 DIMinus2 = SmoothedDirectionalMovementMinus2 / SmoothedTrueRange2 * 100 DX2 = abs(DIPlus2-DIMinus2) / (DIPlus2+DIMinus2)*100 ADX2 = sma(DX2, len2) plot(DIPlus2, color=green, title="DI+") plot(DIMinus2, color=red, title="DI-") //plot(ADX2, color=black, title="ADX") // --- len3 = input(title="Length", type=integer, defval=16) th3 = input(title="threshold", type=integer, defval=20) TrueRange3 = max(max(high-low, abs(high-nz(close[1]))), abs(low-nz(close[1]))) DirectionalMovementPlus3 = high-nz(high[1]) > nz(low[1])-low ? max(high-nz(high[1]), 0): 0 DirectionalMovementMinus3 = nz(low[1])-low > high-nz(high[1]) ? max(nz(low[1])-low, 0): 0 SmoothedTrueRange3 = nz(SmoothedTrueRange3[1]) - (nz(SmoothedTrueRange3[1])/len3) + TrueRange3 SmoothedDirectionalMovementPlus3 = nz(SmoothedDirectionalMovementPlus3[1]) - (nz(SmoothedDirectionalMovementPlus3[1])/len3) + DirectionalMovementPlus3 SmoothedDirectionalMovementMinus3 = nz(SmoothedDirectionalMovementMinus3[1]) - (nz(SmoothedDirectionalMovementMinus3[1])/len3) + DirectionalMovementMinus3 DIPlus3 = SmoothedDirectionalMovementPlus3 / SmoothedTrueRange3 * 100 DIMinus3 = SmoothedDirectionalMovementMinus3 / SmoothedTrueRange3 * 100 DX3 = abs(DIPlus3-DIMinus3) / (DIPlus3+DIMinus3)*100 ADX3 = sma(DX3, len3) plot(DIPlus3, color=green, title="DI+") plot(DIMinus3, color=red, title="DI-") // --- len4 = input(title="Length", type=integer, defval=14) th4 = input(title="threshold", type=integer, defval=20) TrueRange4 = max(max(high-low, abs(high-nz(close[1]))), abs(low-nz(close[1]))) DirectionalMovementPlus4 = high-nz(high[1]) > nz(low[1])-low ? max(high-nz(high[1]), 0): 0 DirectionalMovementMinus4 = nz(low[1])-low > high-nz(high[1]) ? max(nz(low[1])-low, 0): 0 SmoothedTrueRange4 = nz(SmoothedTrueRange4[1]) - (nz(SmoothedTrueRange4[1])/len4) + TrueRange4 SmoothedDirectionalMovementPlus4 = nz(SmoothedDirectionalMovementPlus4[1]) - (nz(SmoothedDirectionalMovementPlus4[1])/len4) + DirectionalMovementPlus4 SmoothedDirectionalMovementMinus4 = nz(SmoothedDirectionalMovementMinus4[1]) - (nz(SmoothedDirectionalMovementMinus4[1])/len4) + DirectionalMovementMinus4 DIPlus4 = SmoothedDirectionalMovementPlus4 / SmoothedTrueRange4 * 100 DIMinus4 = SmoothedDirectionalMovementMinus4 / SmoothedTrueRange4 * 100 DX4 = abs(DIPlus4-DIMinus4) / (DIPlus4+DIMinus4)*100 ADX4 = sma(DX4, len4) plot(DIPlus4, color=green, title="DI+") plot(DIMinus4, color=red, title="DI-") // --- len5 = input(title="Length", type=integer, defval=12) th5 = input(title="threshold", type=integer, defval=20) TrueRange5 = max(max(high-low, abs(high-nz(close[1]))), abs(low-nz(close[1]))) DirectionalMovementPlus5 = high-nz(high[1]) > nz(low[1])-low ? max(high-nz(high[1]), 0): 0 DirectionalMovementMinus5 = nz(low[1])-low > high-nz(high[1]) ? max(nz(low[1])-low, 0): 0 SmoothedTrueRange5 = nz(SmoothedTrueRange5[1]) - (nz(SmoothedTrueRange5[1])/len5) + TrueRange5 SmoothedDirectionalMovementPlus5 = nz(SmoothedDirectionalMovementPlus5[1]) - (nz(SmoothedDirectionalMovementPlus5[1])/len5) + DirectionalMovementPlus5 SmoothedDirectionalMovementMinus5 = nz(SmoothedDirectionalMovementMinus5[1]) - (nz(SmoothedDirectionalMovementMinus5[1])/len5) + DirectionalMovementMinus5 DIPlus5 = SmoothedDirectionalMovementPlus5 / SmoothedTrueRange5 * 100 DIMinus5 = SmoothedDirectionalMovementMinus5 / SmoothedTrueRange5 * 100 DX5 = abs(DIPlus5-DIMinus5) / (DIPlus5+DIMinus5)*100 ADX5 = sma(DX5, len5) plot(DIPlus5, color=green, title="DI+") plot(DIMinus5, color=red, title="DI-") // --- len6 = input(title="Length", type=integer, defval=10) th6 = input(title="threshold", type=integer, defval=20) TrueRange6 = max(max(high-low, abs(high-nz(close[1]))), abs(low-nz(close[1]))) DirectionalMovementPlus6 = high-nz(high[1]) > nz(low[1])-low ? max(high-nz(high[1]), 0): 0 DirectionalMovementMinus6 = nz(low[1])-low > high-nz(high[1]) ? max(nz(low[1])-low, 0): 0 SmoothedTrueRange6 = nz(SmoothedTrueRange6[1]) - (nz(SmoothedTrueRange6[1])/len6) + TrueRange6 SmoothedDirectionalMovementPlus6 = nz(SmoothedDirectionalMovementPlus6[1]) - (nz(SmoothedDirectionalMovementPlus6[1])/len6) + DirectionalMovementPlus6 SmoothedDirectionalMovementMinus6 = nz(SmoothedDirectionalMovementMinus6[1]) - (nz(SmoothedDirectionalMovementMinus6[1])/len6) + DirectionalMovementMinus6 DIPlus6 = SmoothedDirectionalMovementPlus6 / SmoothedTrueRange6 * 100 DIMinus6 = SmoothedDirectionalMovementMinus6 / SmoothedTrueRange6 * 100 DX6 = abs(DIPlus6-DIMinus6) / (DIPlus6+DIMinus6)*100 ADX6 = sma(DX6, len6) plot(DIPlus6, color=green, title="DI+") plot(DIMinus6, color=red, title="DI-") // --- len7 = input(title="Length", type=integer, defval=8) th7 = input(title="threshold", type=integer, defval=20) TrueRange7 = max(max(high-low, abs(high-nz(close[1]))), abs(low-nz(close[1]))) DirectionalMovementPlus7 = high-nz(high[1]) > nz(low[1])-low ? max(high-nz(high[1]), 0): 0 DirectionalMovementMinus7 = nz(low[1])-low > high-nz(high[1]) ? max(nz(low[1])-low, 0): 0 SmoothedTrueRange7 = nz(SmoothedTrueRange7[1]) - (nz(SmoothedTrueRange7[1])/len7) + TrueRange7 SmoothedDirectionalMovementPlus7 = nz(SmoothedDirectionalMovementPlus7[1]) - (nz(SmoothedDirectionalMovementPlus7[1])/len7) + DirectionalMovementPlus7 SmoothedDirectionalMovementMinus7 = nz(SmoothedDirectionalMovementMinus7[1]) - (nz(SmoothedDirectionalMovementMinus7[1])/len7) + DirectionalMovementMinus7 DIPlus7 = SmoothedDirectionalMovementPlus7 / SmoothedTrueRange7 * 100 DIMinus7 = SmoothedDirectionalMovementMinus7 / SmoothedTrueRange7 * 100 DX7 = abs(DIPlus7-DIMinus7) / (DIPlus7+DIMinus7)*100 ADX7 = sma(DX7, len7) plot(DIPlus7, color=green, title="DI+") plot(DIMinus7, color=red, title="DI-")