version 2; strategy "XAUUSD M1 Dynamic" { symbol = "XAUUSD"; timeframe = M1; input int fastPeriod = 9 min 2 max 100; input int slowPeriod = 21 min 3 max 300; input int atrPeriod = 14 min 2 max 100; input float atrMultiplier = 1.8 min 1.0 max 10.0; input float volatilityMultiplier = 1.5 min 1.01 max 5.0; input float rewardRisk = 1.8 min 1.0 max 10.0; input float minimumAdx = 18.0 min 1.0 max 60.0; input bool useSessionFilter = true; let fastTrend = ema(close, fastPeriod); let slowTrend = ema(close, slowPeriod); let m5Trend = higher_ema(M5, close, slowPeriod); let strength = adx(high, low, close, atrPeriod); let positiveDirection = plus_di(high, low, close, atrPeriod); let negativeDirection = minus_di(high, low, close, atrPeriod); let sessionAllowed = !useSessionFilter || in_session("LONDON"); let buySignal = fastTrend > slowTrend && close > fastTrend && close > m5Trend && strength >= minimumAdx && positiveDirection > negativeDirection && volatility_normal(atrPeriod, volatilityMultiplier) && sessionAllowed; let sellSignal = fastTrend < slowTrend && close < fastTrend && close < m5Trend && strength >= minimumAdx && negativeDirection > positiveDirection && volatility_normal(atrPeriod, volatilityMultiplier) && sessionAllowed; buy { when = buySignal; entry = ask; stop = atr_stop(atrMultiplier); target = rr(rewardRisk); } sell { when = sellSignal; entry = bid; stop = atr_stop(atrMultiplier); target = rr(rewardRisk); } plot(fastTrend, color.green); plot(slowTrend, color.orange); }