Welcome Guest, please sign in to participate in a discussion. Search | Active Topics |

Slope of moving linear regression line Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
rickbw
Posted : Monday, June 8, 2015 1:02:39 PM
Registered User
Joined: 10/10/2004
Posts: 30

Is there a way to code the slope of a moving linear regression line?  Thx

Bruce_L
Posted : Monday, June 8, 2015 2:38:17 PM


Worden Trainer

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

You can add a rate of change indicator to the chart and then change the data source of the ROC indicator to use the moving linear regression instead of price.

Change Data Source (3:38)

The period of the ROC indicator is going to determine the slope over Period bars. So setting the period to 1 is going to give you the slope from one bar to the next.



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
rickbw
Posted : Monday, June 8, 2015 3:15:09 PM
Registered User
Joined: 10/10/2004
Posts: 30

Thank you Bruce, I watched the video and was able to plot the slope in the chart window.  Is there a way to be able to create this in a PCF so that I could use it in a watchlist when the slope is above 0 I could see it?  I am interested in the MovLinR 30.  Thanks in advance

Bruce_L
Posted : Monday, June 8, 2015 4:03:21 PM


Worden Trainer

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

The following Indicator Formula assumes you are interested in the 1 period net rate of change in the 30 period moving linear regression.

(59 * C - 87 * AVGC29.1 + 28 * C30) / 465

Using Linear Regression vs Classical Peaks/Valleys for Divergence Analysis



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
diceman
Posted : Tuesday, June 9, 2015 1:39:15 PM
Registered User
Joined: 1/28/2005
Posts: 6,049

QUOTE (Bruce_L)

The following Indicator Formula assumes you are interested in the 1 period net rate of change in the 30 period moving linear regression.

(59 * C - 87 * AVGC29.1 + 28 * C30) / 465

Using Linear Regression vs Classical Peaks/Valleys for Divergence Analysis

 

Could you do one for an 8, 20, and 100 period.

 

Thanks

 

Bruce_L
Posted : Tuesday, June 9, 2015 1:59:42 PM


Worden Trainer

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

1-Period Net Change in 8-Period Moving Linear Regression:

(5 * C - 7 * AVGC7.1 + 2 * C8) / 12

1-Period Net Change in 20-Period Moving Linear Regression:

(13 * C - 19 * AVGC19.1 + 6 * C20) / 70

1-Period Net Change in 100-Period Moving Linear Regression:

(199 * C - 297 * AVGC99.1 + 98 * C100) / 5050

The generalized form would appear to be as follows. I thought I did this calculation in the forums previously, but I don't seem to be able to find it.

((P * 2 - 1) * C - (P * 3 - 3) * AVGC(P-1).1 + (P - 2) * CP) / (P * (P + 1) / 2)



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
rickbw
Posted : Wednesday, June 17, 2015 2:45:19 PM
Registered User
Joined: 10/10/2004
Posts: 30

Bruce,

I wanted to do the calculation for an 1 period change in a 5 period moving linear regression, but unless I'm thick I can't follow the fomula.  It makes sense on the 100 period;

(P * 2 - 1) or (100 * 2 - 1)  = 199

&

C - (P * 3 - 3) or (100 * 3- 3) = 297 

but if I do the same for an 8 period;

 (P * 2 - 1) or (8 * 2 - 1) = 15     (your formula above shows 5

C - (P * 3 - 3) or (8 * 3 - 3) = 21   (your formula above shows 7

 

Ultimately I want an 5 period, can you help me understand what I am missing?

Thx

Bruce_L
Posted : Wednesday, June 17, 2015 2:52:17 PM


Worden Trainer

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

Substituting 5 for P results in the following Indicator Formula.

((5 * 2 - 1) * C - (5 * 3 - 3) * AVGC4.1 + (5 - 2) * C5) / (5 * (5 + 1) / 2)

Which can be simplifed down to the following.

(9 * C - 12 * AVGC4.1 + 3 * C5) / 15

Substituting 8 for P results in the following Indicator Formula.

((8 * 2 - 1) * C - (8 * 3 - 3) * AVGC7.1 + (8 - 2) * C8) / (8 * (8 + 1) / 2)

Which can be simplified down to the following.

(15 * C - 21 * AVGC7.1 + 6 * C8) / 36

Which can be further simplified to the following (by dividing by the numerator and denominator by 3).

(5 * C - 7 * AVGC7.1 + 2 * C8) / 12



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
rickbw
Posted : Wednesday, June 17, 2015 6:05:53 PM
Registered User
Joined: 10/10/2004
Posts: 30

Thanks Bruce - got it.  I was not dividing the numerator and denominator.

Bruce_L
Posted : Wednesday, June 17, 2015 6:09:50 PM


Worden Trainer

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

You don't need to divide the numerator and denominator. Even the long formula resulting from just substituting the period for P should work (although it is probably less efficient than the other two formulas).



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
CFGBull
Posted : Wednesday, September 14, 2016 12:30:39 PM
Gold Customer Gold Customer

Joined: 8/14/2014
Posts: 1

I am new to these formulas and still learning to write them and was wondering how to have an up/down boolean formula to flash up or down  based on the change(+ or -) in moving linear regression slope over a certain time. (ie. 75 and 100 for a five-minute period)..  I tried using the rate of change on the MLR but would like to simplify it further to determine when the slope changes positive or negative. Thanks.

Bruce_L
Posted : Thursday, September 15, 2016 9:12:10 AM


Worden Trainer

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

Add a 2-period moving average to the MLR. You can then click on the MLR and select Create Scan Condtiion for the MLR crossing through its moving average.

Create Conditions from Your Chart (5:25)

When the MLR is crossing down through its moving average then the slope has changed from up to down.

When the MLR is crossing up through its moving average then the slope has changed from moving down to up.



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