Welcome Guest, please sign in to participate in a discussion. | Search | Active Topics | |
Registered User Joined: 12/1/2004 Posts: 105
|
One endeavor that I would like to pursue is price deviation from a linear regression line. This is based on the general thought that price reverts to the mean. I have not been able to obtain the LR value at any bar location along the linear regression line. My question is: do you have any suggestions as to how I might proceed to obtain price deviation from a linear regression line?
Thank you for your assistance.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
If you are looking for the deviation along the entire line, you might want to take at look at standard error or the linear regression curve fit error (LRrms).
Need help writing a PCF for r-squared
Determining the value of a given point in a linear regression line is fairly straightforward, but can result in some rather long formula:
Using Linear Regression vs Classical Peaks/Valleys for Divergence Analysis
Let's take a 6-Period Linear Regression formula from the above topic and break it down:
AVGC6 + 2.5 * (2.5 * C + 1.5 * C1 + .5 * C2 - .5 * C3 - 1.5 * C4 - 2.5 * C5) / 17.5
This covers a time span of 6-bars with the first bar being 5 bars away from the last bar in the series.
AVGC6 is just a 6-period simple moving average. It is the value of the linear regression line in its exact center. There isn't actually a bar at the exact center as this point is 2.5 bars from either end.
Which brings us to the + 2.5 * section that comes next. We know the exact center is just the value of the moving average. So the value of the right end is going to the value of the center + 2.5 times the slope of the linear regression line from one bar to the next.
If we want to calculate the value of the left end of the linear regression, it would be - 2.5 * instead of + 2.5 *. All of the values in between can be calculated by incremented this factor by 1. So you would use + 1.5 * to get the value of linear regression at 1-bar from the right end of the linear regression line.
You can even add or subtract more than 2.5 times the slope to extend the linear regression line beyond the bars used in its calculations.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 12/1/2004 Posts: 105
|
Bruce,
I understand all you have done except this: how do I actually program the increments so that they will be included in the PCF and result in a plot of actual values for the linear regression values?
Thanks for your help.
Dempsey30338
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
I have no idea what you mean by "program the increments". The formula for just the slope itself extracted from the above formula would be:
(2.5 * C + 1.5 * C1 + .5 * C2 - .5 * C3 - 1.5 * C4 - 2.5 * C5) / 17.5
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 12/1/2004 Posts: 105
|
Bruce,
What I mean is how do I program the increments so that I end up with the LR value plotted versus the date scale. Ultimately, I would like to have an oscillator that would be the difference in the prrice and the LR value plotted at all date points covering the complete LR date scale. It would be similar to an oscillator based on (C-AvgC50). In order to do this, the LR end point and slope must be known (the PCFs for this are known). Does this make sense?
Thanks,
Dempsey30338
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
I still don't understand what you want, but let's continue to use the 6-Period Linear Regression as an example.
The current price minus the right end point of the linear regression (or the value of the moving linear regression) could be written as:
C - (AVGC6 + 2.5 * (2.5 * C + 1.5 * C1 + .5 * C2 - .5 * C3 - 1.5 * C4 - 2.5 * C5) / 17.5)
You could use this as the formula in a Custom PCF Indicator to plot the value of price minus the moving linear regression over time.
It is possible to create formulas for difference between the other five prices along the current linear regression line minus the value of the current linear regression line at that price. For 1-bar ago, this would be:
C1 - (AVGC6 + 1.5 * (2.5 * C + 1.5 * C1 + .5 * C2 - .5 * C3 - 1.5 * C4 - 2.5 * C5) / 17.5)
And for 2-bars ago:
C2 - (AVGC6 + .5 * (2.5 * C + 1.5 * C1 + .5 * C2 - .5 * C3 - 1.5 * C4 - 2.5 * C5) / 17.5)
And for 3-bars ago:
C3 - (AVGC6 - .5 * (2.5 * C + 1.5 * C1 + .5 * C2 - .5 * C3 - 1.5 * C4 - 2.5 * C5) / 17.5)
And for 4-bars ago:
C4 - (AVGC6 - 1.5 * (2.5 * C + 1.5 * C1 + .5 * C2 - .5 * C3 - 1.5 * C4 - 2.5 * C5) / 17.5)
And for 5-bars ago:
C5 - (AVGC6 - 2.5 * (2.5 * C + 1.5 * C1 + .5 * C2 - .5 * C3 - 1.5 * C4 - 2.5 * C5) / 17.5)
But there really isn't an automated method of plotting these values on the chart to express the difference between the price and the current linear regression line as a histogram.
If we were to try to average these results by adding them together and dividing by 6, the value would always be zero. The average of the absolute difference between price and the linear regression line over the period will usually result in a non-zero result however.
(ABS(C - (ABS(AVGC6 + 2.5 * (2.5 * C + 1.5 * C1 + .5 * C2 - .5 * C3 - 1.5 * C4 - 2.5 * C5) / 17.5)) + ABS(C1 - (AVGC6 + 1.5 * (2.5 * C + 1.5 * C1 + .5 * C2 - .5 * C3 - 1.5 * C4 - 2.5 * C5) / 17.5)) + ABS(C2 - (AVGC6 + .5 * (2.5 * C + 1.5 * C1 + .5 * C2 - .5 * C3 - 1.5 * C4 - 2.5 * C5) / 17.5)) + ABS(C3 - (AVGC6 - .5 * (2.5 * C + 1.5 * C1 + .5 * C2 - .5 * C3 - 1.5 * C4 - 2.5 * C5) / 17.5)) + ABS(C4 - (AVGC6 - 1.5 * (2.5 * C + 1.5 * C1 + .5 * C2 - .5 * C3 - 1.5 * C4 - 2.5 * C5) / 17.5)) + ABS(C5 - (AVGC6 - 2.5 * (2.5 * C + 1.5 * C1 + .5 * C2 - .5 * C3 - 1.5 * C4 - 2.5 * C5) / 17.5))) / 6
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 12/1/2004 Posts: 105
|
Bruce,
Thanks for your assistance relative to the oscillator. The bottom line is that it is not possible to do as TC2000 is currently structured. I will pursue another approach to my thoughts.
I have a suggestion that perhaps you could pass on to the TC2000 software development manager. It is:
When the pointer is used and the data information box is displayed, I would find it helpful to add one more item to the Price section. It would simply display the location of the pointer, such as C0, C3, C10, etc. This could serve as a measure of bars back from the current close on the chart, regardles of the day, week, or month selection. It could easily be displayed next to or below the date display in the data information box.
Thanks again for your help.
Dempsey30338
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
Thank you for your suggestion.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Guest-1 |