Recreate this Statergy: //@version=5 strategy("Advanced VWAP Strategy with Enhanced…
- User
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
- Assistant