Here is the traditionnal MACD (Moving Average Convergence Divergence) indicator made with the “zero lag” calculation process.
The default values are : 26 (long) , 12 (short) and 9 for the signal line.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
EMAshort1 = exponentialaverage[short](close) EMAshort2 = exponentialaverage[short](EMAshort1) DifferenceShort = EMAshort1 - EMAshort2 ZeroLagShort = EMAshort1 + DifferenceShort EMAlong1 = exponentialaverage[long](close) EMAlong2 = exponentialaverage[long](EMAlong1) DifferenceLong = EMAlong1 - EMAlong2 ZeroLagLong = EMAlong1 + DifferenceLong ZeroLagMACD = ZeroLagShort - ZeroLagLong signal1=ExponentialAverage[signal](ZEROLAGMACD) signal2=ExponentialAverage[signal](signal1) DIFFERENCE2=signal1-signal2 SignalMACD=signal1+DIFFERENCE2 RETURN ZeroLagMACD as "Zero Lag MACD", SignalMACD as "Signal MACD" |
Share this
No information on this site is investment advice or a solicitation to buy or sell any financial instrument. Past performance is not indicative of future results. Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced investors who have sufficient financial means to bear such risk.
ProRealTime ITF files and other attachments :
Filename : download the ITF files
How to import ITF files into ProRealTime platform?
PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials
Hi.
Can you please describe how you set the colors as in the attached screenshot? Thanks.
Just set the two colors of the ‘SignalMACD’ curve in the indicator properties window.
Hi Nicolas, can you please upload a version with TEMA, so those who don’t know how to code can download the .itf ? Thanks
Use the MACD code here: https://www.prorealcode.com/topic/standard-prt-code-for-macd/#post-189640
and change exponentialaverage with TEMA
see instruction: https://www.prorealcode.com/documentation/tema/
Hi Nicolas,
When applying these codes for MACD zero lag above I don’t get the same result as the stadard MACD zero lag indicator embedded in the system, please see picture attached. Do you know what I am doing wrong? For this example I am using standard periods – 12/26/9. I am looking for the codes for MACD zero lag indicator in order to use it in the proscreener. thanks.
Hi Lasse, because MACD is a line and not an histogram for the indicator embedded in the platform.
ok, but even though I look at the line and compare it with the histogram in the default indicator it is still not the same result – …not really sure what you mean. What I am looking for, is a coding for the MACD Zero lag indicator in order to apply it as part of my proscreenings. Could you please post the link to the indicator codings if it’s available? thanks.
Hello,
Here is a code with the same result as default indicator :
// MACD ZERO LAG
// p= variable macd zerolag : 12 par défaut
// q= variable signal : 26 par défaut
// r= variable macd - signal : 9 par défaut // mettre histogramme
p = 12
q = 26
r = 9
z1=DEMA[p](close)
z2 =dema[q](close)
e= z1 - z2
z3=DEMA[r](e)
f=z3
g=e-f
return e AS \"MACD ZEROLAG\",f AS \"signal\",g as \"macd-signal\",0 as \"zero\"
Best regards,
Hi,
How to build this into the system as a condition such as: “IF MACDZeroLag > MACDZeroLag[1] THEN …” When i call for this indicator probuilder shows an error because only one value out of three is used.
Thanks
There are 2 versions of the MACD (almost) Zero Lag in the same Article introducing Zero-Lag MACD, (Patrick G. Mulloy), “Smoothing Data With Less Lag” article in TASC (Technical Analysis of Stock and Commodities) V12.2 pages 72-80.
One version is indeed using a DEMA as shown in the code above, the second version in the article used a TEMA instead.
Only the DEMA version is implemented in ProrealTime.
The TEMA is faster (and has even less lag),
BTW: Both versions are not truly zero-lag, but are “almost” zero-lag.
Patrick Murphy stated that “Comparing the MACDs for TEMA1 with DEMA1” … “The DEMA1 MACD had two fewer trades, approximately a
20% improvement in overall profit, and one fewer drawdown.”
But he stated that with other period parameters, TEMA version was way better and showed a 50% improvement in overall profit vs the DEMA version. Please refer to the article for more clues.
The TEMA instruction is available, so that’s easy to make an MACD with it. https://www.prorealcode.com/documentation/tema/
Buenas tardes Nicolás,
Estoy intenando configurar este indicador MACD Retraso 0, y no se que debo poner en “defina la siguiente variable: EMAshort1.
Espero sus noticias. Muchas gracias
Afin d’avoir l’Histogramme Macd il faut rajouter ligne18 : HistogrammeMacd = ZeroLagMACD – SignalMACD (et dans le) Return HistogrammeMacd as “HistogrammeMacd”(ligne19)