//version=5
indicator(“EMA 12 Cross and Close with Red Candle Strategy”, overlay=true)
// Calculate 12-period EMA
ema12 = ta.ema(close, 12)
// Plot the EMA
plot(ema12, title=”EMA 12″, color=color.blue, linewidth=2)
// Condition 1: Price crosses above EMA 12
priceCrossUp = ta.crossover(close, ema12)
// Condition 2: Red candle (open > close) that does not touch the EMA
redCandleNoTouch = (open > close) and (low > ema12) and (high > ema12)
// Condition 3: A red candle crosses and closes below EMA 12
redCandleCrossDown = (open > close) and ta.crossunder(close, ema12)
// Combine conditions
entryCondition = priceCrossUp and redCandleNoTouch and redCandleCrossDown
// Strategy entry on the condition
if (entryCondition)
strategy.entry(“Sell”, strategy.short)
// Optional: Exit strategy (you can adjust this based on your risk management)
strategy.exit(“Exit Sell”, “Sell”, stop=close * 1.02, limit=close * 0.98)