// ||------------------------------------------------------------------------------------------------------------------------------------------------------------------------\\ ||
// || This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ \\ ||
// ||------------------------------------------------------------------------------------------------------------------------------------------------------------------------\\ ||
// || DMI in Pine v4 \\ ||
// ||------------------------------------------------------------------------------------------------------------------------------------------------------------------------\\ ||
//<Start Source> <pine>
//@version=4
study(title='DMI (Pine v4)', shorttitle= 'DMI', overlay=false)
len = input(14, minval=1, title="DI Length")
lensig = input(14, title="ADX Smoothing", minval=1, maxval=50)
dmi(len, lensig) =>
up = change(high)
down = -change(low)
plusDM = na(up) ? na : up > down and up > 0 ? up : 0
minusDM = na(down) ? na : down > up and down > 0 ? down : 0
trur = rma(tr, len)
plus = fixnan(100 * rma(plusDM, len) / trur)
minus = fixnan(100 * rma(minusDM, len) / trur)
sum = plus + minus
adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), lensig)
[plus, minus, adx]
[D, I, A] = dmi(len, lensig)
plot(D, color=color.blue, title="+DI")
plot(I, color=color.orange, title="-DI")
plot(A, color=color.red, title="ADX")
// </End Source> </pine>
// ||----------------------------------------------------------------------------------------------------------------------------------------------------------------------------||
// || ||
// ||--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ||
// || Published by © Eric Thies on Tradingview.com --> Released on 2/13/2020 ||
// ||--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ||