Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers Joined: 7/25/2005(UTC) Posts: 1,042
Was thanked: 57 time(s) in 54 post(s)
|
Hi Johnathan
Anything is possible but I think it’s rather unlikely that simple accumulations using Cum() are going to return suspect numbers. Take a look at the numbers generated by some of the expression in the first formula below and you’ll see just how big those numbers can be.
Try plotting the MFL-based Linear Regression indicators below on 40-50 years of DJIA daily data and check that against the plot of a standard LinearReg() function.
Here’s a typical MFL Linear Regression formula.
{Linear Regression (N)}
N:=14;
(N*Sum(Cum(1)*C,N)-Sum(Cum(1),N)*Sum(C,N))/
(N*Sum(Pwr(Cum(1),2),N)-Pwr(Sum(Cum(1),N),2))*
Cum(1)+(Mov(C,N,S)-Mov(Cum(1),N,S)*
(N*Sum(Cum(1)*C,N)-Sum(Cum(1),N)*Sum(C,N))/
(N*Sum(Pwr(Cum(1),2),N)-Pwr(Sum(Cum(1),N),2)));
When you look at the huge numbers generated by some of the expressions, "Pwr(Sum(Cum(1),14),2)*Cum(1)" for example, you can see that it’s not just bars or prices that are being accumulated. The result of this expression grows exponentially into trillions or even quadrillions if it spans enough data.
Here’s another version of Linear Regression, also built in MFL, and it follows much the same pattern as above although that’s not obvious at first glance. The only significant difference is that my formula generates one constant (the B variable) directly from N rather than subtracting one huge number from another slightly bigger (huger) number.
{Linear Regression Indicator}
N:=Input("LR Indicator Periods",1,99,14);
M:=Cum(1);
U:=Sum(M,N);
X:=Sum(C,N);
Y:=Sum(M*C,N);
Z:=Sum(Pwr(M,2),N);
A:=(N*Y-U*X);
B:=N*N*(N+1)*(2*N+1)/6-Pwr(N*(N+1)/2,2);
LRS:=A/B;
LRS*M + X/N - LRS*U/N;
Not being a mathematician I have no idea how Linear Regression is generated within MetaStock as a standard function. What I do know is that discrete code versions come up short, and what I suspect is that a linear regression line or plot should only have to use N periods of data to get a result, not the complete history.
I’m confused as to the original question posed by ngterry, but if it’s any help to him here are my MFL versions of Linear Regression Slope and Time Series Forecast. There’s a good chance that none of the code will post correctly, but since the official method of posting code doesn’t seem to work for me I’ll just take my chances.
{Linear Regression Slope}
N:=Input("LR Indicator Periods",1,99,14);
M:=Cum(1);
U:=Sum(M,N);
X:=Sum(C,N);
Y:=Sum(M*C,N);
Z:=Sum(Pwr(M,2),N);
A:=(N*Y-U*X);
B:=N*N*(N+1)*(2*N+1)/6-Pwr(N*(N+1)/2,2);
A/B;
{Time Series Forecast}
N:=Input("LR Indicator Periods",1,99,14);
M:=Cum(1);
U:=Sum(M,N);
X:=Sum(C,N);
Y:=Sum(M*C,N);
Z:=Sum(Pwr(M,2),N);
A:=(N*Y-U*X);
B:=N*N*(N+1)*(2*N+1)/6-Pwr(N*(N+1)/2,2);
LRS:=A/B;
LRS*M + X/N - LRS*U/N +A/B;
Roy
|