Linear regression channel colored based on slope


Category:
0
0

I would like to have an LRC that I can modify the number of days back as well as the amount of standard deviation I am looking for.  I know there are several regression plots out there that I can do this…but the one thing I would like is the plot to change from green to red when the channel moves to a down trend and vice versa.

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on May 14, 2020 7:55 pm
138 views
0
Private answer

Please provide the source code you want to modify or the name of a built-in study included in Thinkorswim. We are not going to create this from scratch.

Edit: The source code for this request was provided in the comment section below. So I can now provide the solution that was requested.

input price = close;
input deviations = 2.0;
input fullRange = yes;
input length = 21;
def regression;
def stdDeviation;
if (fullRange) {
regression = InertiaAll(price);
stdDeviation = stdevAll(price);
} else {
regression = InertiaAll(price, length);
stdDeviation = stdevAll(price, length);
}
plot upperLine = regression + deviations * stdDeviation;
plot middleLine = regression;
plot lowerLine = regression - deviations * stdDeviation;
upperLine.DefineColor("Up", Color.GREEN);
upperLine.DefineColor("Down", Color.RED);
upperLine.AssignValueColor(if upperLine > upperLine[1] then upperLine.Color("Up") else upperLine.Color("Down"));
middleLine.SetDefaultColor(GetColor(8));
middleLine.DefineColor("Up", Color.GREEN);
middleLine.DefineColor("Down", Color.RED);
middleLine.AssignValueColor(if middleLine > middleLine[1] then middleLine.Color("Up") else middleLine.Color("Down"));
lowerLine.SetDefaultColor(GetColor(8));
lowerLine.DefineColor("Up", Color.GREEN);
lowerLine.DefineColor("Down", Color.RED);
lowerLine.AssignValueColor(if lowerLine > lowerLine[1] then lowerLine.Color("Up") else lowerLine.Color("Down"));

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on May 14, 2020 8:13 pm
0
input price = close; input deviations = 2.0; input fullRange = Yes; input length = 21; def regression; def stdDeviation; if (fullRange) { regression = InertiaAll(price); stdDeviation = stdevAll(price); } else { regression = InertiaAll(price, length); stdDeviation = stdevAll(price, length); } plot UpperLine = regression + deviations * stdDeviation; plot MiddleLine = regression; plot LowerLine = regression - deviations * stdDeviation; UpperLine.SetDefaultColor(GetColor(8)); MiddleLine.SetDefaultColor(GetColor(8)); LowerLine.SetDefaultColor(GetColor(8));
( at May 15, 2020 7:13 am)
0
I have updated my answer to include the solution you requested.
( at May 15, 2020 8:01 am)
0
Thank you very much!!
( at May 15, 2020 8:03 pm)