Description of the indicator.
The «MACD Color» indicator is the classic Moving Average Convergence Divergence indicator created by Gerald Appel in the 1970s and later improved by Thomas Aspray in the 1980s, in this case, for Thinkorswim®. It is part of the standard technical analysis library. In this case, the code for Thinkorswim® has been used as a base, customizable colors have been added so that the user can choose them and enhance the reading of the indicator, along with a couple of alerts that the user can enable or disable in the chart study settings. As for the translation, it was based on the classic MACD from the TradingView® community library of indicators and strategies.
Because the MACD principle integrates two moving averages, the widening and narrowing of the space between them is also an indicator of the strength of the trend, especially when a change occurs at the extremes.
Explanation of the code.
Block 5-11: We declare that the indicator should occupy its place in a window outside the main price chart. Then, we declare and define the input variables, in this case, the two moving averages of the MACD, the number of periods for the MACD, the type of moving average, and the hiding of the graphical signals of the crosses. The latter is a default setting for Thinkorswim®.
Block 13-23: In this block, we graph all the visual elements that make up the MACD: the two moving averages, the histogram, the zero level line, and the graphic signals of the crossings, with their respective logical activation or deactivation using the SetHiding attribute.
Block 25-31: We establish the colors that all visual elements will have: the histogram, the averages, and the fill of the space between them, whether they are bullish or bearish.
Block 33-50: We establish the logical structure of the previously declared colors. First, there is the color of the moving averages with the AssignValueColor attribute. Then, the color of the histogram DefineColor, its style, and line type. After that, the color and style of the line for the zero level and the visual signals of the crossings. Finally, the logical conditions for the fill color with the AddCloud function.
Block 52-53: We added a couple of automatic alerts so that the user can easily set and enable them from the current studies settings of the chart in question; one alert is for the bullish crossover and the other for the bearish crossover.