//@version=5
indicator("Smart Trade Pro Advanced", shorttitle="STPA", overlay=true)
// --- Inputs ---
fastEMALength = input.int(10, "Fast EMA Length", minval=1)
slowEMALength = input.int(20, "Slow EMA Length", minval=1)
rsiLength = input.int(14, "RSI Length", minval=1)
rsiOverbought = input.int(70, "RSI Overbought Level", minval=50, maxval=100)
rsiOversold = input.int(30, "RSI Oversold Level", minval=0, maxval=50)
slPercent = input.float(0.1, "Stop Loss %", minval=0.1, step=0.1)
targetPercent = input.float(0.3, "Target %", minval=0.1, step=0.1)
// --- EMA Calculation ---
fastEMA = ta.ema(close, fastEMALength)
slowEMA = ta.ema(close, slowEMALength)
// --- RSI Calculation for Confirmation ---
rsiValue = ta.rsi(close, rsiLength)
// --- Buy/Sell Signals with RSI Filter ---
buyCondition = ta.crossover(fastEMA, slowEMA) and rsiValue < rsiOverbought
sellCondition = ta.crossunder(fastEMA, slowEMA) and rsiValue > rsiOversold
// --- Stop Loss and Target Calculation ---
var float buySL = na
var float buyTarget = na
var float sellSL = na
var float sellTarget = na
if buyCondition
buySL := close * (1 - slPercent / 100)
buyTarget := close * (1 + targetPercent / 100)
if sellCondition
sellSL := close * (1 + slPercent / 100)
sellTarget := close * (1 - targetPercent / 100)
// --- Signal Persistence ---
var int trend = 0
if buyCondition
trend := 1
else if sellCondition
trend := -1
else
trend := 0
// --- Plotting Signals (Text Labels for Entry) ---
plotshape(buyCondition, style=shape.labelup, location=location.belowbar,
color=color.rgb(0, 255, 0), size=size.normal, text="Long", textcolor=color.white)
plotshape(sellCondition, style=shape.labeldown, location=location.abovebar,
color=color.rgb(255, 0, 0), size=size.normal, text="Short", textcolor=color.white)
// --- Plotting Stop Loss and Target Lines ---
plot(trend == 1 ? buySL : na, "Buy SL", color=color.red, style=plot.style_cross)
plot(trend == 1 ? buyTarget : na, "Buy Target", color=color.green,
style=plot.style_cross)
plot(trend == -1 ? sellSL : na, "Sell SL", color=color.red, style=plot.style_cross)
plot(trend == -1 ? sellTarget : na, "Sell Target", color=color.green,
style=plot.style_cross)
// --- Adding Text Labels for SL and Target using label.new() ---
if buyCondition
label.new(bar_index, buySL, "Stoploss", color=color.red, textcolor=color.white,
style=label.style_label_up, size=size.tiny)
label.new(bar_index, buyTarget, "Target", color=color.green,
textcolor=color.white, style=label.style_label_down, size=size.tiny)
if sellCondition
label.new(bar_index, sellSL, "Stoploss", color=color.red,
textcolor=color.white, style=label.style_label_down, size=size.tiny)
label.new(bar_index, sellTarget, "Target", color=color.green,
textcolor=color.white, style=label.style_label_up, size=size.tiny)
// --- Alerts ---
alertcondition(buyCondition, "Smart Trade Long Entry", "Smart Trade Long Entry with
SL and Target")
alertcondition(sellCondition, "Smart Trade Short Entry", "Smart Trade Short Entry
with SL and Target")