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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
Defparam CalculateOnLastBars = 5000 MACD1 = DEMA[12](close) //Moving Average 1 MACD2 = DEMA[26](close) //Moving Average 2 MACDSource = MACD1 - MACD2 MACDSignal = DEMA[9](MACDSource) //MACD Signal Line DivergencePeriod = 20 If MACDSignal > 2 and MACDSignal[1] <= MACDSource[1] and MACDSignal >= MACDSource Then MACDCrossHigh = MACDSignal ElsIf MACDSignal < -2 and MACDSignal[1] >= MACDSource[1] and MACDSignal <= MACDSource Then MACDCrossLow = MACDSignal EndIf If MACDCrossHigh < MACDCrossHigh[DivergencePeriod] and close > close[DivergencePeriod] and (high-max(open,close) > (max(open,close)-min(open,close)) or (close[1] > open[1] 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[1] < open[1] and close > max(open,close))) Then Divergence = 1 r = 0 g = 255 Else Divergence = 0 r = 0 g = 0 EndIf Return Divergence coloured(r,g,0) style(histogram) as "Divergence" |
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 :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