Improve this script for Buy and Sell signal wise as well as Long and Short signal wise, Signals also provide on running candle not on previous candle

//@version=5
strategy("Real-Time Buy/Sell & Long/Short Signals (Current Candle)", overlay=true, pyramiding=0, default_qty_type=strategy.percent_of_equity, default_qty_value=10)

// === Input Parameters ===
length_fast_ema   = input.int(9, title="Fast EMA Length")
length_slow_ema   = input.int(21, title="Slow EMA Length")
length_rsi        = input.int(14, title="RSI Length")
rsi_overbought    = input.int(70, title="RSI Overbought")
rsi_oversold      = input.int(30, title="RSI Oversold")
length_macd_fast  = input.int(12, title="MACD Fast Length")
length_macd_slow  = input.int(26, title="MACD Slow Length")
length_macd_signal= input.int(9, title="MACD Signal Length")
length_adx        = input.int(14, title="ADX Length")
adx_threshold     = input.float(25, title="ADX Threshold for Trend")

// === Indicator Calculations ===
ema_fast   = ta.ema(close, length_fast_ema)
ema_slow   = ta.ema(close, length_slow_ema)
rsi        = ta.rsi(close, length_rsi)
[macd_line, signal_line, _] = ta.macd(close, length_macd_fast, length_macd_slow, length_macd_signal)
[_, _, adx_value] = ta.dmi(length_adx, length_adx)

// === Candlestick Pattern Detection (Current Candle) ===
is_bullish_engulfing = close > open and close[1] < open[1] and (close - open) > 1.5 * (open[1] - close[1])
is_bearish_engulfing = close < open and close[1] > open[1] and (open - close) > 1.5 * (close[1] - open[1])

// === Trend Direction (Current Candle) ===
is_uptrend   = ema_fast > ema_slow
is_downtrend = ema_fast < ema_slow

// === Signal Logic (Current Candle) ===
buy_signal  = (is_uptrend and rsi < rsi_oversold and macd_line > signal_line and adx_value > adx_threshold) or is_bullish_engulfing
sell_signal = (is_downtrend and rsi > rsi_overbought and macd_line < signal_line and adx_value > adx_threshold) or is_bearish_engulfing

long_exit_signal  = rsi > rsi_overbought or macd_line < signal_line or adx_value < adx_threshold
short_exit_signal = rsi < rsi_oversold or macd_line > signal_line or adx_value < adx_threshold

// === Strategy Execution (on current bar, based on current bar's signal) ===
if buy_signal
    strategy.entry("Long", strategy.long)
if sell_signal
    strategy.entry("Short", strategy.short)
if strategy.position_size > 0 and long_exit_signal
    strategy.close("Long")
if strategy.position_size < 0 and short_exit_signal
    strategy.close("Short")

// === Plotting Signals (on current candle) ===
plotshape(buy_signal,  title="Buy Signal",  location=location.belowbar, color=color.green, style=shape.labelup,   text="BUY",  size=size.small)
plotshape(sell_signal, title="Sell Signal", location=location.abovebar, color=color.red,   style=shape.labeldown, text="SELL", size=size.small)

// === Plot EMAs for Visual Context ===
plot(ema_fast, color=color.blue,   title="Fast EMA")
plot(ema_slow, color=color.orange, title="Slow EMA")

// === Plot RSI ===
plot(rsi, color=color.purple, title="RSI")
hline(rsi_overbought, "Overbought", color=color.red)
hline(rsi_oversold, "Oversold", color=color.green)

// === Plot ADX ===
plot(adx_value, color=color.gray, title="ADX")
hline(adx_threshold, "ADX Threshold", color=color.new(color.gray, 50))