#
# TD Ameritrade IP Company, Inc. (c) 2020-2021
#
declare lower;
input price = close;
input length = 49;
def lProjection = reference TimeSeriesForecast(price = price, length = length, "bar plus" = 1);
def convolutionLength = Floor(Sqrt(length));
plot LeavittConvolutionSlope = reference LinearRegressionSlope(price = lProjection, length = convolutionLength);
plot ZeroLine = 0;
LeavittConvolutionSlope.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
LeavittConvolutionSlope.DefineColor("Summer", Color.GREEN);
LeavittConvolutionSlope.DefineColor("Fall", Color.RED);
LeavittConvolutionSlope.DefineColor("Spring", Color.LIGHT_GREEN);
LeavittConvolutionSlope.DefineColor("Winter", Color.DARK_RED);
LeavittConvolutionSlope.AssignValueColor(if LeavittConvolutionSlope >= LeavittConvolutionSlope[1] and LeavittConvolutionSlope > 0 then LeavittConvolutionSlope.Color("Summer") else if LeavittConvolutionSlope < LeavittConvolutionSlope[1] and LeavittConvolutionSlope > 0 then LeavittConvolutionSlope.Color("Fall") else if LeavittConvolutionSlope < LeavittConvolutionSlope[1] and LeavittConvolutionSlope < 0 then LeavittConvolutionSlope.Color("Winter") else LeavittConvolutionSlope.Color("Spring"));
ZeroLine.SetDefaultColor(GetColor(7));
def LCS = LeavittConvolutionSlope;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input averageType = AverageType.Simple;
def sDev = stdev(data = LCS, 20);
plot MidLine = MovingAverage(averageType, LCS, 20);
plot Ldev2 = MidLine + -2 * sDev;
plot Udev2 = MidLine + 2* sDev;
plot Ldev1 = MidLine + -1 * sDev;
plot Udev1 = MidLine + 1* sDev;
#vw.setdefaultColor(color.yellow);
Udev1.SetDefaultColor(Color.violet);
Udev2.SetDefaultColor(Color.Plum);
Udev1.SetPaintingStrategy(PaintingStrategy.DASHES);
Udev2.SetPaintingStrategy(PaintingStrategy.DASHES);
Udev1.SetLineWeight(1);
Udev2.SetLineWeight(1);
Ldev1.SetDefaultColor(Color.Violet);
Ldev2.SetDefaultColor(Color.Plum);
Ldev1.SetPaintingStrategy(PaintingStrategy.DASHES);
Ldev2.SetPaintingStrategy(PaintingStrategy.DASHES);
Ldev1.SetLineWeight(1);
Ldev2.SetLineWeight(1);