CryptoRygel

[Rygel] MACD 4C with divergences, crossovers and alerts

CryptoRygel Uppdaterad   
This indicator is a reliable, exhaustive, instant, simple divergence detector for the MACD 4C oscillator.

I've struggled for months to find a MACD divergence indicator I can rely on, I've tinkered with the ones I found and never was satisfied by the final result. For all of them important divergences were not shown, for some divergences was shown too late, for others divergence lines was not drawn, some even shown some strange exotic divergences... I played will all the parameters and something was always wrong or missing at the end.

It was even worse for the MACD 4C indicator, the 4-color MACD, which I prefer to use.

So I finally decided to write my own divergence algorithm and to create my own indicator. After a few attempts, here's the result.

This MACD indicator is using the same divergence detection algorithm I wrote for my RSI indicator. You'll find on its description page a comparison of my divergence algorithm with other ones to see how it differs.

When I built this indicator, my objectives were to create one that is:

  • Reliable. I didn't want to have to double-check an indicator to make sure it's doing what I expect it to do. I want to be able to look at it for one second and know I can rely on it.
  • Exhaustive. I didn't want to have to rely on multiple indicators to be sure I'm not missing a divergence.
  • Instant. I wanted the divergences to be shown as soon as soon as they form and not after a pivot is confirmed. For some indicator, when the divergence is displayed, it's already too late to act on it.
  • Simple. I wanted my indicator to be clean, readable and not visually aggressive. The main objective of this indicator is to show divergences and I didn't want to visually overload it with unrequired information.
I wanted my indicator to be a simple as possible, nonetheless you'll find a few parameters to tinker with. Many of them will need no explanation but here's the list.

  • Show signal line: disabled by default. Show the MACD signal line.
  • Color signal line: disabled by default. Show the signal line as green when it goes up and read when it goes down.
  • Show signal crossovers: enabled by default. Show a green dot when MACD crosses up its signal line and a red dot when it crosses down.
  • Show zero line: enabled by default. Show a line at the 0 value.
  • Show zero crossovers: disabled by default. Show a green triangle when MACD crosses up the 0 line and a red triangle when it crosses down.
  • Show regular divergences: enabled by default.
  • Show hidden divergences: disabled by default for readability. I try to keep the indicator as clean as possible by default.
  • Bullish regular divergence color: no explanation needed I suppose.
  • Bullish hidden divergence color: same.
  • Bearish regular divergence color: ditto.
  • Bearish hidden divergence color: uhh.
  • Show overbought and oversell backgrounds: when RSI is oversold or oversell, the background color changes to red or green. The indicator uses two levels of oversold/overbought. When the RSI is strongly oversold/overbought the background color gets brighter. You can configure these levels in the advanced parameters.
Advanced parameters:

  • MACD fast moving average length: 12 by default.
  • MACD slow moving average length: 26 by default.
  • MACD signal moving average length: 9 by default.
  • Show divergences before pivot confirmation: enabled by default. Divergences will appear as soon as possible, before the pivot is confirmed by another candlestick. Unconfirmed divergences will appear as dashed lines then disappear if not confirmed or turn to solid lines if confirmed. This may create false positives with alerts as the divergence may disappear.
  • Minimum bars to check: 5 by default. As this indicator detects absolutely all the divergences, some may be insignificant and it may become unreadable without some filtering. If you want to see absolutely all the divergences, you may lower this value. Please note TradingView limits to 50 how many lines are displayed at the same time on an indicator. So when you display more divergences, some in the past disappear. It's not usually an issue but if you scroll back in time, divergences will stop to show at one point in the past.
  • Maximum bars to check: 75 by default. Divergences may go far in the past, this parameters limit how old a divergence may be. You can higher it to show more divergences.
  • Show pivots: disabled by default. Show the pivot points used for divergence detections.
This indicator offers the following alerts:

  • Any divergence
  • Bearish divergence
  • Bullish divergence
  • Regular bearish divergence
  • Regular bullish divergence
  • Hidden bearish divergence
  • Hidden bullish divergence
  • MACD becoming positive
  • MACD becoming negative
  • MACD crossing up signal line
  • MACD crossing down signal line
Please note TradingView limits for performance reason to 50 the number of lines you can display on an indicator at the same time. So when you scroll back in time, at one point divergences will stop to show. If you want to see divergences far in the past, you may need to use the replay feature or to configure stronger filtering settings.

I hope you'll enjoy this indicator as much as I do! :)
Feel free to comment if you experience a bug or if an important feature is missing for you. (Please note the core of this indicator is divergence detection, I want to keep it simple so I will probably not add many unrelated features to it.)
Versionsinformation:
Increased maximum visible divergence lines from 50 to 500.
I've just discovered you can increase the maximum visible line count up to 500. By default TradingView limits it to 50. This solves almost all the issues caused by the 50 lines limitation I talked about in this indicator description. Hurray! :)
Versionsinformation:
Added MACD histogram, VWMACD (Volume-Weighted MACD) and VMMACD histogram modes.
Versionsinformation:
Fixed signal for histogram modes
Versionsinformation:
Final V1 release. Please upgrade to Rygel MACD V2 to get the latest updates and improvements.
Versionsinformation:
I'm still learning the TradingView publication process. I've tried to create a V2 release of this script to update its description but it's not allowed, so I'm merging the changes here.

Added "hypothetical divergences" option to show divergences before a pivot is forming, added new alerts for confirmed, confirming and unconfirmed divergences, decreased "minimum bars to check" to 3 and increased "maximum bars to check" to 100.

Please find below an updated user guide of this indicator parameters.

  • MACD type: MACD, MACD histogram, VWMACD or VWMACD histogram.
    MACD:
    MACD histogram:
    VWMACD:
    VWMACD histogram:
  • Show regular divergences: enabled by default.
  • Show hidden divergences: disabled by default for readability. I try to keep the indicator as clean as possible by default.
  • Bullish regular divergence color: no explanation needed I suppose.
  • Bullish hidden divergence color: same.
  • Bearish regular divergence color: ditto.
  • Bearish hidden divergence color: uhh.
  • Show signal line: disabled by default. Show the MACD signal line.
  • Color signal line: disabled by default. Show the signal line as green when it goes up and read when it goes down.
  • Show signal crossovers: enabled by default. Show a green dot when MACD crosses up its signal line and a red dot when it crosses down.
  • Show zero line: enabled by default. Show a line at the 0 value.
  • Show zero crossovers: disabled by default. Show a green triangle when MACD crosses up the 0 line and a red triangle when it crosses down.

Advanced parameters:

  • MACD fast moving average length: 12 by default.
  • MACD slow moving average length: 26 by default.
  • MACD signal moving average length: 9 by default.
  • Show forming divergences, before pivot confirmation: enabled by default. Divergences will appear as soon as possible, before the pivot is confirmed by another candlestick. Unconfirmed divergences will appear as dashed lines then disappear if not confirmed or turn to solid lines if confirmed. This may create false positives with alerts as the divergence may disappear.
  • Show hypothetical divergences, before pivot creation: disabled by default. Divergences will appear even before a pivot is forming. Lot of false positives. Only for educational purposes. Don't take trading decisions based on hypothetical divergences. Hypothetical divergences appears as white dashed lines.
  • Minimum bars to check: 3 by default. As this indicator detects absolutely all the divergences, some may be insignificant and it may become unreadable without some filtering. If you want to see less divergences, you may increase this value.
  • Maximum bars to check: 100 by default. Divergences may go far in the past, this parameters limit how old a divergence may be. You can decrease it to show less divergences.
  • Use limits for divergences: enabled by default. Don't show divergences when they are above or below a threshold. Another filtering options to make sure only relevant divergences are shown. Mostly useful for hidden divergences.
  • Minimum value for bearish divergence: 40 by default.
  • Maximum value for bullish divergence: 60 by default.
  • Show pivots: disabled by default. Show the pivot points used for divergence detections.

This indicator now offers the following alerts:

Confirmed divergences: pivot is confirmed, bar is closed, divergence is real and final.

  • Confirmed divergence
  • Confirmed regular divergence
  • Confirmed hidden divergence
  • Confirmed bullish divergence
  • Confirmed bearish divergence
  • Confirmed regular bullish divergence
  • Confirmed regular bearish divergence
  • Confirmed hidden bullish divergence
  • Confirmed hidden bearish divergence

Confirming divergences: pivot is formed but the bar is not yet closed, divergence may disappear until it is. You will received false positive alerts.

  • Confirming divergence
  • Confirming regular divergence
  • Confirming hidden divergence
  • Confirming bullish divergence
  • Confirming bearish divergence
  • Confirming regular bullish divergence
  • Confirming regular bearish divergence
  • Confirming hidden bullish divergence
  • Confirming hidden bearish divergence

Unconfirmed divergences: pivot doesn't fully exist yet, divergence may never be confirmed and disappear. Two bars have yet to close for the divergence to become real and final. You will receive many false positive alerts.

  • Unconfirmed divergence
  • Unconfirmed regular divergence
  • Unconfirmed hidden divergence
  • Unconfirmed bullish divergence
  • Unconfirmed bearish divergence
  • Unconfirmed regular bullish divergence
  • Unconfirmed regular bearish divergence
  • Unconfirmed hidden bullish divergence
  • Unconfirmed hidden bearish divergence

Signal line crossing up and down

  • Crossing up signal line (not yet confirmed, the bar is not yet closed)
  • Crossing down signal line (not yet confirmed, the bar is not yet closed)
  • Crossed up signal line (confirmed, the bar is closed)
  • Crossed down signal line (confirmed, the bar is closed)

Zero line crossing up and down

  • Becoming positive (not yet confirmed, the bar is not yet closed)
  • Becoming negative (not yet confirmed, the bar is not yet closed)
  • Became positive (confirmed, the bar is closed)
  • Became negative (confirmed, the bar is closed)
Versionsinformation:
Updated indicator chart picture.
Versionsinformation:
  • Added a new setting option: "When divergences are similar, only keep the longest one".
    By default, when multiple divergences end at the same point, only the longest one is displayed. When you disable this setting, all the divergences ending at the same point become visible.
    This setting is enabled by default for readability. If you disable it, divergences may clutter the graph. It will also reduce how far in the past divergences are shown because of the TradingView 500 lines limitation.
    Use this option only if you want to see absolutely all of the divergences.
  • Increased maximum allowed value for "Divergence maximum bars" from 100 to 200. 100 is still the default "maximum bars" setting but you can now increase it up to 200.
  • When a regular and a hidden divergence end at the same point, only the regular one was displayed. Both are now visible.
Versionsinformation:
Improved pivot price detection. Price and MACD pivots are not always on the exact same bar, sometimes there is a 1 bar offset. Price is now selected to always be the lowest/highest rather than the one exactly on the MACD pivot bar.
Versionsinformation:
Improved divergence detection. (I found a few edge cases where my divergence algorithm couldn't detect some divergences for slow moving indicators like MACD because of malformed pivots. Though these divergences were real, their pivot couldn't be validated and so the divergence didn't appear. So I wrote a new pivot detection algorithm that can handle these specific unorthodox pivots.)
Versionsinformation:
Increased default maximum bars to check from 100 to 180 and increased absolute maximum to 250. Previous default setting was missing a major daily divergence on Bitcoin.
Versionsinformation:
Fixed a condition where alert for unconfirmed bearish divergences would not be sent.
Versionsinformation:
  • Fixed a rare issue with some divergences being wrongfully displayed because of the slow price reaction of the MACD indicator ;
  • Fixed a rare issue with hypothetical divergences hiding confirmed ones.
Versionsinformation:
Fixed a condition where some alerts were not sent when hypothetical divergences were enabled.
Versionsinformation:
Moving average minimum lengths set to 1.
Versionsinformation:
  • Improved reliability. A divergence won't show anymore if a price pivot breaks the divergence line. For instance, when you draw a bullish regular divergence line from price A to price B, if an intermediate price pivot breaks the divergence line (i.e. if the price of the pivot is below the divergence line), the divergence won't show anymore.
  • Improved pivot detection. Some pivots are now better positioned.
  • To improve readability, hidden bullish divergences are now in blue and hidden bearish divergences in orange. Hidden and regular divergences should be easier and faster to identify.
  • Fixed a condition where some alerts were not sent when hypothetical divergences were enabled
  • Fixed a condition where a divergence could be missing when too many pivots were detected.

Skyddat skript
Detta skript publiceras med stängd källkod och du kan använda det fritt. Du kan ange den som favorit för att använda den i ett diagram. Du kan inte visa eller ändra dess källkod.
Frånsägelse av ansvar

Informationen och publikationerna är inte avsedda att vara, och utgör inte heller finansiella, investerings-, handels- eller andra typer av råd eller rekommendationer som tillhandahålls eller stöds av TradingView. Läs mer i Användarvillkoren.

Vill du använda det här skriptet i ett diagram?