Copy all code -
//@version=5
strategy(title="EMA Crossover Strategy", overlay=true)
// Input Parameters
ema13_length = input.int(13, title="13 EMA Length")
ema50_length = input.int(50, title="50 EMA Length")
// Define EMA's
ema13 = ta.ema(close, ema13_length)
ema50 = ta.ema(close, ema50_length)
// Define Strategy Entry and Exit Conditions
crossover(x, y) => x[1] < y[1] and x > y
buy_signal = crossover(close, ema50) and ema13 < ema50
sell_signal = crossover(ema50, close) and ema13 > ema50
// Submit Buy and Sell Orders
if buy_signal
strategy.entry("Buy", strategy.long)
if sell_signal
strategy.entry("Sell", strategy.short)
// Plot EMAs and Strategy Entry and Exit Points
plot(ema13, title="13 EMA", color=color.blue)
plot(ema50, title="50 EMA", color=color.red)
plotshape(buy_signal, title="Buy Signal", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)
plotshape(sell_signal, title="Sell Signal", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small)
// Add Background Color Between EMAs
ema13_line = plot(ema13, color=color.blue, title="13 EMA")
ema50_line = plot(ema50, color=color.red, title="50 EMA")
fill(ema13_line, ema50_line, color=#D0D0D0, transp=70)