//@version=5 strategy("XAUUSD Scalping Candlestick Strategy", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10) // --- Inputs --- emaPeriod = input.int(50, title="EMA Trend Filter Period") atrPeriod = input.int(14, title="ATR Period") atrMultiplierSL = input.float(1.5, title="ATR Stop Loss Multiplier") riskReward = input.float(1.5, title="Risk/Reward Ratio (TP Multiplier)") // --- Indicators --- emaValue = ta.ema(close, emaPeriod) atrValue = ta.atr(atrPeriod) // --- Price Action & Candlestick Analysis --- barRange = high - low bodyRange = math.abs(close - open) // Pin Bar Detection (Rejection Candle) bullishPin = (barRange > 0) and ((math.min(open, close) - low) >= 0.55 * barRange) and ((high - math.max(open, close)) <= 0.25 * barRange) bearishPin = (barRange > 0) and ((high - math.max(open, close)) >= 0.55 * barRange) and ((math.min(open, close) - low) <= 0.25 * barRange) // Engulfing Pattern Detection bullishEngulfing = (close[1] < open[1]) and (close > open) and (close >= open[1]) and (open <= close[1]) bearishEngulfing = (close[1] > open[1]) and (close < open) and (close <= open[1]) and (open >= close[1]) // --- Strategy Entry Rules --- longCondition = (close > emaValue) and (bullishPin or bullishEngulfing) shortCondition = (close < emaValue) and (bearishPin or bearishEngulfing) // --- Strategy Execution --- if (longCondition and strategy.position_size == 0) slDistance = atrValue * atrMultiplierSL slPrice = close - slDistance tpPrice = close + (slDistance * riskReward) strategy.entry("Long", strategy.long) strategy.exit("Exit Long", "Long", stop=slPrice, limit=tpPrice) if (shortCondition and strategy.position_size == 0) slDistance = atrValue * atrMultiplierSL slPrice = close + slDistance tpPrice = close - (slDistance * riskReward) strategy.entry("Short", strategy.short) strategy.exit("Exit Short", "Short", stop=slPrice, limit=tpPrice) // --- Plotting --- plot(emaValue, title="50 EMA Trend Filter", color=color.blue, linewidth=2) plotshape(bullishPin or bullishEngulfing, title="Buy Signal", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small) plotshape(bearishPin or bearishEngulfing, title="Sell Signal", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small)