Volume Based RSI with ADX
// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © Noufal-Bin-Jalal

//@version=5
indicator("Volume Based RSI with ADX", overlay=false, format=format.price, precision=2, timeframe="", timeframe_gaps=true,max_labels_count = 100, max_lines_count = 100, max_boxes_count = 100, max_bars_back = 100)
//Settings
src = input.source(defval = ohlc4,group = "RSI Settings", title="RSI Source", tooltip = "What type of source using RSI?")
length = input.int(defval=25,group = "RSI Settings", minval=1, maxval=100, title="RSI Length", tooltip = "RSI length means the indicator is calculated using the last number of candles")
overbought_level = input.int(defval=70,group = "RSI Settings", minval=1, maxval=100, title="Overbought Level", tooltip = "RSI overbought level")
oversold_level = input.int(defval=30,group = "RSI Settings", minval=1, maxval=100, title="Oversold Level", tooltip = "RSI oversold level")
minVol = input.int(title="Volume Settings", group = "Minimum Volume",defval=100, minval=100, step=10, maxval=500,tooltip = "Minimum volume required for a trade")
bullColor = input.color(color.new(#3cf74b, 0),title = 'Bullish',group='RSI Settings', inline = 'RSI-Color')
bearColor = input.color(color.new(#ec4e42, 0),title = 'Bearish',group='RSI Settings', inline = 'RSI-Color')
sideColor = input.color(color.new(#8d8b8a,0),title = 'Weak Volume',group='RSI Settings', inline = 'RSI-Color')
isADX = input.bool(group='ADX Settings', title="Show ADX", defval=true, tooltip = "It show's ADX level")
adxlen = input.int(group='ADX Settings', title="ADX Smoothing", defval=14, minval=1, maxval=100)
dilen = input.int(group='ADX Settings', title="DI Length", defval=14, minval=1, maxval=100) 
threshold = input.int(group='ADX Settings',title="ADX Threshold", defval=20, minval=1, maxval=100)
adxColor = input.color(color.new(#715ceb, 80),title = 'Valid ADX',group='ADX Settings', inline = 'RSI-Color')
wadxColor = input.color(color.new(#888685, 70),title = 'Weak ADX',group='ADX Settings', inline = 'RSI-Color')
//Volume Analyze
vol = math.sign(ta.change(hlc3)) * nz(volume)
//Time Settings
var isMoment =  (second((time_close(timeframe.period, syminfo.session, syminfo.timezone) - time(timeframe.period))) <= 10) or (second((time_close(timeframe.period, syminfo.session, syminfo.timezone) - timenow)) <= 10)? true : false
bool isVol =  math.abs(vol) >= minVol ? true : false
//RSI
rsi_value = ta.rsi(src, length)
//ADX
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)
sig = adx(dilen, adxlen)
adxOk = (sig > threshold) ? true : false
color rsiColor = if(vol > syminfo.mintick and (isVol and isMoment))
	bullColor
else if (vol < syminfo.mintick and (isVol and isMoment))
	bearColor
else
	sideColor
color adxCol = (adxOk) ? adxColor :	wadxColor
// Plot RSI
topLine=hline(100, "Top Band", color=color.new(#d6da0c, 50), linestyle=hline.style_solid, editable = false)
plot(rsi_value, title="RSI", color=rsiColor, linewidth  = 2,style = plot.style_linebr, editable = false)
plot(sig, title="ADX", color=adxCol, linewidth  = 2,style = plot.style_areabr, display = (isADX) ? display.all : display.none, editable = false)
hline(overbought_level, title="Overbought", color=#787B86, linestyle=hline.style_solid)
hline(50, "Middle Band", color=color.new(#787B86, 50), linestyle=hline.style_solid)
hline(oversold_level, title="Oversold", color=#787B86, linestyle=hline.style_solid)
lowLine=hline(0, "Low Band", color=color.new(#10c210, 50), linestyle=hline.style_solid, editable = false)
fill(topLine, lowLine, color=color.rgb(126, 87, 194, 90), title="Background", editable = false)



