OPEN-SOURCE SCRIPT
XAUUSD D1 Swing Signal + SL/TP

//version=5
indicator("XAUUSD D1 Swing Signal + SL/TP", overlay=true)
// === INPUTS ===
rsiPeriod = input(14, "RSI Period")
overbought = input(70, "Overbought Level")
oversold = input(30, "Oversold Level")
emaPeriod = input(200, "EMA Period")
tpMultiplier = input.float(3.0, "Take-Profit Multiplier", step=0.1) // Slightly wider TP for D1
slMultiplier = input.float(1.5, "Stop-Loss Multiplier", step=0.1) // Slightly wider SL for D1
// === CALCULATIONS ===
rsi = ta.rsi(close, rsiPeriod)
ema200 = ta.ema(close, emaPeriod)
atr = ta.atr(14) // D1 ATR handles daily volatility
// === SIGNAL CONDITIONS ===
longSignal = ta.crossover(rsi, oversold) and close > ema200
shortSignal = ta.crossunder(rsi, overbought) and close < ema200
// === ENTRY PRICES ===
entryPriceLong = close
entryPriceShort = close
// === SL/TP LEVELS ===
slLong = entryPriceLong - atr * slMultiplier
tpLong = entryPriceLong + atr * tpMultiplier
slShort = entryPriceShort + atr * slMultiplier
tpShort = entryPriceShort - atr * tpMultiplier
// === PLOT SIGNALS ===
plotshape(longSignal, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(shortSignal, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")
// === PLOT SL/TP ZONES ===
plot(longSignal ? tpLong : na, title="TP Long", style=plot.style_linebr, color=color.green)
plot(longSignal ? slLong : na, title="SL Long", style=plot.style_linebr, color=color.red)
plot(shortSignal ? tpShort : na, title="TP Short", style=plot.style_linebr, color=color.green)
plot(shortSignal ? slShort : na, title="SL Short", style=plot.style_linebr, color=color.red)
// === ALERT CONDITIONS ===
alertcondition(longSignal, title="Buy Alert", message="📈 XAUUSD D1 BUY SIGNAL\nEntry: {{close}}\nTP: {{plot_0}}\nSL: {{plot_1}}")
alertcondition(shortSignal, title="Sell Alert", message="📉 XAUUSD D1 SELL SIGNAL\nEntry: {{close}}\nTP: {{plot_2}}\nSL: {{plot_3}}")
indicator("XAUUSD D1 Swing Signal + SL/TP", overlay=true)
// === INPUTS ===
rsiPeriod = input(14, "RSI Period")
overbought = input(70, "Overbought Level")
oversold = input(30, "Oversold Level")
emaPeriod = input(200, "EMA Period")
tpMultiplier = input.float(3.0, "Take-Profit Multiplier", step=0.1) // Slightly wider TP for D1
slMultiplier = input.float(1.5, "Stop-Loss Multiplier", step=0.1) // Slightly wider SL for D1
// === CALCULATIONS ===
rsi = ta.rsi(close, rsiPeriod)
ema200 = ta.ema(close, emaPeriod)
atr = ta.atr(14) // D1 ATR handles daily volatility
// === SIGNAL CONDITIONS ===
longSignal = ta.crossover(rsi, oversold) and close > ema200
shortSignal = ta.crossunder(rsi, overbought) and close < ema200
// === ENTRY PRICES ===
entryPriceLong = close
entryPriceShort = close
// === SL/TP LEVELS ===
slLong = entryPriceLong - atr * slMultiplier
tpLong = entryPriceLong + atr * tpMultiplier
slShort = entryPriceShort + atr * slMultiplier
tpShort = entryPriceShort - atr * tpMultiplier
// === PLOT SIGNALS ===
plotshape(longSignal, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(shortSignal, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")
// === PLOT SL/TP ZONES ===
plot(longSignal ? tpLong : na, title="TP Long", style=plot.style_linebr, color=color.green)
plot(longSignal ? slLong : na, title="SL Long", style=plot.style_linebr, color=color.red)
plot(shortSignal ? tpShort : na, title="TP Short", style=plot.style_linebr, color=color.green)
plot(shortSignal ? slShort : na, title="SL Short", style=plot.style_linebr, color=color.red)
// === ALERT CONDITIONS ===
alertcondition(longSignal, title="Buy Alert", message="📈 XAUUSD D1 BUY SIGNAL\nEntry: {{close}}\nTP: {{plot_0}}\nSL: {{plot_1}}")
alertcondition(shortSignal, title="Sell Alert", message="📉 XAUUSD D1 SELL SIGNAL\nEntry: {{close}}\nTP: {{plot_2}}\nSL: {{plot_3}}")
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.