defparam drawonlastbaronly=true
ONCE FastAvg = 12
ONCE SlowAvg = 26
ONCE SigAvg = 9
EMAshort1 = exponentialaverage[FastAvg](close)
EMAshort2 = exponentialaverage[FastAvg](EMAshort1)
DifferenceShort = EMAshort1 - EMAshort2
ZeroLagShort = EMAshort1 + DifferenceShort
EMAlong1 = exponentialaverage[SlowAvg](close)
EMAlong2 = exponentialaverage[SlowAvg](EMAlong1)
DifferenceLong = EMAlong1 - EMAlong2
ZeroLagLong = EMAlong1 + DifferenceLong
ZeroLagMACD = ZeroLagShort - ZeroLagLong
signal1=ExponentialAverage[SigAvg](ZEROLAGMACD)
signal2=ExponentialAverage[SigAvg](signal1)
DIFFERENCE2=signal1-signal2
SignalMACD=signal1+DIFFERENCE2
alphaX=2/(1+FastAvg)
alphaY=2/(1+SlowAvg)
prevEMA1=ZeroLagShort[1]
prevEMA2=ZeroLagLong[1]
//This is de value of MACD you want to check
macdValue=0
priceMACD=(macdValue+((1-alphaY)*prevEMA2)-((1-alphaX)*prevEMA1))/(alphaX-alphaY)
pricerounded=round(priceMACD,2)
drawtext("ZMACD crossing:#pricerounded#",barindex,priceMACD+2,SansSerif,Bold,10)
DRAWSEGMENT(barindex-10,priceMACD,barindex,priceMACD) coloured(0,0,0)
return