I have similiar strategies to plot only MACD buy signals on chart when SMA50 above SMA200. Unfortunately, it prompted me error:
"line 31: Mismatched input 'MACD_buy' expecting 'end of line without line continuation'
This is my code:
//@version=4
study("Testing MACD Strategy", overlay=true)
fastLength = input(12)
slowlength = input(26)
MACDLength = input(9)
MACD = ema(close, fastLength) - ema(close, slowlength)
aMACD = ema(MACD, MACDLength)
delta = MACD - aMACD
// EMA or SMA input //
len50 = input(50, minval=1, title="SMA 50")
len200 = input(200, minval=1, title="SMA 200")
src50 = input(close, title="SMA 50 Source")
src200 = input(close, title="SMA 200 Source")
sma50 = sma(src50, len50)
sma200 = sma(src200, len200)
//aboveEMA10 = ema10 > ema20
//belowEMA10 = ema10 < ema20
//barcolor(aboveEMA10 ? color.olive : na)
plot(sma50, color=color.blue, linewidth=3, title="SMA 50")
plot(sma200, color=color.red, linewidth=4, title="SMA 200")
if sma50 > sma200
MACD_buy = crossover(delta, 0)
plotshape(MACD_buy, title='MACD BUY', style=shape.triangleup,
text='B', location=location.belowbar, color=#00BCD4,
textcolor=color.gray, size=size.tiny)
if sma50 < sma200
MACD_sell = crossunder(delta, 0)
plotshape(MACD_sell, title='MACD SELL', style=shape.triangledown,
text='S', location=location.abovebar, color=#E040FB,
textcolor=color.gray, size=size.tiny)