Can you look at this code and optimize it better for pinescript 6. I want to make it as optimal as possible and visually easy to trade Micro es mini 500 futures, with the best buy and sell signals I usually use 15 minute time interval

//@version=5
indicator("Adaptive Trend Following Indicator with Dashboard", overlay=true, max_labels_count=500)

// ————— Input Parameters ————— //
show_EMAs = input.bool(true, title="Show EMAs")
fast_EMA_length = input.int(20, minval=1, title="Fast EMA Length")
slow_EMA_length = input.int(50, minval=1, title="Slow EMA Length")
smoothing_length = input.int(5, minval=1, title="Smoothing Length for EMAs")

show_DMI = input.bool(true, title="Show DMI and ADX")
DMI_length = input.int(14, minval=1, title="DMI Length")
ADX_threshold = input.float(25.0, minval=1.0, title="ADX Threshold")

show_RSI = input.bool(true, title="Show RSI")
RSI_length = input.int(14, title="RSI Length")
RSI_overbought = input.float(70.0, title="RSI Overbought Level")
RSI_oversold = input.float(30.0, title="RSI Oversold Level")

show_Volume = input.bool(true, title="Show Volume Analysis")
volume_MA_length = input.int(20, minval=1, title="Volume MA Length")

show_SupportResistance = input.bool(true, title="Show Support and Resistance Zones")

show_Structure = input.bool(true, title="Show Structure Breakouts/Breakdowns")

show_Signals = input.bool(true, title="Show Buy/Sell Signals")
signal_gap = input.int(1, minval=1, title="Signal Label Gap")

// Dashboard Options
show_Dashboard = input.bool(true, title="Show Trend Dashboard")

// ————— Calculations ————— //

// — EMAs — //
fastEMA = ta.ema(close, fast_EMA_length)
slowEMA = ta.ema(close, slow_EMA_length)

// Smoothed EMAs
smoothedFastEMA = ta.ema(fastEMA, smoothing_length)
smoothedSlowEMA = ta.ema(slowEMA, smoothing_length)

// — Directional Movement Index (DMI) and Average Directional Index (ADX) — //
float plusDM = na
float minusDM = na

upMove = ta.change(high)
downMove = -ta.change(low)
plusDM := (upMove > downMove and upMove > 0) ? upMove : 0.0
minusDM := (downMove > upMove and downMove > 0) ? downMove : 0.0

trueRange = ta.tr(true)
sumPlusDM = ta.rma(plusDM, DMI_length)
sumMinusDM = ta.rma(minusDM, DMI_length)
sumTR = ta.rma(trueRange, DMI_length)

plusDI = (sumTR != 0) ? 100 * (sumPlusDM / sumTR) : 0.0
minusDI = (sumTR != 0) ? 100 * (sumMinusDM / sumTR) : 0.0
DX = ((plusDI + minusDI) != 0) ? 100 * math.abs(plusDI - minusDI) / (plusDI + minusDI) : 0.0
ADX = ta.rma(DX, DMI_length)

// — RSI — //
rsiValue = ta.rsi(close, RSI_length)

// — MACD Histogram — //
macd_fast_length = 20
macd_slow_length = 50
macd_signal_length = 9
macdLine = ta.ema(close, macd_fast_length) - ta.ema(close, macd_slow_length)
signalLine = ta.sma(macdLine, macd_signal_length)
macdHist = macdLine - signalLine

// — Volume Analysis — //
volumeMA = ta.sma(volume, volume_MA_length)
highVolume = volume > volumeMA

// — Support and Resistance — //
pivot_high = ta.pivothigh(high, 5, 5)
pivot_low = ta.pivotlow(low, 5, 5)
resistance = pivot_high ? high[5] : na
support = pivot_low ? low[5] : na

var float resistance_level = na
var float support_level = na

if not na(resistance)
    resistance_level := resistance
else
    resistance_level := resistance_level[1]

if not na(support)
    support_level := support
else
    support_level := support_level[1]

// — Structure Breakouts/Breakdowns — //
breakout = close > nz(resistance_level[1]) ? 1 : 0
breakdown = close < nz(support_level[1]) ? 1 : 0

// — Signal Conditions — //
// Long Condition: Positive DI > Negative DI and smoothedFastEMA > smoothedSlowEMA
bullTrend = plusDI > minusDI and smoothedFastEMA > smoothedSlowEMA
// Short Condition: Negative DI > Positive DI and smoothedFastEMA < smoothedSlowEMA
bearTrend = minusDI > plusDI and smoothedFastEMA < smoothedSlowEMA

buySignal = bullTrend
sellSignal = bearTrend

// ————— Plotting ————— //

// — Plot EMAs — //
plot(show_EMAs ? smoothedFastEMA : na, title="Smoothed Fast EMA", color=color.blue, linewidth=2)
plot(show_EMAs ? smoothedSlowEMA : na, title="Smoothed Slow EMA", color=color.orange, linewidth=2)

// — Plot DMI and ADX — //
plot(show_DMI ? ADX : na, title="ADX", color=color.purple, linewidth=2)
plot(show_DMI ? plusDI : na, title="+DI", color=color.green)
plot(show_DMI ? minusDI : na, title="-DI", color=color.red)
hline_ADX = show_DMI ? ADX_threshold : na
hline(hline_ADX, title="ADX Threshold", color=color.gray, linestyle=hline.style_dotted)

// — Plot RSI — //
plot(show_RSI ? rsiValue : na, title="RSI", color=color.aqua)
hline_RSI_overbought = show_RSI ? RSI_overbought : na
hline(hline_RSI_overbought, title="RSI Overbought", color=color.red, linestyle=hline.style_dashed)
hline_RSI_oversold = show_RSI ? RSI_oversold : na
hline(hline_RSI_oversold, title="RSI Oversold", color=color.green, linestyle=hline.style_dashed)

// — Plot Volume MA — //
plot(show_Volume ? volumeMA : na, title="Volume MA", color=color.purple)

// — Plot Support and Resistance Zones — //
if show_SupportResistance and not na(resistance_level)
    line.new(bar_index - 5, resistance_level, bar_index, resistance_level, extend=extend.right, color=color.red, style=line.style_dotted, width=2)
if show_SupportResistance and not na(support_level)
    line.new(bar_index - 5, support_level, bar_index, support_level, extend=extend.right, color=color.green, style=line.style_dotted, width=2)

// — Plot Structure Breakouts/Breakdowns — //
plotshape(show_Structure and breakout, title="Breakout", style=shape.labelup, location=location.belowbar, color=color.new(color.green, 0), text="Breakout", textcolor=color.white, offset=-signal_gap)
plotshape(show_Structure and breakdown, title="Breakdown", style=shape.labeldown, location=location.abovebar, color=color.new(color.red, 0), text="Breakdown", textcolor=color.white, offset=-signal_gap)

// — Plot Buy and Sell Signals — //
plotshape(show_Signals and buySignal, title="Buy Signal", style=shape.triangleup, location=location.belowbar, color=color.new(color.lime, 0), size=size.large, text="Buy", textcolor=color.white, offset=-signal_gap)
plotshape(show_Signals and sellSignal, title="Sell Signal", style=shape.triangledown, location=location.abovebar, color=color.new(color.maroon, 0), size=size.large, text="Sell", textcolor=color.white, offset=-signal_gap)

// ————— Dashboard ————— //
var table dashboard = na
if show_Dashboard
    // Define Bullish, Bearish, Neutral colors
    bullishColor = color.lime
    bearishColor = color.red
    neutralColor = color.gray

    // EMA Trend
    emaTrend = smoothedFastEMA > smoothedSlowEMA ? "Bullish" : smoothedFastEMA < smoothedSlowEMA ? "Bearish" : "Neutral"
    emaColor = smoothedFastEMA > smoothedSlowEMA ? bullishColor : smoothedFastEMA < smoothedSlowEMA ? bearishColor : neutralColor

    // RSI Trend
    rsiTrend = rsiValue > 50 ? "Bullish" : rsiValue < 50 ? "Bearish" : "Neutral"
    rsiColor = rsiValue > 50 ? bullishColor : rsiValue < 50 ? bearishColor : neutralColor

    // MACD Histogram Trend
    macdTrend = macdHist > 0 ? "Bullish" : macdHist < 0 ? "Bearish" : "Neutral"
    macdColor = macdHist > 0 ? bullishColor : macdHist < 0 ? bearishColor : neutralColor

    // ADX Trend Strength
    adxTrend = ADX > ADX_threshold ? "Trending" : "Ranging"
    adxColor = ADX > ADX_threshold ? bullishColor : neutralColor

    // Volume Analysis
    volumeTrend = highVolume ? "High Volume" : "Low Volume"
    volumeColor = highVolume ? bullishColor : neutralColor

    // Create the dashboard table
    if barstate.isfirst
        dashboard := table.new(position.top_center, 5, 1, border_width=1)

    // Update the dashboard on each bar
    table.cell(dashboard, 0, 0, "EMA Trend: " + emaTrend, text_color=color.white, text_size=size.small, bgcolor=emaColor)
    table.cell(dashboard, 1, 0, "RSI Trend: " + rsiTrend, text_color=color.white, text_size=size.small, bgcolor=rsiColor)
    table.cell(dashboard, 2, 0, "MACD Trend: " + macdTrend, text_color=color.white, text_size=size.small, bgcolor=macdColor)
    table.cell(dashboard, 3, 0, "ADX: " + adxTrend, text_color=color.white, text_size=size.small, bgcolor=adxColor)
    table.cell(dashboard, 4, 0, "Volume: " + volumeTrend, text_color=color.white, text_size=size.small, bgcolor=volumeColor)