Read this Code and Understand it how it work and then write completey in new format : //@version=5
strategy("Advanced VWAP Strategy with Enhanced Features", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)

// Input parameters
length = input.int(50, title="VWAP Length", minval=1)
src = close
vwapsession = ta.vwap(close)

// Dynamic position size based on ATR
atrLength = input.int(14, title="ATR Length")
atrMultiplier = input.float(1.5, title="ATR Multiplier for Position Sizing")
atrValue = ta.atr(atrLength)

// Price movement condition
minPriceMovement = 0.30
priceChangePercent = (close - close[1]) / close[1] * 100
priceMovementCondition = math.abs(priceChangePercent) >= minPriceMovement

// Plot VWAP
plot(vwapsession, color=color.blue, linewidth=2, title="VWAP")

// RSI filter for confirmation
rsiPeriod = input.int(14, title="RSI Period")
rsiValue = ta.rsi(close, rsiPeriod)
rsiOverbought = 70
rsiOversold = 30
plot(rsiValue, title="RSI", color=color.orange)
hline(rsiOverbought, title="RSI Overbought", color=color.red)
hline(rsiOversold, title="RSI Oversold", color=color.green)

// Buy and Sell Signals
buySignal = ta.crossover(close, vwapsession)
sellSignal = ta.crossunder(close, vwapsession)

// Only take buy when RSI is not overbought and sell when RSI is not oversold
buySignalWithRSI = buySignal and rsiValue < rsiOverbought
sellSignalWithRSI = sellSignal and rsiValue > rsiOversold

// Trend Strength Filter using ADX
adxPeriod = input.int(14, title="ADX Period")
adxSmoothing = input.int(14, title="ADX Smoothing")
minADX = input.float(25.0, title="Minimum ADX for Trend Filter", minval=1.0)

// Use ta.dmi to get ADX value
[plusDI, minusDI, adxValue] = ta.dmi(adxPeriod, adxSmoothing)
trendCondition = adxValue >= minADX
plot(adxValue, color=color.purple, title="ADX")
hline(minADX, title="Minimum ADX Threshold", color=color.gray)

// Multi-timeframe trend filter (use higher timeframe to confirm trend)
higherTimeframe = input.timeframe("240", title="Higher Timeframe for Trend Filter")
higherTimeframeVWAP = request.security(syminfo.tickerid, higherTimeframe, ta.vwap(close))
higherTimeframeTrend = close > higherTimeframeVWAP ? 1 : -1

// Filter buy and sell signals based on higher timeframe trend and ADX
buySignalWithTrend = buySignalWithRSI and priceMovementCondition and higherTimeframeTrend == 1 and trendCondition
sellSignalWithTrend = sellSignalWithRSI and priceMovementCondition and higherTimeframeTrend == -1 and trendCondition

// Plot final buy/sell signals with trend filter
plotshape(series=buySignalWithTrend, location=location.belowbar, color=color.lime, style=shape.labelup, title="Buy Signal with Trend", text="BUY")
plotshape(series=sellSignalWithTrend, location=location.abovebar, color=color.maroon, style=shape.labeldown, title="Sell Signal with Trend", text="SELL")

// Execute final orders based on trend confirmation
if (buySignalWithTrend)
    strategy.entry("Buy", strategy.long)

if (sellSignalWithTrend)
    strategy.entry("Sell", strategy.short)

// Trailing Stop Loss configuration
trailOffset = input.float(0.5, title="Trail Offset (ATR)", minval=0.1) // in ATR
trailPoints = atrValue * trailOffset

// Trailing Stop Loss for Buy and Sell positions
strategy.exit("Exit Buy", from_entry="Buy", trail_points=trailPoints)
strategy.exit("Exit Sell", from_entry="Sell", trail_points=trailPoints)

// Optional: Take profit scaling
takeProfitLevels = input.int(3, title="Take Profit Levels", minval=1)
takeProfitStep = input.float(0.5, title="Take Profit Step (%)")

// Set partial take profits at multiple levels for Buy positions
if (strategy.position_size > 0 and strategy.position_side == strategy.long)
    // Begin 'for' loop inside the 'if' block
    for i = 1 to takeProfitLevels
        takeProfitPriceBuy = strategy.position_avg_price * (1 + takeProfitStep * i / 100)
        strategy.exit("Take Profit Buy " + str.tostring(i), from_entry="Buy", limit=takeProfitPriceBuy, qty_percent=100 / takeProfitLevels)

// Set partial take profits at multiple levels for Sell positions
if (strategy.position_size < 0 and strategy.position_side == strategy.short)
    // Begin 'for' loop inside the 'if' block
    for i = 1 to takeProfitLevels
        takeProfitPriceSell = strategy.position_avg_price * (1 - takeProfitStep * i / 100)
        strategy.exit("Take Profit Sell " + str.tostring(i), from_entry="Sell", limit=takeProfitPriceSell, qty_percent=100 / takeProfitLevels)