Tala

Wait 5 sec.

TalaGoldOANDA:XAUUSDalisarchahi887//@version=6 strategy("XAUUSD EMA + Stochastic Backtest", overlay=true, initial_capital=10000, pyramiding=0, process_orders_on_close=true) // === Moving Averages === ema12 = ta.ema(close, 12) ema48 = ta.ema(close, 48) ema192 = ta.ema(close, 192) // === Stochastic 5,3,2 === k = ta.stoch(close, high, low, 5) smoothK = ta.sma(k, 3) d = ta.sma(smoothK, 2) // === Buy Conditions === buyCondition = ema12 > ema48 and ema48 > ema192 and ema12 > ema12 and ema48 > ema48 and ema192 > ema192 and smoothK > 51 and d > 51 // === Sell Conditions === sellCondition = ema12 < ema48 and ema48 < ema192 and ema12 < ema12 and ema48 < ema48 and ema192 < ema192 and smoothK < 49 and d < 49 // Enter only when conditions first become true buySignal = buyCondition and not buyCondition sellSignal = sellCondition and not sellCondition // === Backtest Period: Oct 12–16, 2026 === startTime = timestamp("12 Oct 2026 00:00 +0330") endTime = timestamp("17 Oct 2026 00:00 +0330") inDateRange = time >= startTime and time < endTime // === Entries === if inDateRange and buySignal strategy.entry("BUY", strategy.long) if inDateRange and sellSignal strategy.entry("SELL", strategy.short) // === Take Profit and Stop Loss === if strategy.position_size > 0 strategy.exit("BUY EXIT", from_entry="BUY", limit=strategy.position_avg_price * 1.10, stop=strategy.position_avg_price * 0.97) if strategy.position_size < 0 strategy.exit("SELL EXIT", from_entry="SELL", limit=strategy.position_avg_price * 0.90, stop=strategy.position_avg_price * 1.03) // === Plot EMAs === plot(ema12, color=color.red, title="EMA 12") plot(ema48, color=color.green, title="EMA 48") plot(ema192, color=color.blue, title="EMA 192") plotshape(buySignal and inDateRange, title="Buy Signal", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small) plotshape(sellSignal and inDateRange, title="Sell Signal", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small)