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 |

linear regression Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
danielbender
Posted : Friday, January 20, 2006 3:55:57 PM
Registered User
Joined: 1/14/2006
Posts: 436
can I use the linear regression formula in a pcf or quickscan. I want to use it to see if the slope is positive for the equity over the last 3 to 6 months ... thank you ... dan
Bruce_L
Posted : Friday, January 20, 2006 4:39:36 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
Yes. You may wish to review the following:

Using Linear Regression vs Classical Peaks/Valleys for Divergence Analysis
Spotting trend changes using linear regression channel sorts
Using Linear Regression Sorts to Help Spot Divergences

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
danielbender
Posted : Friday, January 20, 2006 4:57:18 PM
Registered User
Joined: 1/14/2006
Posts: 436
Bruce,

Not sure my last email went thru. Please give me the equation to put into the PCF that will generate the slope for a 60 daylinear regression line.

Thank you
Bruce_L
Posted : Friday, January 20, 2006 5:24:31 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
Please try the following:

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

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
danielbender
Posted : Friday, January 20, 2006 7:02:02 PM
Registered User
Joined: 1/14/2006
Posts: 436
Bruce. Thank you .... would you also provide a 120 day linear regression equation? That would save me some time.

Dan Bender

Bruce_L
Posted : Friday, January 20, 2006 7:04:50 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
Please try the following:

(59.5 * C + 58.5 * C1 + 57.5 * C2 + 56.5 * C3 + 55.5 * C4 + 54.5 * C5 + 53.5 * C6 + 52.5 * C7 + 51.5 * C8 + 50.5 * C9 + 49.5 * C10 + 48.5 * C11 + 47.5 * C12 + 46.5 * C13 + 45.5 * C14 + 44.5 * C15 + 43.5 * C16 + 42.5 * C17 + 41.5 * C18 + 40.5 * C19 + 39.5 * C20 + 38.5 * C21 + 37.5 * C22 + 36.5 * C23 + 35.5 * C24 + 34.5 * C25 + 33.5 * C26 + 32.5 * C27 + 31.5 * C28 + 30.5 * C29 + 29.5 * C30 + 28.5 * C31 + 27.5 * C32 + 26.5 * C33 + 25.5 * C34 + 24.5 * C35 + 23.5 * C36 + 22.5 * C37 + 21.5 * C38 + 20.5 * C39 + 19.5 * C40 + 18.5 * C41 + 17.5 * C42 + 16.5 * C43 + 15.5 * C44 + 14.5 * C45 + 13.5 * C46 + 12.5 * C47 + 11.5 * C48 + 10.5 * C49 + 9.5 * C50 + 8.5 * C51 + 7.5 * C52 + 6.5 * C53 + 5.5 * C54 + 4.5 * C55 + 3.5 * C56 + 2.5 * C57 + 1.5 * C58 + 0.5 * C59 - 0.5 * C60 - 1.5 * C61 - 2.5 * C62 - 3.5 * C63 - 4.5 * C64 - 5.5 * C65 - 6.5 * C66 - 7.5 * C67 - 8.5 * C68 - 9.5 * C69 - 10.5 * C70 - 11.5 * C71 - 12.5 * C72 - 13.5 * C73 - 14.5 * C74 - 15.5 * C75 - 16.5 * C76 - 17.5 * C77 - 18.5 * C78 - 19.5 * C79 - 20.5 * C80 - 21.5 * C81 - 22.5 * C82 - 23.5 * C83 - 24.5 * C84 - 25.5 * C85 - 26.5 * C86 - 27.5 * C87 - 28.5 * C88 - 29.5 * C89 - 30.5 * C90 - 31.5 * C91 - 32.5 * C92 - 33.5 * C93 - 34.5 * C94 - 35.5 * C95 - 36.5 * C96 - 37.5 * C97 - 38.5 * C98 - 39.5 * C99 - 40.5 * C100 - 41.5 * C101 - 42.5 * C102 - 43.5 * C103 - 44.5 * C104 - 45.5 * C105 - 46.5 * C106 - 47.5 * C107 - 48.5 * C108 - 49.5 * C109 - 50.5 * C110 - 51.5 * C111 - 52.5 * C112 - 53.5 * C113 - 54.5 * C114 - 55.5 * C115 - 56.5 * C116 - 57.5 * C117 - 58.5 * C118 - 59.5 * C119) / 143990

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
danielbender
Posted : Friday, January 20, 2006 7:41:30 PM
Registered User
Joined: 1/14/2006
Posts: 436
Bruce,

I tried the formula for 60d linear regression on IMB chart. Slope of IBM over 60d is negative. Value from your formula is 83 or so. 83 seems to represent the price of the last point of the linear regression, not the slope. Would you please provide the PCF formula for the slope of the linear regression lines for both 60 day and 120 days.

Thank you ... Dan Bender
Bruce_L
Posted : Friday, January 20, 2006 10:12:53 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
You might wish to retry the formula again. I just copied, pasted and tried it for IBM. The result of the formula itself for the 60-Period Linear Regression Slope Formula for IMB is -$.02/day (agreeing with the visible negative slope). You may be looking in the wrong place since the value of the endpoint of the Linear Regression is 84.04 (which you could get by multiplying the slope formula by 29.5 and adding it to the value of the mid-point of the Linear Regression, AVGC60).

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
danielbender
Posted : Monday, January 23, 2006 11:53:47 AM
Registered User
Joined: 1/14/2006
Posts: 436
Bruce

I put the formula into a PCF, hit test, changed symbol to IBM, and received the value of 84.05. What am I doing wrong?

Thank you ... Dan
Craig_S
Posted : Monday, January 23, 2006 11:55:14 AM


Worden Trainer

Joined: 10/1/2004
Posts: 18,819
Post the formula you are using here, please.

- Craig
Here to Help!
danielbender
Posted : Monday, January 23, 2006 12:33:17 PM
Registered User
Joined: 1/14/2006
Posts: 436
Its the one you gave me on Friday.

(59.5 * C + 58.5 * C1 + 57.5 * C2 + 56.5 * C3 + 55.5 * C4 + 54.5 * C5 + 53.5 * C6 + 52.5 * C7 + 51.5 * C8 + 50.5 * C9 + 49.5 * C10 + 48.5 * C11 + 47.5 * C12 + 46.5 * C13 + 45.5 * C14 + 44.5 * C15 + 43.5 * C16 + 42.5 * C17 + 41.5 * C18 + 40.5 * C19 + 39.5 * C20 + 38.5 * C21 + 37.5 * C22 + 36.5 * C23 + 35.5 * C24 + 34.5 * C25 + 33.5 * C26 + 32.5 * C27 + 31.5 * C28 + 30.5 * C29 + 29.5 * C30 + 28.5 * C31 + 27.5 * C32 + 26.5 * C33 + 25.5 * C34 + 24.5 * C35 + 23.5 * C36 + 22.5 * C37 + 21.5 * C38 + 20.5 * C39 + 19.5 * C40 + 18.5 * C41 + 17.5 * C42 + 16.5 * C43 + 15.5 * C44 + 14.5 * C45 + 13.5 * C46 + 12.5 * C47 + 11.5 * C48 + 10.5 * C49 + 9.5 * C50 + 8.5 * C51 + 7.5 * C52 + 6.5 * C53 + 5.5 * C54 + 4.5 * C55 + 3.5 * C56 + 2.5 * C57 + 1.5 * C58 + 0.5 * C59 - 0.5 * C60 - 1.5 * C61 - 2.5 * C62 - 3.5 * C63 - 4.5 * C64 - 5.5 * C65 - 6.5 * C66 - 7.5 * C67 - 8.5 * C68 - 9.5 * C69 - 10.5 * C70 - 11.5 * C71 - 12.5 * C72 - 13.5 * C73 - 14.5 * C74 - 15.5 * C75 - 16.5 * C76 - 17.5 * C77 - 18.5 * C78 - 19.5 * C79 - 20.5 * C80 - 21.5 * C81 - 22.5 * C82 - 23.5 * C83 - 24.5 * C84 - 25.5 * C85 - 26.5 * C86 - 27.5 * C87 - 28.5 * C88 - 29.5 * C89 - 30.5 * C90 - 31.5 * C91 - 32.5 * C92 - 33.5 * C93 - 34.5 * C94 - 35.5 * C95 - 36.5 * C96 - 37.5 * C97 - 38.5 * C98 - 39.5 * C99 - 40.5 * C100 - 41.5 * C101 - 42.5 * C102 - 43.5 * C103 - 44.5 * C104 - 45.5 * C105 - 46.5 * C106 - 47.5 * C107 - 48.5 * C108 - 49.5 * C109 - 50.5 * C110 - 51.5 * C111 - 52.5 * C112 - 53.5 * C113 - 54.5 * C114 - 55.5 * C115 - 56.5 * C116 - 57.5 * C117 - 58.5 * C118 - 59.5 * C119) / 143990
Bruce_L
Posted : Monday, January 23, 2006 12:48:03 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
That is the formula given for the slope of the 120-Period Linear Regression. When I paste the formula into the Editing Formula window and select Test with IBM as the test symbol, the result is 0.04 (agreeing with the slightly positive slope of the Linear Regression plot on the chart). Based on your description of what you said you just did, your results do not make sense to me at all. All I can suggest is to recopy the formulas directly from this topic and try again.

PS - When I do the same for the for the shorter 60-Period formula from my Friday, January 20, 2006 5:24:31 PM post, I get a result of -0.02.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Craig_S
Posted : Monday, January 23, 2006 12:50:04 PM


Worden Trainer

Joined: 10/1/2004
Posts: 18,819
... this formula is giving you a value of 80+ on IBM?

There must be a mixup somewhere. Double check your PCF... it cannot contain the code you have above.

Friday's close returns 0.04 for IBM using the above formula.

You must be looking at a different formula than the one above.

- Craig
Here to Help!
danielbender
Posted : Monday, January 23, 2006 1:26:40 PM
Registered User
Joined: 1/14/2006
Posts: 436
Sorry. You were correct - was using another formula. May I impose on you for the 120day Linear Regression Formula?

Thank you... Dan
Bruce_L
Posted : Monday, January 23, 2006 1:57:08 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
My Friday, January 20, 2006 5:24:31 PM post contains the formula for a 60-Period Linear Regression Slope.

My Friday, January 20, 2006 7:04:50 PM post contains the formula for a 120-Period Linear Regression Slope.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
tomkilker
Posted : Thursday, April 20, 2006 4:06:49 AM
Registered User
Joined: 12/7/2004
Posts: 1
Could you tell me the source of the linear regression formulas or give me a reference or explanation how it relates to least squares best fit?

Thanks

Tom Kilker
Bruce_L
Posted : Thursday, April 20, 2006 6:28:06 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
tomkilker,
Please read through the topics referenced in my Friday, January 20, 2006 4:39:36 PM post. You may also wish to review the following:

Need help writing a PCF for r-squared
RSquared...reconciling below formula with spreadsheet

The formulas are accurate (the results match those of both more complicated formulas and other programs making these calculations), but lessons in Statistics fall outside the scope of the training provided here on how to use TeleChart. This is not to say the subject is not discussed to some extent in the forums by both the trainers and other users, so you might wish to search for additional material within the forums:

Learn how to use the forums: post a new topic, reply, Search existing topics

If that does not answer your question, you can find additional information on Linear Regressions and Least Squares using an internet search (and it is always possible somebody else might provide an answer here with more details).

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
auchang929
Posted : Sunday, December 6, 2009 2:41:59 PM
Gold Customer Gold Customer

Joined: 12/5/2005
Posts: 63
Bruce, please help me to write a PCF:
1.  The slope of 63 bar period linear regression on price (close price)
Thank you!
Bruce_L
Posted : Monday, December 7, 2009 8:54:25 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
auchang929,
Please try the following Personal Criteria Formula:

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

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
auchang929
Posted : Monday, December 7, 2009 8:02:23 PM
Gold Customer Gold Customer

Joined: 12/5/2005
Posts: 63
Thank you!  Bruce
Bruce_L
Posted : Tuesday, December 8, 2009 8:26:44 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
auchang929,
You're welcome. Our pleasure.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Hindsight
Posted : Monday, April 19, 2010 5:54:49 PM

Registered User
Joined: 10/7/2004
Posts: 5
Hey, Bruce.  I'd like to create a custom 13-day Linear Regression PCF for use in an EasyScan.  I've taken a look at the code you've created for the other users, above, but am at a loss on how to convert it to a 13-day timeframe.  Could you coach me on how to modify the above to meet my needs?

Ideally, I'd like the measure of the slope to be my output for use in EasyScan.  Given that the above code, when used in a chart, outputs a line that vissually reflects the price trend over that period, would I have to use two 13-day linear regression calculations offset by say, 13 days, and subtract the end-of-period calculation from the beginning of period calculation to get the slope?  For instance, > 0 would suggest a positve slope and < 0 would suggest negative slope.

Thanks,
-Mike.
Bruce_L
Posted : Tuesday, April 20, 2010 8:24:44 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
Hindsight,
A formula for the right endpoint of a 13-Period Linear Regression would be:

AVGC13 + 6 * (6 * C + 5 * C1 + 4 * C2 + 3 * C3 + 2 * C4 + C5 - C7 - 2 * C8 - 3 * C9 - 4 * C10 - 5 * C11 - 6 * C12) / 182

The last bit starting with the open parenthesis is the formula for the slope:

(6 * C + 5 * C1 + 4 * C2 + 3 * C3 + 2 * C4 + C5 - C7 - 2 * C8 - 3 * C9 - 4 * C10 - 5 * C11 - 6 * C12) / 182

So if that is positive, the 13-Period Linear Regression Line would be sloping up and if it is negative, it is sloping down.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Hindsight
Posted : Wednesday, April 21, 2010 12:23:49 PM

Registered User
Joined: 10/7/2004
Posts: 5
Bruce -- This is very helpful.  Thank you!

I'm now thinking that, instead of writing this as a PCF that I could call in an EasyScan, that I'll instead use it as a custom indicator in a chart along with a 5 period simple moving average.  Doing this, I can sort based on above/below 5SMA and easily accomplish my objective.

So, again, thanks for your help.

-Mike.
Bruce_L
Posted : Wednesday, April 21, 2010 12:25:34 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
Hindsight,
You're welcome. I'm happy to read you were able to use my response to come up with something even more useful.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Hindsight
Posted : Wednesday, April 21, 2010 12:28:25 PM

Registered User
Joined: 10/7/2004
Posts: 5
Hey, Bruce.  I just noticed we have the same "Joined" date: 10/07/2004 . . .

     :o)
Bruce_L
Posted : Wednesday, April 21, 2010 12:34:00 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
Hindsight,
I could be wrong, but I don't think that's quite as coincidental as it seems. I think that's the join date for anybody outside of initial forum testing that had a non-forum account of any type with Worden Brothers when the forums were created. There are only nine accounts with an earlier join date.

-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.