His autocorrelation periodogram is easily found. This one, not so much.
Code: Select all
{
Autocorrelation Reversals
© 2013 John F. Ehlers
}
Inputs:
HPLength(48),
LPLength(10),
AvgLength(3);
Vars:
alpha1(0),
HP(0),
a1(0),
b1(0),
c1(0),
c2(0),
c3(0),
Filt(0),
M(0),
N(0),
X(0),
Y(0),
Lag(0),
count(0),
Sx(0),
Sy(0),
Sxx(0),
Syy(0),
Sxy(0),
SumDeltas(0),
Reversal(0);
Arrays:
Corr[48, 2](0);
//Highpass filter cyclic components whose periods are shorter than 48 bars
alpha1 = (Cosine(.707*360 / 48) + Sine (.707*360 / 48) - 1) / Cosine(.707*360 / 48);
HP = (1 - alpha1 / 2)*(1 - alpha1 / 2)*(Close - 2*Close[1] + Close[2]) + 2*(1 - alpha1)*HP[1] - (1 - alpha1)*
(1 - alpha1)*HP[2];
//Smooth with a Super Smoother Filter from equation 3-3
a1 = expvalue(-1.414*3.14159 / LPLength);
b1 = 2*a1*Cosine(1.414*180 / LPLength);
c2 = b1;
c3 = -a1*a1;
c1 = 1 - c2 - c3;
Filt = c1*(HP + HP[1]) / 2 + c2*Filt[1] + c3*Filt[2];
//Pearson correlation for each value of lag
For Lag = 3 to 48 Begin
Corr[Lag, 2] = Corr[Lag, 1];
//Set the averaging length as M
M = AvgLength;
If AvgLength = 0 Then M = Lag;
//Initialize correlation sums
Sx = 0;
Sy = 0;
Sxx = 0;
Syy = 0;
Sxy = 0;
//Advance samples of both data streams and sum Pearson components
For count = 0 to M - 1 Begin
X = Filt[count];
Y = Filt[Lag + count];
Sx = Sx + X;
Sy = Sy + Y;
Sxx = Sxx + X*X;
Sxy = Sxy + X*Y;
Syy = Syy + Y*Y;
End;
//Compute correlation for each value of lag
If (M*Sxx - Sx*Sx)*(M*Syy - Sy*Sy) > 0 Then Corr[Lag, 1] = (M*Sxy - Sx*Sy)/SquareRoot((M*Sxx - Sx*Sx)*(M*Syy - Sy*Sy));
//Scale each correlation to range between 0 and 1
Corr[Lag, 1] = .5*(Corr[Lag, 1] + 1);
End;
SumDeltas = 0;
For Lag = 3 to 48 Begin
If (Corr[Lag, 1] > .5 and Corr[Lag, 2] < .5) Or (Corr[Lag, 1] < .5 and Corr[Lag, 2] > .5) Then SumDeltas = SumDeltas + 1;
End;
Reversal = 0;
If SumDeltas > 24 Then Reversal = 1;
Plot1(Reversal);