Standard Deviation Channel Daily/Weekly Locked
A very popular study on TOS is the Standard Deviation Channel. It creates very clear support/resistance lines for the timeframe you are looking at.
When switching to an intra-day chart, the Standard Deviation Channel switches to match the trend of this chart. However sometimes clients want to see if the larger timeframes' support and resistance levels are coming into play on the intra-day chart they are using. To do so would require them to switch back and forth between timeframes, so a client requested that we make one where the timeframe it's using is locked to one specific timeframe. We already do this exact thing for the SMA (Called Daily SMA).
First, we will be using 252 and Days to reference the data of a 1Y 1D chart:
input deviations = 2.0;
def regression_1Y_1D = Inertia(close(period = AggregationPeriod.day), 252);
def stdDeviation_1Y_1D = StDev(close(period = AggregationPeriod.day), 252);
plot UpperLine_1Y_1D = regression_1Y_1D + deviations * stdDeviation_1Y_1D;
plot MiddleLine_1Y_1D = regression_1Y_1D;
plot LowerLine_1Y_1D = regression_1Y_1D - deviations * stdDeviation_1Y_1D;
UpperLine_1Y_1D.SetDefaultColor(color.magenta);
MiddleLine_1Y_1D.SetDefaultColor(color.magenta);
LowerLine_1Y_1D.SetDefaultColor(color.magenta);
As you can see, the standard deviation channel on the right side of this screenshot (5D 15m) matches perfectly with the current values from our 1Y 1D chart on the left.
Next, we will do the same thing as last time with 156 and Weeks to reference the data of a 3Y 1w chart:
input deviations = 2.0;
def regression_3Y_1W = Inertia(close(period = AggregationPeriod.week),156);
def stdDeviation_3Y_1W = StDev(close(period = AggregationPeriod.week), 156);
plot UpperLine_3Y_1W = regression_3Y_1W + deviations * stdDeviation_3Y_1W;
plot MiddleLine_3Y_1W = regression_3Y_1W;
plot LowerLine_3Y_1W = regression_3Y_1W - deviations * stdDeviation_3Y_1W;
UpperLine_3Y_1W.SetDefaultColor(color.cyan);
MiddleLine_3Y_1W.SetDefaultColor(color.cyan);
LowerLine_3Y_1W.SetDefaultColor(color.cyan);
Once again the values from our 3Y 1w chart (left) match up perfectly with the values shown on the right (5D 15m)
Finally, we put it all together in 1 script:
input deviations = 2.0;
def regression_1Y_1D = Inertia(close(period = AggregationPeriod.day), 252);
def stdDeviation_1Y_1D = StDev(close(period = AggregationPeriod.day), 252);
plot UpperLine_1Y_1D = regression_1Y_1D + deviations * stdDeviation_1Y_1D;
plot MiddleLine_1Y_1D = regression_1Y_1D;
plot LowerLine_1Y_1D = regression_1Y_1D - deviations * stdDeviation_1Y_1D;
UpperLine_1Y_1D.SetDefaultColor(color.magenta);
MiddleLine_1Y_1D.SetDefaultColor(color.magenta);
LowerLine_1Y_1D.SetDefaultColor(color.magenta);
def regression_3Y_1W = Inertia(close(period = AggregationPeriod.week),156);
def stdDeviation_3Y_1W = StDev(close(period = AggregationPeriod.week), 156);
plot UpperLine_3Y_1W = regression_3Y_1W + deviations * stdDeviation_3Y_1W;
plot MiddleLine_3Y_1W = regression_3Y_1W;
plot LowerLine_3Y_1W = regression_3Y_1W - deviations * stdDeviation_3Y_1W;
UpperLine_3Y_1W.SetDefaultColor(color.cyan);
MiddleLine_3Y_1W.SetDefaultColor(color.cyan);
LowerLine_3Y_1W.SetDefaultColor(color.cyan);
With both the 1 year and 3 year standard deviation channels, we can see that the stock has actually traded between two of these larger timeframes' support and resistance levels. Something we could have been blind to without this study.