Description of the indicator.
In a previous post, we said that the «Standard Error Channel Color» indicator, unlike the «Standard Dev Channel Color», takes the average dispersion of prices around the adjusted regression line; that is, it does not consider prices directly, but rather uses the standard error. This indicator, which we have called «Multi Standard Error Channel Color» is based on the same principle, except that we have added three channels so that the user can analyze the price chart for different numbers of bars and standard deviations. The underlying theory has already been explained, but it is worth remembering that it is based on the premise that prices follow a normal distribution, which is inaccurate and was the cause of the failure of the Black-Scholes-Merton model for «valuing» options, to say the least.
Users should be aware that, when using this indicator, although it overcomes the problem of the subjectivity of trend lines, it does not exempt them from making mistakes by believing that, because it has an underlying mathematical theory, it is infallible. In fact, it is better to know how to use trend lines and channels well than to be fooled into believing that this indicator is special just because it is based on probability functions.
Explanation of the code.
Block 5-14: We define the inputs of the system's input variables, dividing the code into three similar blocks, as they must be independent so that the user can configure everything from the current studies window in Thinkorswim®, or from the current TradingView® indicator settings, without touching a single line of code. The fullRange# variable indicates the logical value of true or false to consider all or only part of the prices in the channel chart.
Block 16-42: This code, although complicated, is simply a conditional replicated in three blocks that allows the channel to be calculated based on all or only part of the prices. In effect, it is the block of code necessary for our fullRange# variable to be functional when choosing its value at the beginning.
Block 44-52: With this code, we specify that each of the three channels be plotted independently of the others. We note that when drawing the error regression channel, the same procedure is followed as with the standard regression channel; however, here we are using the pre-built StErrAll function. This simple function had to be built from scratch in PineScript, based on related formulas and code. The time and effort saved by this type of function is quite evident.
Block 54-75: This section is where the separation of each of the three code blocks, one for each channel, becomes most apparent, as the color settings are unique to each channel, allowing the user to modify them directly in the pop-up window without having to resort to the code each time they want to do so. In the first part, the color and style of each line of the channel are assigned as attributes; in the second part, the fill colors are defined as global colors, and finally, the AddCloud function is used so that each fill color follows a logical condition, instead of coloring spaces without a clear logic.
Block 77-82: To conclude, we add three pairs of independent alerts, one pair for each time the price crosses the upper or lower line of each channel. The structure of the function to add the alert may already be quite clear to those who have consulted the previous indicators, as it is based on the logical activation condition, followed by the text that is displayed when activated, the location of the alert in the price data, and the type of sound that is heard when activated.