It is definitely possible to determine the value of any particular point of a linear regression line of price using the techniques given in the Using Linear Regression vs Classical Peaks/Valleys for Divergence Analysis topic.
Specific examples involving the values of the various points of a 6-period linear regression line were given in the Deviation From Linear Regression topic where we explored linear regression lines previously.
If what you want to do is calculate any one of the individual values in a linear regression line, this is definitely possible.
If you want to create a histogram plotting the difference between a moving linear regression and price, this is definitely possible.
What was indicated in the topic was that 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 (which is what you indicated you wanted to do in the topic).
The reason for this has nothing to do with being able to calculate the values of the linear regession line at any given point. The reason has to do with how Custom PCF Indicators work.
Custom PCF Indicators start calculating at the far left of the data and continue their calculations to the far right of the data. The formulas used are calculated as if that point in the data is the most recent value.
So let us take the 6-period linear regression example from the Deviation From Linear Regression topic again. The difference between the current price and the right end of the linear regression line is:
C - (AVGC6 + 2.5 * (2.5 * C + 1.5 * C1 + .5 * C2 - .5 * C3 - 1.5 * C4 - 2.5 * C5) / 17.5)
So this last bar would get calculated correctly. But this same formula would also be used for the previous bar. What this means is that the formula would effectively be calculated as:
C1 - (AVGC6.1 + 2.5 * (2.5 * C1 + 1.5 * C2 + .5 * C3 - .5 * C4 - 1.5 * C5 - 2.5 * C6) / 17.5)
And this would in fact be the correct value if we wanted the difference between the price at that point and the moving linear regression at that point. But if we want the difference between the price at that point and the value of the current linear regression line at that point, the calculation would have need to have been the following instead:
C1 - (AVGC6 + 1.5 * (2.5 * C + 1.5 * C1 + .5 * C2 - .5 * C3 - 1.5 * C4 - 2.5 * C5) / 17.5)
For this calculation to work, we would need future data. So we would need to be able to write something like the following (which isn't valid syntax):
C - (AVGC6.(-1) + 1.5 * (2.5 * C(-1) + 1.5 * C + .5 * C1 - .5 * C2 - 1.5 * C3 - 2.5 * C4) / 17.5)
We can theoretically get around this by using dates if you are willing to change the formula each and every day. This is the reason I used the qualifier "automated method" in the original response.
As I post this, it is April 10, 2014. This means it would be possible to reference the future data in a Custom PCF Indicator using date syntax instead of the (-1) syntax which isn't valid in the example given above. Just replacing the (-1) instances with dates in that formula would result in:
C - (AVGC6.'04/10/2014' + 1.5 * (2.5 * C'04/10/2014' + 1.5 * C + .5 * C1 - .5 * C2 - 1.5 * C3 - 2.5 * C4) / 17.5)
But this formula would only be correct today for the previous bar. It wouldn't calculate correctly for any other bars. To do this is much more complicated.
What is needed is a formula which can tell which bar is being calculated in some fashion so it knows the correct formula to use for that bar and only calculates that portion of the formula. There isn't a way to make such a formula which doesn't need to be changed each day and the techniques available to us to determine the day actual bar being calculated are somewhat limited and probably won't work for all symbols.
The following works as a Custom PCF Indicator for some but not all symbols to calculate the difference between the closing price at the time and the current 6-period linear regression line along the course of that linear regression line. It checks the open, high, low, close and volume of each bar against specific dates in an attempt to determine which bar is being calculated. In cases where this information is enough, the calculations should be correct, but in cases where this is not enough, the calculations will not be correct.
ABS(O = O'04/10/2014' AND H = H'04/10/2014' AND L = L'04/10/2014' AND C = C'04/10/2014' AND V = V'04/10/2014') * (C'04/10/2014' - (AVGC6.'04/10/2014' + 2.5 * (2.5 * C'04/10/2014' + 1.5 * C'04/09/2014' + .5 * C'04/08/2014' - .5 * C'04/07/2014' - 1.5 * C'04/04/2014' - 2.5 * C'04/03/2014') / 17.5)) + ABS(O = O'04/09/2014' AND H = H'04/09/2014' AND L = L'04/09/2014' AND C = C'04/09/2014' AND V = V'04/09/2014') * (C'04/09/2014' - (AVGC6.'04/10/2014' + 1.5 * (2.5 * C'04/10/2014' + 1.5 * C'04/09/2014' + .5 * C'04/08/2014' - .5 * C'04/07/2014' - 1.5 * C'04/04/2014' - 2.5 * C'04/03/2014') / 17.5)) + ABS(O = O'04/08/2014' AND H = H'04/08/2014' AND L = L'04/08/2014' AND C = C'04/08/2014' AND V = V'04/08/2014') * (C'04/08/2014' - (AVGC6.'04/10/2014' + .5 * (2.5 * C'04/10/2014' + 1.5 * C'04/09/2014' + .5 * C'04/08/2014' - .5 * C'04/07/2014' - 1.5 * C'04/04/2014' - 2.5 * C'04/03/2014') / 17.5)) + ABS(O = O'04/07/2014' AND H = H'04/07/2014' AND L = L'04/07/2014' AND C = C'04/07/2014' AND V = V'04/07/2014') * (C'04/07/2014' - (AVGC6.'04/10/2014' - .5 * (2.5 * C'04/10/2014' + 1.5 * C'04/09/2014' + .5 * C'04/08/2014' - .5 * C'04/07/2014' - 1.5 * C'04/04/2014' - 2.5 * C'04/03/2014') / 17.5)) + ABS(O = O'04/04/2014' AND H = H'04/04/2014' AND L = L'04/04/2014' AND C = C'04/04/2014' AND V = V'04/04/2014') * (C'04/04/2014' - (AVGC6.'04/10/2014' - 1.5 * (2.5 * C'04/10/2014' + 1.5 * C'04/09/2014' + .5 * C'04/08/2014' - .5 * C'04/07/2014' - 1.5 * C'04/04/2014' - 2.5 * C'04/03/2014') / 17.5)) + ABS(O = O'04/03/2014' AND H = H'04/03/2014' AND L = L'04/03/2014' AND C = C'04/03/2014' AND V = V'04/03/2014') * (C'04/03/2014' - (AVGC6.'04/10/2014' - 2.5 * (2.5 * C'04/10/2014' + 1.5 * C'04/09/2014' + .5 * C'04/08/2014' - .5 * C'04/07/2014' - 1.5 * C'04/04/2014' - 2.5 * C'04/03/2014') / 17.5))
But constructing this type of formula on a daily basis is not the sort of thing most customers are going to be either able or willing to do.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|