//@version=5
strategy("EMA Crossover", overlay=true)
// Input parameters
ema_fast_length = input.int(5, title="Fast EMA Length")
ema_slow_length = input.int(21, title="Slow EMA Length")
take_profit_percent = input.float(1.0, title="Take Profit (%)", minval=0.1, maxval=4.0, step=0.1) / 100
stop_loss_percent = input.float(2.0, title="Stop Loss (%)", minval=0.1, maxval=4.0, step=0.1) / 100
// Calculate EMAs
ema_fast = ta.ema(close, ema_fast_length)
ema_slow = ta.ema(close, ema_slow_length)
// Plot EMAs
plot(ema_fast, color=color.blue, title="Fast EMA")
plot(ema_slow, color=color.red, title="Slow EMA")
// Crossing condition
long_condition = ta.crossover(ema_fast, ema_slow)
short_condition = ta.crossunder(ema_fast, ema_slow)
// Entry and exit strategy
if (long_condition)
strategy.entry("Buy", strategy.long)
strategy.exit("TP/SL", "Buy", limit=close * (1 + take_profit_percent), stop=close * (1 - stop_loss_percent))
if (short_condition)
strategy.entry("Sell", strategy.short)
strategy.exit("TP/SL", "Sell", limit=close * (1 - take_profit_percent), stop=close * (1 + stop_loss_percent))