OPEN-SOURCE SCRIPT

Combined WMA and ADX

109
//version=6
indicator("Combined WMA and ADX", shorttitle="WMA & ADX", overlay=true, timeframe="", timeframe_gaps=true)

// --- WMA Inputs ---
lenWMA = input.int(9, minval=1, title="WMA Length")
src = input(close, title="WMA Source")
offset = input.int(title="WMA Offset", defval=0, minval=-500, maxval=500, display=display.data_window)

// --- ADX Inputs ---
adxlen = input(14, title="ADX Smoothing")
dilen = input(14, title="DI Length")

// --- WMA Calculation ---
outWMA = ta.wma(src, lenWMA)

// --- ADX and DI Calculation ---
dirmov(len) =>
up = ta.change(high)
down = -ta.change(low)
plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
truerange = ta.rma(ta.tr, len)
plus = fixnan(100 * ta.rma(plusDM, len) / truerange)
minus = fixnan(100 * ta.rma(minusDM, len) / truerange)
[plus, minus]

adx(dilen, adxlen) =>
[plus, minus] = dirmov(dilen)
sum = plus + minus
adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
adx

sigADX = adx(dilen, adxlen)

// --- Plot WMA and ADX ---
plot(outWMA, title="WMA", color=color.blue, offset=offset)
plot(sigADX, title="ADX", color=color.red)

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.