3-Minute RSI and EMA Crossover Sell Strategy with Exit Conditions and Re-entry
![]()
//@version=5
strategy("3-Minute RSI and EMA Crossover Sell Strategy with Exit Conditions and Re-entry", overlay=true)
// Define timeframes for RSI and EMA
threeMinRSI = request.security(syminfo.tickerid, "3", ta.rsi(close, 3))
// Define EMA on 1-minute timeframe
ema10_1m = ta.ema(close, 10)
ema20_1m = ta.ema(close, 20)
// Define EMA on 3-minute timeframe
threeMinEMA10 = request.security(syminfo.tickerid, "3", ta.ema(close, 10))
threeMinEMA20 = request.security(syminfo.tickerid, "3", ta.ema(close, 20))
ema13 = ta.ema(close, 13)
// Track state of the 3-minute RSI condition
var bool rsi_condition_met = false
var float sell_price = na
var int last_trade_close_time = na
// Check if 3-minute RSI goes above 85
if (threeMinRSI >= 85)
rsi_condition_met := true
// Check for EMA crossover and candle close conditions after RSI condition is met
sell_condition = rsi_condition_met and ta.crossunder(ema10_1m, ema20_1m) and close < ema10_1m and close < ema20_1m
if (sell_condition)
sell_price := close
strategy.entry("Sell", strategy.short)
// Plot "Sell" text on the chart at the crossover point with 20% opacity
label.new(bar_index, low, "Sell", color=color.new(color.red, 80), style=label.style_label_down, textcolor=color.white, size=size.normal)
// Reset the RSI condition to ensure new sequences are checked
rsi_condition_met := false
// Exit Conditions
price_movement = close <= (sell_price - 300)
ema_cross_up_3m = ta.crossover(threeMinEMA10, threeMinEMA20)
if (strategy.position_size < 0) // Checking if the position is short
if (price_movement or ema_cross_up_3m)
strategy.close("Sell")
// Plot "Close" text on the chart with 20% opacity
label.new(bar_index, high, "Close", color=color.new(color.green, 80), style=label.style_label_up, textcolor=color.white, size=size.normal)
// Store the time when the trade was closed
last_trade_close_time := timenow
// Re-entry Condition
min_wait_time = 3 * 60 * 1000 // 3 minutes in milliseconds
time_since_last_close = timenow - last_trade_close_time
// Re-entry if at least 3 minutes have passed and EMA 10 crosses below EMA 20 on the 3-minute timeframe
reentry_condition_3m = ta.crossunder(threeMinEMA10, threeMinEMA20) and time_since_last_close >= min_wait_time
if (reentry_condition_3m)
sell_price := close
strategy.entry("Re-sell", strategy.short)
// Plot "Re-sell" text on the chart with 20% opacity
label.new(bar_index, high, "Re-sell", color=color.new(color.blue, 80), style=label.style_label_down, textcolor=color.white, size=size.normal)
// Plot EMAs for visualization
plot(ema10_1m, title="EMA 10 (1m)", color=color.green, linewidth=2)
plot(ema20_1m, title="EMA 20 (1m)", color=color.orange, linewidth=2)
plot(ema13, title="EMA 13", color=color.white, linewidth=2)
// Comment out the plots for 3-minute EMAs to hide them from the chart
// plot(threeMinEMA10, title="EMA 10 (3m)", color=color.blue, linewidth=2)
// plot(threeMinEMA20, title="EMA 20 (3m)", color=color.red, linewidth=2)