Skip to main content

EMA MACD RSI Combined Strategy

Discover our EMA MACD RSI Combined Strategy PineScript template, designed for traders seeking to use multiple indicators. Easily backtest on TradingView and live execute this template on AlgoTest. Adjusting inputs like Lengths of individual indicators, RSI oversold and overbought level, target points, and stop loss points to suit your trading preferences.

strategy("Combining 3 indicator Strategy", overlay=true)

fast_ema_L =, title='Fast EMA Length', group='EMA')
slow_ema_L =, title='Slow EMA Length', group='EMA')

fast_macd_L =, title='Fast MACD Length', group='MACD')
slow_macd_L =, title='Slow MACD Length', group='MACD')
siglen =, title='Signal Smoothing MACD', group='MACD')

rsi_L =, title='RSI Length', group='RSI')
rsi_val_gt =, title='RSI greater than', group='RSI')
rsi_val_lt =, title='RSI lesser than', group='RSI')

target_points =, title="Target Points")
stop_loss_points =, title="Stop Loss Points")

fast_ema = ta.ema(close, fast_ema_L)
slow_ema = ta.ema(close, slow_ema_L)

[macdLine, signalLine, histLine] = ta.macd(close, fast_macd_L, slow_macd_L, siglen)

rsi = ta.rsi(close, rsi_L)

long_condition = ta.crossover(fast_ema, slow_ema) and signalLine > macdLine and rsi > rsi_val_gt
short_condition = ta.crossunder(fast_ema, slow_ema) and signalLine < macdLine and rsi < rsi_val_lt

plot(macdLine, title='MACD Line',
plot(signalLine, title='MACD Signal Line',

plot(fast_ema, title='Fast EMA', color=color.aqua)
plot(slow_ema, title='Slow EMA', color=color.yellow)

plot(rsi, title='RSI', color=color.lime)

// Strategy entry and exit
if long_condition
strategy.entry("Long", strategy.long)
if short_condition
strategy.entry("Short", strategy.short)

// Calculate target and stop loss levels
long_target = strategy.position_avg_price + target_points
long_stop_loss = strategy.position_avg_price - stop_loss_points
short_target = strategy.position_avg_price - target_points
short_stop_loss = strategy.position_avg_price + stop_loss_points

// Strategy exit
strategy.exit("Long Exit", "Long", limit=long_target, stop=long_stop_loss)
strategy.exit("Short Exit", "Short", limit=short_target, stop=short_stop_loss)