Skip to Content

Standard Dev Channel Color

January 15, 2026 by
Standard Dev Channel Color
Al-Juarismi-Lab

TradingView® Thinkorswim®

Description of the indicator.

The «Standard Dev Channel Color» indicator is based on the statistical concept of linear regression, with Gilbert Raff being the first to implement it as a technical analysis indicator. Basically, it is one of many ways of making future projections based on known past and current data; it also requires that the variables be linearly related, i.e., that changes in the variables remain stable, resulting in a straight line on the plane, hence the term «linear». Advanced users may rightly note that prices do not always tend to fall within the channel in question, as sometimes the intensity of a movement is so strong that prices move outside the channel. Traditionally, this indicator is often used under the same principle as Bollinger Bands, with the difference that we do not take the standard deviations from the mean, but from the linear regression line. It is assumed that, if prices are normally distributed, the theory ensures that the probability of them being within the channel of one standard deviation is 68.27%, of them being within two standard deviations is 95.45%, and within three is 99.73%.

It doesn't take much effort to realize that prices do not follow a normal distribution, and since this is the case, the price will not always respect the probability of the Gaussian distribution of falling within the channel. There will be times when prices do not even touch the channel, or remain outside the channel for a long time. While the theory is correct, applying it to prices denotes a lack of conceptual understanding; it is an objective solution to a problem that trend lines have already solved. It is true that linear regression channels manage to overcome the subjectivity inherent in any interpretation of charts, as they have a solid mathematical basis, but this is no guarantee, given that the theory is poorly applied.

Explanation of the code.

Block 5-8: As initial assignments, we define four variables corresponding to the price type, the number of periods, the standard deviation factor of the regression line, which will give rise to the channel, and the optional statement to display the channel for all bars visible on the chart.

Block 10-22: In the first section of the block, we define the relative assignments that will be used to structure the channel, depending on whether the logical value for displaying all bars is true or false; in both cases, it is possible to obtain the result using the InertiaAll and stdevAll functions, whose default input is all the data in the current chart. In the second section, we simply plot the regression line and the channel lines. Thinkorswim® recognizes the prebuilt stdevAll function as a way to automatically build the channel; in the case of PineScript, we can verify that there is no such function, so we use a different method using the declared Building(y, n) function.

Block 24-33: As usual, we now simply define the color type and style for both the lines and the space between them. We use the SetDefaultColor and SetStyle attributes for the lines, and GetColor as a system function that adapts their color to the user's theme type, remembering that the AddCloud function is what allows us to color the space between objects.

Block 35-36: We conclude the code with the two usual alerts, the first to notify when the price crosses the top of the channel, and the second to do so when the price crosses below the channel. As with all ThinkScript alerts, the crucial part is crosses above, as it is a logical condition that in PineScript must be defined by mathematical inequality symbols.

PineScript [TradingView®]:

ThinkScript [Thinkorswim®]:

Share