RSI + ADX + MACD
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Dvd_Trading


//@version=5
indicator(title='RSI + ADX ')

// Getting inputs
MACDmultiplier = input.float(title='MACD Hight multiplier', minval=0.0000000000001, maxval=999999999999, defval=0.1)
fast_length = input(title='Fast Length', defval=12)
slow_length = input(title='Slow Length', defval=26)
src = input(close, title='Source')
signal_length = input.int(title='Signal Smoothing', minval=1, maxval=50, defval=9)
sma_source = input(title='Simple MA(Oscillator)', defval=false)
sma_signal = input(title='Simple MA(Signal Line)', defval=false)


RSILength = input.int(14, minval=1, title='RSI Length')


// Plot colors
col_grow_above = #26A69A
col_grow_below = #FFCDD2
col_fall_above = #B2DFDB
col_fall_below = #EF5350
col_macd = color.green  //#0094ff
col_signal = color.red  //#ff6a00

// Calculating MACD
sma_1 = ta.sma(src, fast_length)
ema_1 = ta.ema(src, fast_length)
fast_ma = sma_source ? sma_1 : ema_1
sma_2 = ta.sma(src, slow_length)
ema_2 = ta.ema(src, slow_length)
slow_ma = sma_source ? sma_2 : ema_2
macd = fast_ma - slow_ma
sma_3 = ta.sma(macd, signal_length)
ema_3 = ta.ema(macd, signal_length)
signal = sma_signal ? sma_3 : ema_3
hist = macd - signal

// RSI
up = ta.rma(math.max(ta.change(src), 0), RSILength)
down = ta.rma(-math.min(ta.change(src), 0), RSILength)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - 100 / (1 + up / down)

// Awesome Oscillator
ao = (ta.sma(hl2, 5) - ta.sma(hl2, 34)) * MACDmultiplier

// Directional Movement Index (DMI)
DMI_len = input.int(14, minval=1, title='DI Length')
DMI_lensig = input.int(14, title='ADX Smoothing', minval=1, maxval=50)

DMI_up = ta.change(high)
DMI_down = -ta.change(low)
plusDM = na(DMI_up) ? na : DMI_up > DMI_down and DMI_up > 0 ? DMI_up : 0
minusDM = na(DMI_down) ? na : DMI_down > DMI_up and DMI_down > 0 ? DMI_down : 0
trur = ta.rma(ta.tr, DMI_len)
plus = fixnan(100 * ta.rma(plusDM, DMI_len) / trur)
minus = fixnan(100 * ta.rma(minusDM, DMI_len) / trur)
sum = plus + minus
adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), DMI_lensig)



// plot MACD
plot(hist * MACDmultiplier, title='Histogram', style=plot.style_columns, color=hist >= 0 ? hist[1] < hist ? col_grow_above : col_fall_above : hist[1] < hist ? col_grow_below : col_fall_below, transp=0)
plot(macd * MACDmultiplier, title='MACD', color=color.new(col_macd, 0))
plot(signal * MACDmultiplier, title='Signal', color=color.new(col_signal, 0))

// plot RSI
plot(rsi, color=color.new(color.purple, 0))
band1 = hline(70)
band0 = hline(30)
fill(band1, band0, color=color.new(color.fuchsia, 90))
hline(50, title='center', linestyle=hline.style_solid)

// plot AO
plot(ao, color=ta.change(ao) <= 0 ? color.red : color.green, style=plot.style_histogram)

// plot DMI
plot(plus, color=color.new(color.blue, 0), title='+DI')
plot(minus, color=color.new(color.orange, 0), title='-DI')
plot(adx, color=color.new(color.red, 0), title='ADX')
hline(25, title='25%', color=color.black, linestyle=hline.style_solid)

