Linear Regression MTF for ThinkorSwim

british43

New member
I'm trying to create a linear regression MTF but have a problem with plotting the upper and lower lines. Any help would be greatly appreciate.

Code:
def fourHours = close(period = AggregationPeriod.FOUR_HOURS);
def day = close(period = AggregationPeriod.DAY);
def week = close(period = AggregationPeriod.WEEK);
def month = close(period = AggregationPeriod.MONTH);
def period=yes;

plot data=close;

input price = close;
input deviations = .8;

input length = 200; #set your channel lookback period here.
input opacity = 50;

def regression = InertiaAll(price, length);
def stdDeviation = StDevAll(price, length);

plot UpperLine = regression + deviations * stdDeviation;
plot LowerLine = regression - deviations * stdDeviation;
def dayreg=InertiaAll(price-day[1],length);
def daysd= StDevAll(price-day[1],length);

plot dayupper=dayreg+deviations*daysd;
 
Last edited by a moderator:

XeoNoX

Well-known member
VIP
you can just add this study how many ever times you need it
the Week,Day,Hr,Min is configurable through the menu
remember your chart agreggation must be equal to or smaller than what ever timeframe you choose to configure the script for

Linear Regression MTF

Code:
#Linear Regression MTF by XeoNoX via usethinkscript.com
#the Week,Day,Hr,Min is configurable through the menu
#remember your chart agreggation must be equal to or smaller than whatever timeframe you choose to configure the script for
input TimeFrame = AggregationPeriod.DAY;
def price = (close(period =TimeFrame));
input deviations = .8;
input length = 200; #set your channel lookback period here.
input opacity = 50;
def regression = InertiaAll(price, length);
def stdDeviation = StDevAll(price, length);
plot UpperLine = regression + deviations * stdDeviation;
plot LowerLine = regression - deviations * stdDeviation;
def dayreg=InertiaAll(price-close(period =TimeFrame)[1],length);
def daysd= StDevAll(price-close(period =TimeFrame)[1],length);
plot dayupper=dayreg+deviations*daysd;
 
Last edited:

Similar threads

Top