I added a dynamic Cloud and Label (Up = GREEN / Down = RED) to the LinearRegChVar study found here:
https://toslc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/G-L/LinearRegChVar
https://toslc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/G-L/LinearRegChVar
Code:
input Cloud = no;
input price = close;
input widthOfChannel = 100.0;
input fullRange = Yes;
input Label = yes;
input length = 21;
plot MiddleLR;
if (fullRange)
then {
MiddleLR = InertiaAll(price);
} else {
MiddleLR = InertiaAll(price, length);
}
def dist = HighestAll(AbsValue(MiddleLR - price)) * (widthOfChannel / 100.0);
plot UpperLR = MiddleLR + dist;
plot LowerLR = MiddleLR - dist;
MiddleLR.DefineColor("Up", GetColor(6));
MiddleLR.DefineColor("Down", GetColor(5));
MiddleLR.AssignValueColor(if MiddleLR > MiddleLR[1] then MiddleLR.Color("Up") else MiddleLR.Color("Down"));
MiddleLR.SetLineWeight(1);
MiddleLR.SetStyle(1);
MiddleLR.HideBubble();
MiddleLR.HideTitle();
UpperLR.DefineColor("Up", GetColor(6));
UpperLR.DefineColor("Down", GetColor(5));
UpperLR.AssignValueColor(if UpperLR > UpperLR[1] then UpperLR.Color("Up") else UpperLR.Color("Down"));
UpperLR.SetLineWeight(1);
UpperLR.SetStyle(1);
UpperLR.HideBubble();
UpperLR.HideTitle();
LowerLR.DefineColor("Up", GetColor(6));
LowerLR.DefineColor("Down", GetColor(5));
LowerLR.AssignValueColor(if LowerLR > LowerLR[1] then LowerLR.Color("Up") else LowerLR.Color("Down"));
LowerLR.SetLineWeight(1);
LowerLR.SetStyle(1);
LowerLR.HideBubble();
LowerLR.HideTitle();
AddCloud(if MiddleLR > MiddleLR[1] then LowerLR else double.NaN, UpperLR, Color.GREEN, Color.GREEN);
AddCloud(if MiddleLR < MiddleLR[1] then UpperLR else double.NaN, LowerLR, Color.RED, Color.RED);
AddLabel(Label,
if MiddleLR > MiddleLR[1] then
" Bullish "
else
" Bearish ",
if MiddleLR > MiddleLR[1] then Color.GREEN else Color.RED);