"//@version=5
indicator("21.6) Combined VRS Line with Scoring and VWMA VRS with Big HM + wrt + RDX Score", overlay=false)

// Customizable input parameters
rsi_length_14 = input.int(14, minval=1, title='RSI Length 14', group = "WMA | Score")
rsi_length_9 = input.int(9, minval=1, title='RSI Length 9', group = "WMA | Score")
ma_length = input.int(48, minval=1, title='MA Length', group = "WMA | Score")
line_color_14 = input.color(color.red, title='Line Color RSI 14', group = "WMA | Score")
line_color_9 = input.color(color.green, title='Line Color RSI 9', group = "WMA | Score")
line_color_avg = input.color(color.blue, title='Line Color Average', group = "WMA | Score")
smoothing_len = input.int(5, minval=1, title='Smoothing Length')
wma_rsi21_len = input.int(21, minval=1, title='WMA RSI Length (21)')
wma_rsi48_len = input.int(48, minval=1, title='WMA RSI Length (48)')
src = input(close, 'Source')

// Define the MA types
ma_types = array.new_string()
array.push(ma_types, "WMA")
array.push(ma_types, "EMA")
array.push(ma_types, "SMA")
array.push(ma_types, "RMA")
array.push(ma_types, "LSMA")

// Function to calculate the selected moving average
ma(src, length, type) =>
    switch type
        "WMA" => ta.wma(src, length)
        "EMA" => ta.ema(src, length)
        "SMA" => ta.sma(src, length)
        "RMA" => ta.rma(src, length)
        "LSMA" => ta.linreg(src, length, 0)

// Calculate RSI values
rsi14 = ta.rsi(close, rsi_length_14)
rsi9 = ta.rsi(close, rsi_length_9)

// Pre-calculate moving averages for RSI values
ema_rsi14 = ma(rsi14, ma_length, "EMA")
ema_rsi9 = ma(rsi9, ma_length, "EMA")

sma_rsi14 = ma(rsi14, ma_length, "SMA")
sma_rsi9 = ma(rsi9, ma_length, "SMA")

rma_rsi14 = ma(rsi14, ma_length, "RMA")
rma_rsi9 = ma(rsi9, ma_length, "RMA")

lsma_rsi14 = ma(rsi14, ma_length, "LSMA")
lsma_rsi9 = ma(rsi9, ma_length, "LSMA")

wma_rsi14 = ma(rsi14, ma_length, "WMA")
wma_rsi9 = ma(rsi9, ma_length, "WMA")

// Initialize score tracking for the current situation
score = 0

// Calculate scores for each MA type
for i = 0 to array.size(ma_types) - 1
    ma_type = array.get(ma_types, i)
    
    // Calculate moving averages of RSI values
    ma_rsi14 = ma(rsi14, ma_length, ma_type)
    ma_rsi9 = ma(rsi9, ma_length, ma_type)
    
    // Add to score if the condition is met
    if (ma_rsi9 > ma_rsi14)
        score := score + 1

// Calculate the average of all MA types for RSI 14 and RSI 9
avg_ma_rsi14 = (ema_rsi14 + sma_rsi14 + rma_rsi14 + lsma_rsi14 + wma_rsi14) / 5
avg_ma_rsi9 = (ema_rsi9 + sma_rsi9 + rma_rsi9 + lsma_rsi9 + wma_rsi9) / 5

// Calculate the overall average MA RSI
overall_avg_ma_rsi = (avg_ma_rsi14 + avg_ma_rsi9) / 2

// Set the plot color based on the score
plot_color = score == 0 ? color.red : (score == 5 ? color.green : color.orange)

// Plot the overall average MA RSI value
plot(overall_avg_ma_rsi, color=plot_color, title="Overall Average MA RSI")

// Function to get the background color based on score
bg_color(score) =>
    switch score
        0 => color.red
        5 => color.green
        => color.orange

// Display score in a table as a fraction out of 5 or "D/I" if data is insufficient
var table table_id = table.new(position.middle_right, 3, 3)
if bar_index == 0
    table.cell(table_id, 1, 1, text="|", text_size=size.normal, text_color=color.new(color.white, 50))
table.cell(table_id, 0, 1, text=bar_index < ma_length ? "D/I" : str.tostring(score) + "/5", text_size=size.normal, bgcolor=bg_color(score), text_color=color.new(color.white, 0))

// Calculate VWMA of RSI
vwma_48 = ta.vwma(ta.rsi(src, rsi_length_14), 48)

// Calculate different smoothing averages of VWMA with adjustable lengths
ema_vwma = ta.ema(vwma_48, smoothing_len)
rma_vwma = ta.rma(vwma_48, smoothing_len)
lsma_vwma = ta.linreg(vwma_48, smoothing_len, 0)
hull_vwma = ta.wma(2 * ta.wma(vwma_48, smoothing_len / 2) - ta.wma(vwma_48, smoothing_len), math.round(math.sqrt(smoothing_len)))

// Calculate WMA of RSI with different lengths and periods
wma_rsi_14_21 = ta.wma(ta.rsi(src, rsi_length_14), wma_rsi21_len)
wma_rsi_14_48 = ta.wma(ta.rsi(src, rsi_length_14), wma_rsi48_len)
wma_rsi_9_48 = ta.wma(ta.rsi(src, rsi_length_9), wma_rsi48_len)
wma_rsi_9_21 = ta.wma(ta.rsi(src, rsi_length_9), wma_rsi21_len)

// Plot VWMA smoothing averages
plot_ema = plot(ema_vwma, color=color.blue, style=plot.style_line, linewidth=1, title='EMA of VWMA', display=display.none)
plot_rma = plot(rma_vwma, color=color.red, style=plot.style_line, linewidth=1, title='RMA of VWMA', display=display.none)
plot_lsma = plot(lsma_vwma, color=color.green, style=plot.style_line, linewidth=1, title='LSMA of VWMA', display=display.none)
plot_hull = plot(hull_vwma, color=color.purple, style=plot.style_line, linewidth=1, title='Hull MA of VWMA', display=display.none)

// Fill areas based on VWMA values
fill(plot_ema, plot_rma, color=ema_vwma > rma_vwma ? color.new(color.red, 0) : color.new(color.green, 0), title="EMA-RMA Fill")
fill(plot_lsma, plot_hull, color=lsma_vwma > hull_vwma ? color.new(color.red, 0) : color.new(color.green, 0), title="LSMA-Hull Fill")
fill(plot_ema, plot_lsma, color=ema_vwma > lsma_vwma ? color.new(color.red, 0) : color.new(color.green, 0), title="EMA-LSMA Fill")
fill(plot_rma, plot_hull, color=rma_vwma > hull_vwma ? color.new(color.red, 0) : color.new(color.green, 0), title="RMA-Hull Fill")

// Plot horizontal lines at 100, 50, and 0
h_100 = plot(100, color=color.new(color.gray, 50), style=plot.style_line, linewidth=1, title='Line - 100')
h_50 = plot(50, color=color.new(color.gray, 50), style=plot.style_line, linewidth=1, title='Line - 50')
h_0 = plot(0, color=color.new(color.gray, 50), style=plot.style_line, linewidth=1, title='Line - 0')

// Plot horizontal lines at 70 and 30
h_70 = plot(70, color=color.new(color.white, 50), style=plot.style_circles, linewidth=1, title='Line - 70')
h_30 = plot(30, color=color.new(color.white, 50), style=plot.style_circles, linewidth=1, title='Line - 30')

len = input.int(14, minval=1, title='RSI Length_B', group = "RSI")
HMsrc = input(close, 'Source', group = "RSI")
_rsi = ta.rsi(HMsrc, len)

//h_50 = plot(50, color=color.new(color.white, 50), style=plot.style_line, linewidth=1, title='Line - 50 ')
p_rsi = plot(_rsi, color=color.new(color.white, 0), style=plot.style_line, linewidth=1, title='RSI - Plot')
fill(p_rsi, h_50, color=_rsi > 50 ? color.green : color.red, title='RSI Fill', transp=75)

wma_48 = ta.wma(_rsi, 48)
//vwma_48 = ta.vwma(_rsi, 48)
ema_5 = ta.ema(_rsi, 5)

plot(wma_48, color=color.new(color.red, 0), style=plot.style_line, linewidth=1, title='Volume (WMA)', display=display.none)
plot(vwma_48, color=color.new(color.yellow, 0), style=plot.style_line, linewidth=2, title='Volume (VWMA)', display=display.none)
plot(ema_5, color=color.new(color.green, 0), style=plot.style_line, linewidth=1, title='Price')

// Define the input for the MA type, lengths, and source
ma_type = input.string(title="MA Type", defval="EMA", options=["EMA", "WMA", "SMA", "RMA", "LSMA"], group = "Trend")
ma_source = input.source(title="Source", defval=close, group = "Trend")
ma_5_length = input.int(title="Length for MA 5", defval=5, group = "Trend")
ma_9_length = input.int(title="Length for MA 9", defval=9, group = "Trend")
ma_13_length = input.int(title="Length for MA 13", defval=13, group = "Trend")

// Function to select the MA type
f_get_ma(src, length, ma_type) =>
    ma = switch ma_type
        "WMA" => ta.wma(src, length)
        "SMA" => ta.sma(src, length)
        "RMA" => ta.rma(src, length)
        "LSMA" => ta.linreg(src, length, 0)
        => ta.ema(src, length) // Default is EMA
    ma

// Calculate the MAs
ma_5 = f_get_ma(ma_source, ma_5_length, ma_type)
ma_9 = f_get_ma(ma_source, ma_9_length, ma_type)
ma_13 = f_get_ma(ma_source, ma_13_length, ma_type)

// Calculate the average of the 5, 9, and 13 MAs
ma_avg = (ma_5 + ma_9 + ma_13) / 3

// Determine the line color based on conditions
line_color = color.new(color.orange, 0)
if (ma_5 > ma_9 and ma_9 > ma_13)
    line_color := color.new(color.green, 0)
else if (ma_13 > ma_9 and ma_9 > ma_5)
    line_color := color.new(color.red, 0)

// Plot the line at 50 with the conditional color
plot(50, color=line_color, linewidth=2, title="Plot Trend")

/////

//Essential Inputs
matype = input.string(title='Moving Average Type', defval='SMA', options=['SMA', 'EMA', 'WMA'], group='Moving Average for Relative Strength')
malength = input(title='Moving Average Length', defval=50, group='Moving Average for Relative Strength')

//Index for Relative Strength
index = input.string(title='Index to compare To', defval='NSE:NIFTY', options=['NSE:NIFTY', 'NSE:CNX500', 'NSE:NIFTYSMLCAP250', 'NSE:CNXSMALLCAP'],group='Index for Relative Strength')
compareToOtherIndex = input.bool(title="Compare to different index?", defval=false, group='Index for Relative Strength', inline='Different compare')
otherIndex = input.symbol(title='', defval='', group='Index for Relative Strength', inline='Different compare')

//Customisation
Easycolors = input(true,'Easy Colors?', group="Customisation", tooltip = 'Easy colors option just changes the histogram colors to either green or red, indicating out-performance or under-performance, respectively.')

//Table options
toggleTable = input(true, group = 'Table Options', title='Show table', tooltip = 'Select this to display the table')
toggleVerboseTable = input.bool(title='Display verbose table?', defval=true, group='Table Options', tooltip = 'Select this to display the table with detailed text')

//Configuring the Moving Average
ma_function(source, length) =>
    if matype == 'SMA'
        ta.sma(source, length)
    else
        if matype == 'EMA'
            ta.ema(source, length)
        else
            if matype == 'WMA'
                ta.wma(source, length)

// Basic conditions
indexToUse = compareToOtherIndex == false ? index : otherIndex
closeIndex = request.security(indexToUse, timeframe.period, close)

ma = ma_function(close, malength)
maIndex = ma_function(closeIndex, malength)

symbolPercent = (close - ma) / ma * 100
indexPercent = (closeIndex - maIndex) / maIndex * 100
val = symbolPercent - indexPercent

priceIsAboveMa = close > ma
priceIsAboveIndexMa = closeIndex > maIndex
indexgreen = request.security(indexToUse, timeframe.period, priceIsAboveIndexMa)

priceIsBelowMa = close <= ma
priceIsBelowIndexMa = closeIndex <= maIndex
indexred = request.security(indexToUse, timeframe.period, priceIsBelowIndexMa)

rop = indexred and priceIsBelowMa and val > 0
gop = indexgreen and priceIsAboveMa and val > 0
aop = indexred and priceIsAboveMa

rup = indexgreen and priceIsAboveMa and val < 0
gup = indexred and priceIsBelowMa and val < 0
aup = indexgreen and priceIsBelowMa

roptext = "both index & stock are bearish, but stock is less bearish"
goptext = "both index & stock are bullish, but stock is more bullish"
aoptext = "index is bearish, but stock is bullish! 🤷‍♂️"
ruptext = "both index & stock are bullish, but stock is less bullish"
guptext = "both index & stock are bearish, but stock is more bearish"
auptext = "index is bullish, but stock is bearish! 🙈"

EasyColor = val >= 0 ? color.green : color.red

//Smoothing
RSma(source, length, type) =>
    switch type
        "SMA" => ta.sma(source, length)
        "EMA" => ta.ema(source, length)
        "WMA" => ta.wma(source, length)

typeMA = input.string(title = "Method", defval = "EMA", options=["SMA", "EMA", "WMA"], group="Smoothing")
smoothingLength = input.int(title = "Length", defval = 9, minval = 1, maxval = 200, group="Smoothing")

smoothingLine = RSma(val, smoothingLength, typeMA)

//Table
toggleDarkColors = input(title="Dark Mode for Table", defval=false, group = "Customisation", tooltip = 'Adjusts background colors of the table as per dark mode.')
BGColor_MARS = toggleDarkColors ? color.new(color.black, 0): color.new(color.white, 0)
TextColor_MARS = color.new(color.white, 0)
TextColorOther_MARS = toggleDarkColors ? color.new(color.white, 0): color.new(color.black, 0)

FrameCol_MARS = toggleDarkColors ? color.new(#999999, 50) : color.rgb(241, 241, 241)
BorderCol_MARS = toggleDarkColors ? color.new(color.white, 100): color.new(color.gray, 100)

string tablesize_MARS = input.string("small", "Size", inline = "21", group = 'Table Options', options = ["tiny", "small", "normal", "large", "huge", "auto"])
string tableposY_MARS = input.string("bottom", "↕", inline = "21", group = 'Table Options', options = ["top", "middle", "bottom"])
string tableposX_MARS = input.string("right", "↔", inline = "21", group = 'Table Options', options = ["left", "center", "right"])

var table marstable_MARS = table.new(tableposY_MARS + "_" + tableposX_MARS, columns = 10, rows = 10, bgcolor = BGColor_MARS, frame_color = FrameCol_MARS, frame_width = 1, border_color = BorderCol_MARS, border_width = 1)

if toggleTable and toggleVerboseTable
    table.cell(marstable_MARS, 1, 0, text= rop ? 'Relative Outperformance wrt ' + index : gop ? 'Gross Outperformance wrt ' + index : aop ? 'Absolute Outperformance wrt ' + index : rup ? 'Relative Underperformance wrt ' + index : gup ? 'Gross Underperformance wrt ' + index : aup ? 'Absolute Underperformance wrt ' + index : 'Loading...', text_halign=text.align_center, bgcolor= Easycolors ? EasyColor : color.new(color.white, 0), text_color=TextColor_MARS, text_size=tablesize_MARS)
    table.cell(marstable_MARS, 1, 1, text= rop ? roptext : gop ? goptext : aop ? aoptext : rup ? ruptext : gup ? guptext : aup ? auptext : 'change either the stock or the moving average used for MARS', text_halign=text.align_center, bgcolor=BGColor_MARS, text_color=TextColorOther_MARS, text_size=tablesize_MARS)
else if toggleTable
    table.cell(marstable_MARS, 1, 0, text= rop ? 'Relative Outperformance wrt ' + index : gop ? 'Gross Outperformance wrt ' + index : aop ? 'Absolute Outperformance wrt ' + index : rup ? 'Relative Underperformance wrt ' + index : gup ? 'Gross Underperformance wrt ' + index : aup ? 'Absolute Underperformance wrt ' + index : 'Loading...', text_halign=text.align_center, bgcolor= Easycolors ? EasyColor : color.new(color.white, 0), text_color=TextColor_MARS, text_size=tablesize_MARS)

///// RDX Score line /////

lenRDX = input(title='length_ADX', defval=14)
th = input(title='threshold_ADX', defval=14)

// Initialize variables
var float SmoothedTrueRange = na
var float SmoothedDirectionalMovementPlus = na
var float SmoothedDirectionalMovementMinus = na
var float DIPlus = na
var float DIMinus = na
var float DX = na
var float ADX = na
var color current_color = na
var color previous_color = na

TrueRange = math.max(math.max(high - low, math.abs(high - nz(close[1]))), math.abs(low - nz(close[1])))
DirectionalMovementPlus = high - nz(high[1]) > nz(low[1]) - low ? math.max(high - nz(high[1]), 0) : 0
DirectionalMovementMinus = nz(low[1]) - low > high - nz(high[1]) ? math.max(nz(low[1]) - low, 0) : 0

SmoothedTrueRange := nz(SmoothedTrueRange[1]) - nz(SmoothedTrueRange[1]) / lenRDX + TrueRange
SmoothedDirectionalMovementPlus := nz(SmoothedDirectionalMovementPlus[1]) - nz(SmoothedDirectionalMovementPlus[1]) / lenRDX + DirectionalMovementPlus
SmoothedDirectionalMovementMinus := nz(SmoothedDirectionalMovementMinus[1]) - nz(SmoothedDirectionalMovementMinus[1]) / lenRDX + DirectionalMovementMinus

DIPlus := SmoothedDirectionalMovementPlus / SmoothedTrueRange * 100
DIMinus := SmoothedDirectionalMovementMinus / SmoothedTrueRange * 100
DX := math.abs(DIPlus - DIMinus) / (DIPlus + DIMinus) * 100
ADX := ta.sma(DX, lenRDX)

length_RSI = input(14)
priceRSI = close
vrsi = ta.rsi(priceRSI, length_RSI)

m5 = ADX[1] < ADX and vrsi < 30
plotshape(m5, title='SCORE -5', text='-5', textcolor=color.new(color.white, 0), style=shape.labeldown, location=location.abovebar, color=color.new(color.red, 0), size=size.tiny, display=display.none)

m4 = ADX[1] > ADX and vrsi < 30 or ADX[1] < ADX and vrsi < 35 and vrsi > 30
plotshape(m4, title='SCORE -4', text='-4', textcolor=color.new(color.white, 0), style=shape.labeldown, location=location.abovebar, color=color.new(color.red, 0), size=size.tiny, display=display.none)

m3 = ADX[1] > ADX and vrsi < 35 and vrsi > 30 or ADX[1] < ADX and vrsi < 40 and vrsi > 35
plotshape(m3, title='SCORE -3', text='-3', textcolor=color.new(color.white, 0), style=shape.labeldown, location=location.abovebar, color=color.new(color.red, 0), size=size.tiny, display=display.none)

m2 = ADX[1] > ADX and vrsi < 40 and vrsi > 35 or ADX[1] < ADX and vrsi < 45 and vrsi > 40
plotshape(m2, title='SCORE -2', text='-2', textcolor=color.new(color.white, 0), style=shape.labeldown, location=location.abovebar, color=color.new(color.red, 0), size=size.tiny, display=display.none)

m1 = ADX[1] > ADX and vrsi < 45 and vrsi > 40
plotshape(m1, title='SCORE -1', text='-1', textcolor=color.new(color.white, 0), style=shape.labeldown, location=location.abovebar, color=color.new(color.red, 0), size=size.tiny, display=display.none)

m0 = vrsi < 55 and vrsi > 45
plotshape(m0, title='QQE long', text='0', textcolor=color.new(color.black, 0), style=shape.labelup, location=location.belowbar, color=color.new(color.yellow, 0), size=size.tiny, display=display.none)

p1 = ADX[1] > ADX and vrsi > 55 and vrsi < 60
plotshape(p1, title='SCORE 1', text='1', textcolor=color.new(color.white, 0), style=shape.labelup, location=location.belowbar, color=color.new(color.green, 0), size=size.tiny, display=display.none)

p2 = ADX[1] > ADX and vrsi > 60 and vrsi < 65 or ADX[1] < ADX and vrsi > 55 and vrsi < 60
plotshape(p2, title='SCORE 2', text='2', textcolor=color.new(color.white, 0), style=shape.labelup, location=location.belowbar, color=color.new(color.green, 0), size=size.tiny, display=display.none)

p3 = ADX[1] > ADX and vrsi > 65 and vrsi < 70 or ADX[1] < ADX and vrsi > 60 and vrsi < 65
plotshape(p3, title='SCORE 3', text='3', textcolor=color.new(color.white, 0), style=shape.labelup, location=location.belowbar, color=color.new(color.green, 0), size=size.tiny, display=display.none)

p4 = ADX[1] > ADX and vrsi > 70 or ADX[1] < ADX and vrsi > 65 and vrsi < 70
plotshape(p4, title='SCORE 4', text='4', textcolor=color.new(color.white, 0), style=shape.labelup, location=location.belowbar, color=color.new(color.green, 0), size=size.tiny, display=display.none)

p5 = ADX[1] < ADX and vrsi > 70
plotshape(p5, title='SCORE 5', text='5', textcolor=color.new(color.white, 0), style=shape.labelup, location=location.belowbar, color=color.new(color.green, 0), size=size.tiny, display=display.none)

// Table
//var table score_table = table.new(position.bottom_right, 1, 1, frame_color=color.black, frame_width=1, border_width=1)
var int previous_score = na
var int current_score = na

// Variables to track transitions to and from score 5 and -5
var bool score_became_5 = false
var bool score_left_5 = false
var bool score_became_neg5 = false
var bool score_left_neg5 = false

if m5
    current_score := -5
    current_color := color.red
if m4
    current_score := -4
    current_color := color.red
if m3
    current_score := -3
    current_color := color.red
if m2
    current_score := -2
    current_color := color.red
if m1
    current_score := -1
    current_color := color.red
if m0
    current_score := 0
    current_color := color.yellow
if p1
    current_score := 1
    current_color := color.green
if p2
    current_score := 2
    current_color := color.green
if p3
    current_score := 3
    current_color := color.green
if p4
    current_score := 4
    current_color := color.green
if p5
    current_score := 5
    current_color := color.green

text_color = current_color == color.yellow ? color.black : color.white

if not na(current_score)
    table.cell(table_id, 2, 1, str.tostring(previous_score) + ' -> ' + str.tostring(current_score), bgcolor=current_color, text_color=text_color)
    // Check for score transitions to and from 5
    score_became_5 := previous_score != 5 and current_score == 5
    score_left_5 := previous_score == 5 and current_score != 5
    // Check for score transitions to and from -5
    score_became_neg5 := previous_score != -5 and current_score == -5
    score_left_neg5 := previous_score == -5 and current_score != -5
    
    previous_score := current_score
    previous_color := current_color

// Plot line at 0 with color changing according to the score
plot(0, title='Score Line', color=current_color, linewidth=2)

// Plot green circle when score becomes 5 on the 0 line
plotshape(series=score_became_5 ? 0 : na, title='Score Became 5', location=location.absolute, color=color.green, style=shape.circle, size=size.tiny)

// Plot green X when score leaves 5 on the 0 line
plotshape(series=score_left_5 ? 0 : na, title='Score Left 5', location=location.absolute, color=color.green, style=shape.xcross, size=size.tiny)

// Plot red circle when score becomes -5 on the 0 line
plotshape(series=score_became_neg5 ? 0 : na, title='Score Became -5', location=location.absolute, color=color.red, style=shape.circle, size=size.tiny)

// Plot red X when score leaves -5 on the 0 line
plotshape(series=score_left_neg5 ? 0 : na, title='Score Left -5', location=location.absolute, color=color.red, style=shape.xcross, size=size.tiny)
"

help me alalyse this code i want to make it mutitime frame indicaotr