//@version=5
indicator(title='SuperTrend + MACD + EMA', overlay=true)
//EMA
fast_ema = ta.ema(close, 9)
slow_ema = ta.ema(close, 18)
plot(series=fast_ema, title='Fast EMA', color=#00FFFF, linewidth=1)
plot(series=slow_ema, title='Slow EMA', color=#FF00FF, linewidth=1)
//MACD
fastInput = 12
slowInput = 26
[macdLine, signalLine, histLine] = ta.macd(close, fastInput, slowInput, 9)
//Supertrend
atrPeriod = 10
factor = 3
[supertrend, direction] = ta.supertrend(factor, atrPeriod)
linecolor = direction < 0 ? #00ff00 : #ff0000
plot(series=supertrend, title='Supertrend', color=linecolor, linewidth=1)
// Conditions
long_condition = barstate.isconfirmed and
fast_ema > slow_ema and
macdLine > signalLine and
close > supertrend
short_condition = barstate.isconfirmed and
fast_ema < slow_ema and
macdLine < signalLine and
close < supertrend
// Function to Remove Excessive Signals
exrem(condition_1, condition_2) =>
var entry_signal = 0
entry_signal := condition_1 ? 1 : condition_2 ? -1 : entry_signal[1]
entry = entry_signal != entry_signal[1]
buy = entry and entry_signal == 1
sell = entry and entry_signal == -1
[buy, sell]
// Signals
[long_signal, short_signal] = exrem(long_condition, short_condition)
// Plot
plotshape(long_signal, style=shape.triangleup, color=#00FF00, text='BUY', textcolor=#FFFFFF, editable=false, location=location.belowbar, size=size.small)
plotshape(short_signal, style=shape.triangledown, color=#FF0000, text='SELL', textcolor=#FFFFFF, editable=false, location=location.abovebar, size=size.small)