Description of the indicator.
The indicator «Displaced Moving Averages Suite» is not part of the standard technical analysis repository, but was retrieved from the «Hull Suite» indicator, which was published for free by InSilico in the TradingView® community library.
The system is based on the principle of shifting back the moving average line that the user selects, in relation to the same moving average, but in the present. It is at the crossing of both averages where the bullish or bearish signal will be obtained. Additionally, colors have been added to the averages and to the areas between the averages according to the current signal.
Unlike the classic moving average crossover, in this case and due to the mathematical principle of its construction, we do not observe that the space between the two widens when the trend is stronger and narrows when it is weaker. Instead, it provides a more refined way to obtain the signal, especially when it comes to Alan Hull's moving average, as for a certain configuration it provides signals very similar to Heiken-Ashi candles.
The indicator was also translated to ThinkScript so that the user can implement it for free.
Explanation of the code.
Block 5-8: We declare the input variables, setting the closing price, the Exponential Moving Average (EMA), the periodicity of that EMA, and the number of lag periods that will give rise to the second one by default. This configuration yields results similar to Heiken-Ashi candles.
Block 10-11: We graph both averages using the pre-built MovingAverage function, passing as parameters the type of price, the type of moving average, its length, and the size of the offset.
Block 13-19: We set the color type for each moving average and the space between them. In the first part of the code, the color of the averages is described, depending on whether both express an upward trend or both express a downward trend. In the second part, the colors of the space between them are defined according to the same condition.
Block 21-24: We set the logical conditionals that the graphed colors must follow, using the AssignValueColor attribute. Then, the AddCloud function is used to fill the space between both following the pre-built logical rules.
Block 26-27: Two alerts are defined that the user can activate or deactivate in the settings of the current studies, one for the bullish crossover and another for the bearish crossover.