This is another spin of the classic MACD divergence indicator except we use a zero lag MACD and also consider the immediate price action to filter for stronger signals.
The only adjustable parameter is the lookback period to consider for calculating the divergence between price and the MACD crossover.
Note that the indicator only loads 5000 bars per default in order to load faster but this can easily be changed in the code if required.
Defparam CalculateOnLastBars = 5000
MACD1 = DEMA(close) //Moving Average 1
MACD2 = DEMA(close) //Moving Average 2
MACDSource = MACD1 - MACD2
MACDSignal = DEMA(MACDSource) //MACD Signal Line
DivergencePeriod = 20
If MACDSignal > 2 and MACDSignal <= MACDSource and MACDSignal >= MACDSource Then
MACDCrossHigh = MACDSignal
ElsIf MACDSignal < -2 and MACDSignal >= MACDSource and MACDSignal <= MACDSource Then
MACDCrossLow = MACDSignal
If MACDCrossHigh < MACDCrossHigh[DivergencePeriod] and close > close[DivergencePeriod] and (high-max(open,close) > (max(open,close)-min(open,close)) or (close > open and close < min(open,close))) Then
Divergence = -1
r = 255
g = 0
ElsIf MACDCrosslow > MACDCrossLow[DivergencePeriod] and close < close[DivergencePeriod] and (min(open,close)-low > (max(open,close)-min(open,close)) or (close < open and close > max(open,close))) Then
Divergence = 1
r = 0
g = 255
Divergence = 0
r = 0
g = 0
Return Divergence coloured(r,g,0) style(histogram) as "Divergence"
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 :
PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials
Is there perhaps a problem with the code?
It doesn’t work, at least not on my PRT version 11
Hi Juanj e thanks for your indicator; do you suggest any timeframe for a better use of it? thanks
It doesn’t work
it seems it’s not working on prorealtime 11. I changed MACDSignal to MACDSign in order to avoid running errors. However the indicator does not print anything. Any info for fixing this issue? thanks
Please note that the indicator is meant for PRT 10.3