Linear Regression Channel



The Linear Regression Channel is a very popular study. A client wanted to have additional channels half way in between the ones shown on the left, as well as some color coding (green on the bottom for buy regions, and red on the top for sell regions).



By tweaking/adding on to the original script, we end up with this:

input price = close;


plot MidLine = InertiaAll(price);

def dist100 = HighestAll(AbsValue(MidLine - price));

def dist75 = HighestAll(AbsValue(MidLine - price)) * .75;

def dist50 = HighestAll(AbsValue(MidLine - price)) * .5;

def dist25 = HighestAll(AbsValue(MidLine - price)) * .25;


plot Upper100 = MidLine + dist100;

plot Lower100 = MidLine - dist100;

plot Upper75 = MidLine + dist75;

plot Lower75 = MidLine - dist75;

plot Upper50 = MidLine + dist50;

plot Lower50 = MidLine - dist50;

plot Upper25 = MidLine + dist25;

plot Lower25 = MidLine - dist25;


MidLine.SetDefaultColor(color.light_gray);

Upper100.SetDefaultColor(color.dark_red);

Lower100.SetDefaultColor(color.dark_green);

Upper75.SetDefaultColor(color.red);

Lower75.SetDefaultColor(color.green);

Upper50.SetDefaultColor(color.light_red);

Lower50.SetDefaultColor(color.light_green);

Upper25.SetDefaultColor(color.light_gray);

Lower25.SetDefaultColor(color.light_gray);


def style = curve.medium_dash;

Upper75.setstyle(style);

Lower75.setstyle(style);

Upper25.setstyle(style);

Lower25.setstyle(style);


def style2 = curve.long_dash;

Upper100.setstyle(style2);

Lower100.setstyle(style2);

Upper50.setstyle(style2);

Lower50.setstyle(style2);

midline.setstyle(style2);


addcloud(Lower100, Lower75, color.dark_green, color.dark_GREEN);

addcloud(Lower75, Lower50, color.green, color.green);

addcloud(Lower50, lower25, color.light_green, color.light_GREEN);

addcloud(lower25, upper25, color.white, color.white);

addcloud(upper25, upper50, color.light_RED, color.light_RED);

addcloud(upper50, upper75, color.red, color.red);

addcloud(upper75, upper100, color.dark_red, color.dark_red);




Now we have quarter increments from the full deviation to either side, allowing the user to see additional support and resistance in between the main channels. Also color coded for easier interpretation.




We take the code from the original Linear Regression Channel Study:

input price = close;


plot MiddleLR = InertiaAll(price);

def dist = HighestAll(AbsValue(MiddleLR - price)) * 0.5;

plot UpperLR = MiddleLR + dist;

plot LowerLR = MiddleLR - dist;


MiddleLR.setDefaultColor(GetColor(1));

UpperLR.setDefaultColor(GetColor(1));

LowerLR.setDefaultColor(GetColor(1));