Akshay

Akshay

//@version=5
strategy("EMA Crossover Strategy", overlay=true)

// Define EMAs
ema20 = ta.ema(close, 20)
ema50 = ta.ema(close, 50)

// Define crossover conditions
buySignal = ta.crossover(ema20, ema50)
sellSignal = ta.crossunder(ema20, ema50)

// Entry conditions
longCondition = buySignal and close > ema20 and close > ema50
shortCondition = sellSignal and close < ema20 and close < ema50

// Stop-Loss & Take-Profit (Fixed 1:2 Risk-Reward)
stopLossPips = 30 // Adjust as needed
takeProfitPips = 60

longSL = close - stopLossPips * syminfo.mintick
longTP = close + takeProfitPips * syminfo.mintick

shortSL = close + stopLossPips * syminfo.mintick
shortTP = close - takeProfitPips * syminfo.mintick

// Execute Trades
if longCondition
strategy.entry("Buy", strategy.long)
strategy.exit("Take Profit", from_entry="Buy", limit=longTP, stop=longSL)

if shortCondition
strategy.entry("Sell", strategy.short)
strategy.exit("Take Profit", from_entry="Sell", limit=shortTP, stop=shortSL)

// Plot EMAs
plot(ema20, color=color.blue, linewidth=2, title="20 EMA")
plot(ema50, color=color.red, linewidth=2, title="50 EMA")

// Plot Buy/Sell signals
plotshape(series=longCondition, location=location.belowbar, color=color.green, style=shape.labelup, title="BUY")
plotshape(series=shortCondition, location=location.abovebar, color=color.red, style=shape.labeldown, title="SELL")

Read More

Share:

Latest News