Description of the indicator.
The «Standard Error Channel Color» indicator was taken directly from the Thinkorswim® indicator of the same name, except that «Color» was added because it has been improved to paint the space between the two ends of the channel. As with the linear regression channel, the PineScript code was adapted and structured to correspond exactly to its representation for TradingView®.
The theory underlying the indicator, as with the simple regression channel, has its origins in statistics and the concept of linear regression; however, unlike prices, here the average dispersion of prices around the adjusted regression line is taken, i.e., it does not consider prices directly, but rather uses the standard error. Due to this mathematical principle, it can be seen that, although both consider the same concept of one, two, or three standard deviations, the standard error channel is much narrower than that of the simple deviation; for this reason, prices are more likely to reach the extremes of the channel. As with subjective trend channels, the standard error channel shows a strong trend when the price suddenly leaves that channel; and as with the simple regression channel, the theory underlying this channel implies that the data are normally distributed, i.e., that the data follow a normal probability distribution, which, as already mentioned, is erroneous for the study of prices per se.
Explanation of the code.
Block 5-8: We define the input variables based on the type of price to be implemented, the number of previous prices of the indicator, the standard deviation of the errors, and the option of taking all the bars on the screen for the chart or not.
Block 10-22: Although the code in this block is similar to that of the simple regression channel, users will notice that we have replaced the prebuilt stdevAll function with sterrAll, which comes preconfigured by Thinkorswim® to calculate price sample errors. In fact, this function had to be adapted for PineScript as Building(y, n), in addition to ta.linreg and ta.stdev to calculate and plot the channel. The second section of the code simply specifies that the elements should be plotted: the regression line and the channel lines.
Block 24-33: With these instructions, we specify the color type and style of the lines in the graph. In this case, SetStyle(Curve.SHORT_DASH) means that the linear regression line will not be continuous, but will be a line with slight discontinuities. Remember also that the DefineGlobalColor function allows the AddCloud color to be modified by the user from the study settings.
Block 35-36: We conclude by defining two alerts, one that is triggered when the price crosses the top of the error regression channel, and another when it crosses the bottom of that channel.