EMA MACD RSI Combined Strategy Pinescript
These strategies are for demonstration purposes only and are not intended for actual trading. Saanmi Capital is not responsible for any profit or loss arising from the use of these sample strategies.
//@version=5
strategy(“Combining 3 indicator Strategy”, overlay=true)
fast_ema_L = input.int(defval=9, title=’Fast EMA Length’, group=’EMA’)
slow_ema_L = input.int(defval=21, title=’Slow EMA Length’, group=’EMA’)
fast_macd_L = input.int(defval=12, title=’Fast MACD Length’, group=’MACD’)
slow_macd_L = input.int(defval=26, title=’Slow MACD Length’, group=’MACD’)
siglen = input.int(defval=9, title=’Signal Smoothing MACD’, group=’MACD’)
rsi_L = input.int(defval=7, title=’RSI Length’, group=’RSI’)
rsi_val_gt = input.int(defval=60, title=’RSI greater than’, group=’RSI’)
rsi_val_lt = input.int(defval=40, title=’RSI lesser than’, group=’RSI’)
target_points = input.int(100, title=”Target Points”)
stop_loss_points = input.int(50, 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’, color=color.blue)
plot(signalLine, title=’MACD Signal Line’, color=color.orange)
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)