Download software Tutorial videos
Subscription & data-feed pricing Class schedule


New account application Trading resources
Margin rates Stock & option commissions

Attention: Discussion forums are read-only for extended maintenance until further notice.
Welcome Guest, please sign in to participate in a discussion. Search | Active Topics |

finding stocks with nearly flat linear regression line Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
donv98
Posted : Thursday, June 12, 2014 4:28:43 PM
Registered User
Joined: 7/29/2010
Posts: 417

Nearly flat meaning very low slope either up or down on a daily chart or longer with a minimum period of say 50.

 

How would I create this?

 

Many thanks for any help.

Bruce_L
Posted : Thursday, June 12, 2014 4:49:43 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

It depends entirely on your particular definition of "very low slope".

The raw 50-period linear regression slope can be expressed as:

Using Linear Regression vs Classical Peaks/Valleys for Divergence Analysis

(24.5 * C + 23.5 * C1 + 22.5 * C2 + 21.5 * C3 + 20.5 * C4 + 19.5 * C5 + 18.5 * C6 + 17.5 * C7 + 16.5 * C8 + 15.5 * C9 + 14.5 * C10 + 13.5 * C11 + 12.5 * C12 + 11.5 * C13 + 10.5 * C14 + 9.5 * C15 + 8.5 * C16 + 7.5 * C17 + 6.5 * C18 + 5.5 * C19 + 4.5 * C20 + 3.5 * C21 + 2.5 * C22 + 1.5 * C23 + .5 * C24 - .5 * C25 - 1.5 * C26 - 2.5 * C27 - 3.5 * C28 - 4.5 * C29 - 5.5 * C30 - 6.5 * C31 - 7.5 * C32 - 8.5 * C33 - 9.5 * C34 - 10.5 * C35 - 11.5 * C36 - 12.5 * C37 - 13.5 * C38 - 14.5 * C39 - 15.5 * C40 - 16.5 * C41 - 17.5 * C42 - 18.5 * C43 - 19.5 * C44 - 20.5 * C45 - 21.5 * C46 - 22.5 * C47 - 23.5 * C48 - 24.5 * C49) / 10412.5

And converting this from a daily formula into an annualized percent slope would result in:

100 * (EXP(253 * (24.5 * LOG(C ) + 23.5 * LOG(C1) + 22.5 * LOG(C2) + 21.5 * LOG(C3) + 20.5 * LOG(C4) + 19.5 * LOG(C5) + 18.5 * LOG(C6) + 17.5 * LOG(C7) + 16.5 * LOG(C8) + 15.5 * LOG(C9) + 14.5 * LOG(C10) + 13.5 * LOG(C11) + 12.5 * LOG(C12) + 11.5 * LOG(C13) + 10.5 * LOG(C14) + 9.5 * LOG(C15) + 8.5 * LOG(C16) + 7.5 * LOG(C17) + 6.5 * LOG(C18) + 5.5 * LOG(C19) + 4.5 * LOG(C20) + 3.5 * LOG(C21) + 2.5 * LOG(C22) + 1.5 * LOG(C23) + .5 * LOG(C24) - .5 * LOG(C25) - 1.5 * LOG(C26) - 2.5 * LOG(C27) - 3.5 * LOG(C28) - 4.5 * LOG(C29) - 5.5 * LOG(C30) - 6.5 * LOG(C31) - 7.5 * LOG(C32) - 8.5 * LOG(C33) - 9.5 * LOG(C34) - 10.5 * LOG(C35) - 11.5 * LOG(C36) - 12.5 * LOG(C37) - 13.5 * LOG(C38) - 14.5 * LOG(C39) - 15.5 * LOG(C40) - 16.5 * LOG(C41) - 17.5 * LOG(C42) - 18.5 * LOG(C43) - 19.5 * LOG(C44) - 20.5 * LOG(C45) - 21.5 * LOG(C46) - 22.5 * LOG(C47) - 23.5 * LOG(C48) - 24.5 * LOG(C49)) / 10412.5) - 1)

But what makes the slope "very low"? Does the absolute value of one of the above need to be less than some arbitrary value? Does the absolute range of the linear regression line need to be less than a certain percentage of the total range over some longer period of time? Something else entirely?



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
diceman
Posted : Friday, June 13, 2014 9:33:59 AM
Registered User
Joined: 1/28/2005
Posts: 6,049

Bruce

Id like 21, 42, and 63 day versions of the annualized slope.

 

Thanks

Bruce_L
Posted : Friday, June 13, 2014 11:00:27 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

21-Period Linear Regression Annualized Slope:

100 * (EXP(253 * (10 * LOG(C ) + 9 * LOG(C1) + 8 * LOG(C2) + 7 * LOG(C3) + 6 * LOG(C4) + 5 * LOG(C5) + 4 * LOG(C6) + 3 * LOG(C7) + 2 * LOG(C8) + LOG(C9) - LOG(C11) - 2 * LOG(C12) - 3 * LOG(C13) - 4 * LOG(C14) - 5 * LOG(C15) - 6 * LOG(C16) - 7 * LOG(C17) - 8 * LOG(C18) - 9 * LOG(C19) - 10 * LOG(C20)) / 770) - 1)

42-Period Linear Regression Annualized Slope:

100 * (EXP(253 * (20.5 * LOG(C ) + 19.5 * LOG(C1) + 18.5 * LOG(C2) + 17.5 * LOG(C3) + 16.5 * LOG(C4) + 15.5 * LOG(C5) + 14.5 * LOG(C6) + 13.5 * LOG(C7) + 12.5 * LOG(C8) + 11.5 * LOG(C9) + 10.5 * LOG(C10) + 9.5 * LOG(C11) + 8.5 * LOG(C12) + 7.5 * LOG(C13) + 6.5 * LOG(C14) + 5.5 * LOG(C15) + 4.5 * LOG(C16) + 3.5 * LOG(C17) + 2.5 * LOG(C18) + 1.5 * LOG(C19) + 0.5 * LOG(C20) - 0.5 * LOG(C21) - 1.5 * LOG(C22) - 2.5 * LOG(C23) - 3.5 * LOG(C24) - 4.5 * LOG(C25) - 5.5 * LOG(C26) - 6.5 * LOG(C27) - 7.5 * LOG(C28) - 8.5 * LOG(C29) - 9.5 * LOG(C30) - 10.5 * LOG(C31) - 11.5 * LOG(C32) - 12.5 * LOG(C33) - 13.5 * LOG(C34) - 14.5 * LOG(C35) - 15.5 * LOG(C36) - 16.5 * LOG(C37) - 17.5 * LOG(C38) - 18.5 * LOG(C39) - 19.5 * LOG(C40) - 20.5 * LOG(C41)) / 6170.5) - 1)

63-Period Linear Regression Annualized Slope:

100 * (EXP(253 * (31 * LOG(C ) + 30 * LOG(C1) + 29 * LOG(C2) + 28 * LOG(C3) + 27 * LOG(C4) + 26 * LOG(C5) + 25 * LOG(C6) + 24 * LOG(C7) + 23 * LOG(C8) + 22 * LOG(C9) + 21 * LOG(C10) + 20 * LOG(C11) + 19 * LOG(C12) + 18 * LOG(C13) + 17 * LOG(C14) + 16 * LOG(C15) + 15 * LOG(C16) + 14 * LOG(C17) + 13 * LOG(C18) + 12 * LOG(C19) + 11 * LOG(C20) + 10 * LOG(C21) + 9 * LOG(C22) + 8 * LOG(C23) + 7 * LOG(C24) + 6 * LOG(C25) + 5 * LOG(C26) + 4 * LOG(C27) + 3 * LOG(C28) + 2 * LOG(C29) + LOG(C30) - LOG(C32) - 2 * LOG(C33) - 3 * LOG(C34) - 4 * LOG(C35) - 5 * LOG(C36) - 6 * LOG(C37) - 7 * LOG(C38) - 8 * LOG(C39) - 9 * LOG(C40) - 10 * LOG(C41) - 11 * LOG(C42) - 12 * LOG(C43) - 13 * LOG(C44) - 14 * LOG(C45) - 15 * LOG(C46) - 16 * LOG(C47) - 17 * LOG(C48) - 18 * LOG(C49) - 19 * LOG(C50) - 20 * LOG(C51) - 21 * LOG(C52) - 22 * LOG(C53) - 23 * LOG(C54) - 24 * LOG(C55) - 25 * LOG(C56) - 26 * LOG(C57) - 27 * LOG(C58) - 28 * LOG(C59) - 29 * LOG(C60) - 30 * LOG(C61) - 31 * LOG(C62)) / 20832) - 1)



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
donv98
Posted : Friday, June 13, 2014 3:40:58 PM
Registered User
Joined: 7/29/2010
Posts: 417

HI Bruce,

  Many thanks for your response.

I am trying to  use the easy scan to find stocks that are currently consolidating or basing.

I have tried several approaches and continue to experiment to find scans that give me good results.

The  linear regression line is my attempt at a new approach.

I don't understand what annualized slope is.

In answer to your questions about very low slope, I can only guess. I would guess I'd like a slope less than 5 or 10 %.

 

Thank you for all of your excellent help.

 

Bruce_L
Posted : Friday, June 13, 2014 3:49:32 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

You might want to try taking the absolute value of the annualized percent change (this can be accurately used to compare slopes between symbols no matter what their price):

100 * ABS(EXP(253 * (24.5 * LOG(C ) + 23.5 * LOG(C1) + 22.5 * LOG(C2) + 21.5 * LOG(C3) + 20.5 * LOG(C4) + 19.5 * LOG(C5) + 18.5 * LOG(C6) + 17.5 * LOG(C7) + 16.5 * LOG(C8) + 15.5 * LOG(C9) + 14.5 * LOG(C10) + 13.5 * LOG(C11) + 12.5 * LOG(C12) + 11.5 * LOG(C13) + 10.5 * LOG(C14) + 9.5 * LOG(C15) + 8.5 * LOG(C16) + 7.5 * LOG(C17) + 6.5 * LOG(C18) + 5.5 * LOG(C19) + 4.5 * LOG(C20) + 3.5 * LOG(C21) + 2.5 * LOG(C22) + 1.5 * LOG(C23) + .5 * LOG(C24) - .5 * LOG(C25) - 1.5 * LOG(C26) - 2.5 * LOG(C27) - 3.5 * LOG(C28) - 4.5 * LOG(C29) - 5.5 * LOG(C30) - 6.5 * LOG(C31) - 7.5 * LOG(C32) - 8.5 * LOG(C33) - 9.5 * LOG(C34) - 10.5 * LOG(C35) - 11.5 * LOG(C36) - 12.5 * LOG(C37) - 13.5 * LOG(C38) - 14.5 * LOG(C39) - 15.5 * LOG(C40) - 16.5 * LOG(C41) - 17.5 * LOG(C42) - 18.5 * LOG(C43) - 19.5 * LOG(C44) - 20.5 * LOG(C45) - 21.5 * LOG(C46) - 22.5 * LOG(C47) - 23.5 * LOG(C48) - 24.5 * LOG(C49)) / 10412.5) - 1)

You will want to check for it to be below some arbitrary value. So if you wanted the 50-day linear regression slope to be less than 5% if it were extended over the course of an entire year, you would add a < 5 to the end:

100 * ABS(EXP(253 * (24.5 * LOG(C ) + 23.5 * LOG(C1) + 22.5 * LOG(C2) + 21.5 * LOG(C3) + 20.5 * LOG(C4) + 19.5 * LOG(C5) + 18.5 * LOG(C6) + 17.5 * LOG(C7) + 16.5 * LOG(C8) + 15.5 * LOG(C9) + 14.5 * LOG(C10) + 13.5 * LOG(C11) + 12.5 * LOG(C12) + 11.5 * LOG(C13) + 10.5 * LOG(C14) + 9.5 * LOG(C15) + 8.5 * LOG(C16) + 7.5 * LOG(C17) + 6.5 * LOG(C18) + 5.5 * LOG(C19) + 4.5 * LOG(C20) + 3.5 * LOG(C21) + 2.5 * LOG(C22) + 1.5 * LOG(C23) + .5 * LOG(C24) - .5 * LOG(C25) - 1.5 * LOG(C26) - 2.5 * LOG(C27) - 3.5 * LOG(C28) - 4.5 * LOG(C29) - 5.5 * LOG(C30) - 6.5 * LOG(C31) - 7.5 * LOG(C32) - 8.5 * LOG(C33) - 9.5 * LOG(C34) - 10.5 * LOG(C35) - 11.5 * LOG(C36) - 12.5 * LOG(C37) - 13.5 * LOG(C38) - 14.5 * LOG(C39) - 15.5 * LOG(C40) - 16.5 * LOG(C41) - 17.5 * LOG(C42) - 18.5 * LOG(C43) - 19.5 * LOG(C44) - 20.5 * LOG(C45) - 21.5 * LOG(C46) - 22.5 * LOG(C47) - 23.5 * LOG(C48) - 24.5 * LOG(C49)) / 10412.5) - 1) < 5

It seems like it would be a good place to start if you are going to try to use linear regression slope for this.



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
donv98
Posted : Friday, June 13, 2014 4:14:10 PM
Registered User
Joined: 7/29/2010
Posts: 417

Bruce,

    Thank you very much for your fine work.

I tested both <5% and <7% and both delivered results quite useful to me.

 

Don

THEBIGASS
Posted : Tuesday, December 9, 2014 6:55:30 AM
Registered User
Joined: 5/18/2009
Posts: 7

How would you turn this into a 5 day slope?  I guess if I wanted to screen for greater than 5% I just change < to >?  Or more precise i want to take a 5 day simple moving average with a slope greater than 5%.

And if I wanted to find a stock with a closing price that closed on the other side of the slope line either in the last 1 or 2 days?   Meaning, 3 days ago it was under the slope and today it is above the slope.

Technically I would want to find stocks that just recently closed above the slope line with a >5% slope AND stocks that recently closed below slopes <-5% if slopes can be measured in positive and negative slopes

You helped me before on something similar 5 years ago but it was a different version of TC and the formulas i had are lost now.  Trying to refine/rebuild it.

TIA!

Bruce_L
Posted : Tuesday, December 9, 2014 2:22:51 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

Most of the stuff in the Moving Average Trend vs Stock Price with Date topic is still applicable despite time having passed.

The formulas in this topic are for linear regression line of price slopes, not moving average slopes of any kind.

If you are looking for the 5-period moving average to have moved up more than 5%, over what time frame do you want to calculate the 5% change? Do you just want to compare the value now to the value x bars ago or do you want to calculate a linear regression slope on the moving average? 



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
THEBIGASS
Posted : Tuesday, December 9, 2014 3:05:52 PM
Registered User
Joined: 5/18/2009
Posts: 7

I think what I want is to determine the linear regression slope on the moving average. 

I had this formula which you helped me with, but it isn't narrow enough.

(C > AVGC5 AND C1 <= AVGC5.1 AND AVGC5 > AVGC5.1) OR (C < AVGC5 AND C1 >= AVGC5.1 AND AVGC5 < AVGC5.1)

I want to make sure the slope of the moving average is defined because I only want hits that had a crossover above the MA when the slope grade is positive and cross under the MA when the slope grade is negative. And I want that crossover to have happened today, or within the last 2 days. 

If we don't need to define the LRS and can do this another way, great, but based on what i read in these fora that seemed to be one way to do it that made sense to me.

Thanks for your help

Bruce_L
Posted : Tuesday, December 9, 2014 3:08:51 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

The moving average is a 5-period simple moving average, but we still need to define a period over which to calculate the linear regression slope of the moving average.

The period of the linear regression slope can be different than the period of the moving average. If you want to include all of the values over the period, the period also needs to be an even number (odd periods ignore the central value in the slope calculations).



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
THEBIGASS
Posted : Wednesday, December 10, 2014 3:30:29 AM
Registered User
Joined: 5/18/2009
Posts: 7

Thank you -. I would start with just 6 days as that is closest to 5 days we use on the EMA, and go from there. I only need to identify the slope of the 5dma to weed out hits I do not want. I only want stocks with a price that closed above the 5dma line for the first time in X days when the LRS slope of the 5dma is positive, OR stocks with a price that closed under the 5mda line for the first time in X days when the slope is negative. We can try to define the degree of the slope as > 5% or < -5% and then tweak from there but I don't think it matters too much.  X days can be 5 or 6 but I can also tweak that later.

I know that this sounds like I asking you to write a formula for me - I am sorry for that.  I have tried to research the coding but honestly its over my head. I know what I am trying to do in lay terms. Coding it so a computer can identify these patterns it is more challenging.  I think the LRS of the MA is the trick to identifying the direction of the MA line as either "pointing up" or "pointing down" as we discussed in the link you put up above.  I appreciate your guidance either way.

 

 

Bruce_L
Posted : Wednesday, December 10, 2014 10:28:53 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

The following assumes the 5 day moving average is exponential since that is what you  seem to indicate in your last post. You can delete every instance of X in XAVGC5 to use a 5 day simple moving average instead.

(100 * (EXP(253 * (5 * (LOG(XAVGC5) - LOG(XAVGC5.5)) + 3 * (LOG(XAVGC5.1) - LOG(XAVGC5.4)) + LOG(XAVGC5.2) - LOG(XAVGC5.3)) / 35) - 1) > 5 AND C >  XAVGC5 AND C1 < XAVGC5.1 AND C2 < XAVGC5.2 AND C3  < XAVGC5.3  AND C4 < XAVGC5.4  AND C5  < XAVGC5.5) OR (100 * (EXP(253 * (5 * (LOG(XAVGC5) - LOG(XAVGC5.5)) + 3 * (LOG(XAVGC5.1) - LOG(XAVGC5.4)) + LOG(XAVGC5.2) - LOG(XAVGC5.3)) / 35) - 1) < -5 AND C <  XAVGC5 AND C1 > XAVGC5.1 AND C2 > XAVGC5.2 AND C3  > XAVGC5.3  AND C4 > XAVGC5.4  AND C5  > XAVGC5.5)

Note that this does check for the annualized percent slope to be greater than 5% or less than -5%. This is pretty restrictive if you are using an exponential moving average.

The reason it is more restrictive when using an exponential moving average instead of simple moving average is that we are also checking for price to have been constantly above or below the moving average for the previous 5 bars. An exponential moving average will always move up when price is above it and will always move down when price is below it (a simple moving average could move up or down in these circumstances).

So we are checking for a positive slope when five of the six bars are down and one of the six bars is up or a negative slope when five of the sixx bbars are up and one of the six bars is down. This means the last bar must not only overcome the momentum of the first five bars, it must also reverse it enough to get the annualized percent change up to a magnitude of more than 5% per year.



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
THEBIGASS
Posted : Wednesday, December 10, 2014 2:22:15 PM
Registered User
Joined: 5/18/2009
Posts: 7

Thank you. I will give it a try. I did not mean to write EMA but I didn't see it until after I posted, I just wanted SMA.. But thanks for letting me know how to amend that.

I appreciate your help.  I will start testing it out and I hope ti gives the results I was looking for.  Thanks again.

Bruce_L
Posted : Wednesday, December 10, 2014 2:24:50 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

You're welcome.



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Users browsing this topic
Guest-1

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.