I'm trying to find a way to scan for stocks that have a positive TTM Lrc slope. I've tried using LinearRegressionSlope and copying some scripts I've found during my exhausting search to no avail.
Question: How do go about finding the slope of TTM Lrc?
Thank you for you time,
Mike
to find a slope, you look for a change in y over a change in x.
(y-y) / (x-x)
a change in price, over x bars.
then reduce it down to a price change over 1 bar.
the space between 2 adjacent bars is 1.
lrc is a straight line, so the change between the last 2 bars will work.
if what you want is to know if a straight line is inclining or declining, then subtract the previous price from the current price.
then check if the number is > 0.
to find a slope, compare 2 values of the LR plot from the TTM_LRC study.
just because the code is hidden, doesn't mean you can't reference the variables.
look up the inputs and plots for the study, to make sure you understand what does what.
https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/T-U/TTM-LRC
here is a simple formula, for reading the LR plot.
you use the study name, () , then a period, and the plot name.
def lrc = TTM_LRC().LR;
i included all the input parameters in my study, so it can be setup as desired.
then compare 2 values,
def lrc_slope = lrc - lrc[1];
this is a lower study for testing. but will work as a scan
Code:
#ttm_lrc_slope
#https://usethinkscript.com/threads/find-slope-of-ttm-lrc.17482/
#Find slope of TTM Lrc
declare lower;
# TTM_LRC
input price = CLOSE;
input length = 38;
input beginDate = 0;
input beginTime = 0;
input numDevDn1 = -1.0;
input numDevDn2 = -2.0;
input numDevUp1 = 1.0;
input numDevUp2 = 2.0;
input extLeft = No;
input extRight = Yes;
def lrc = TTM_LRC(price, length, beginDate, beginTime, numDevDn1, numDevDn2, numDevUp1, numDevUp2, extLeft, extRight ).LR;
def lrc_slope = lrc - lrc[1];
def isup = if isnan(lrc) then 0 else if lrc_slope > 0 then 1 else 0;
# true if inclining slope. false if declining
plot z = isup;
#