Recreate this Statergy: //@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)

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

// Calculate the percentage change from the previous close to the current close
priceChangePercent = (close - close[1]) / close[1] * 100
minPriceMovement = 0.30
priceMovementCondition = math.abs(priceChangePercent) >= minPriceMovement

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

// Optional: 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)

// Optional: 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

// Plot buy and sell signals with price movement condition
plotshape(series=buySignalWithRSI and priceMovementCondition, location=location.belowbar, color=color.green, style=shape.labelup, title="Buy Signal with RSI and Price Movement", text="BUY")
plotshape(series=sellSignalWithRSI and priceMovementCondition, location=location.abovebar, color=color.red, style=shape.labeldown, title="Sell Signal with RSI and Price Movement", text="SELL")

// Execute buy and sell orders only if the price movement condition is met
if (buySignalWithRSI and priceMovementCondition)
    // Calculate dynamic position size based on ATR (Risk management)
    positionSize = strategy.equity * 0.01 / (atrValue * atrMultiplier)
    strategy.entry("Buy", strategy.long, qty=positionSize)

if (sellSignalWithRSI and priceMovementCondition)
    // Calculate dynamic position size for short orders
    positionSize = strategy.equity * 0.01 / (atrValue * atrMultiplier)
    strategy.entry("Sell", strategy.short, qty=positionSize)

// Trailing stop loss for higher potential profit
trailOffset = input.float(0.5, title="Trail Offset (ATR)", minval=0.1) // in ATR
trailPoints = atrValue * trailOffset

// Optional: Trailing Stop Loss
strategy.exit("Exit Buy", from_entry="Buy", trail_price=close - trailPoints, trail_offset=trailPoints)
strategy.exit("Exit Sell", from_entry="Sell", trail_price=close + trailPoints, trail_offset=trailPoints)

// 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
buySignalWithTrend = buySignalWithRSI and priceMovementCondition and higherTimeframeTrend == 1
sellSignalWithTrend = sellSignalWithRSI and priceMovementCondition and higherTimeframeTrend == -1

// Plot final buy/sell signals with trend filter
plotshape(series=buySignalWithTrend, location=location.belowbar, color=color.green, style=shape.labelup, title="Buy Signal with Trend", text="BUY")
plotshape(series=sellSignalWithTrend, location=location.abovebar, color=color.red, 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)

// 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 i = 1 to takeProfitLevels
    takeProfitPrice = close * (1 + takeProfitStep * i / 100)
    strategy.exit("Take Profit " + str.tostring(i), from_entry="Buy", limit=takeProfitPrice)

for i = 1 to takeProfitLevels
    takeProfitPrice = close * (1 - takeProfitStep * i / 100)
    strategy.exit("Take Profit " + str.tostring(i), from_entry="Sell", limit=takeProfitPrice)