I cannot debug the error message.Please help and many thanks.
Previously I used pivothigh() and valuewhen() to code, it worked perfect,but I got warning message when setting alerts.
So that I use Dif[2]>Dif[1] and Dif[2]>Dif and so on to replace pivothigh().
But it could be compiled but cannot work properly and shows that references too many candles.
//@version=4
maxbarsback=1000
study(title="MACD v3",max_bars_back=maxbarsback)
dh1=0.0,dh2=0.0,dh3=0.0,dph1=0,dph2=0,dph3=0
var line ll=na
col_grow_above = #26A69A
col_grow_below = #FFCDD2
col_fall_above = #B2DFDB
col_fall_below = #EF5350
col_macd = #0094ff
col_signal = #ff6a00
dif = ema(close,9)-ema(close,26)
signal = ema(dif, 9)
hist = dif - signal
condition1=dif[2]>dif[1] and dif[2]>dif and dif[2]>dif[3] and dif[2]>dif[4]
if condition1
dh3:=dh2[1]
dh2:=dh1[1]
dh1:=dif[2]
dph3:=dph2[1]
dph2:=dph1[1]
dph1:=bar_index-2
condition2=dph3!=0 and dh2>=dh1 and high[bar_index-dph1]>high[bar_index-dph2]
if condition2 and not condition2[1]
ll:=line.new(dph2,dif[bar_index-dph2],dph1,dif[bar_index-dph1],extend=extend.none,color=color.red,width=2,style=line.style_dotted)
plotshape(title='+DC', series=condition2 and not condition2[1] ?dif[2] : na, text='+DC', style=shape.labeldown, location=location.absolute, color=color.maroon, textcolor=color.white,offset=-2)
plot(hist, title="Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below) ), transp=0 )
plot(dif, title="DIF", color=color.white, transp=0)
plot(signal, title="MACD", color=color.gray, transp=0)