I'm a matlab user and i currently try to code Ehler's indicators into matlab. I have a question regarding transcription of EasyLanguage to matlab :
Ehler's uses brackets [n] notation in EasyLangage. It is supposed to refer to the [n] bar of lag (previous 'n' bar).
In a price series, vertically orientated, in chronological order oldest first, [n] refers to the (end-n) element or (1:n) vector ?
You may understand better if I ask what is Filt[count] in the below code : the vector from FILT(1:count), FILT(count) or FILT(end-count) as it is a lag ?
In the second part of this post, the Matlab Code i'm working on (not vectorialized yet)
{
Autocorrelation Reversals
2013 John F. Ehlers
}
Inputs:
HPLength(48),
LPLength(10),
AvgLength(3);
//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;
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] 24 Then Reversal = 1;
%%%%%%%%%%%%%%%%%%%%%%%%%
%In Matlab, I separated the first part of the code, which is the High Pass filter and a Smoother
xdFilter = ehlers_roofingfilter(xdPx,dPeriodShort,dPeriodLong,numOfPx);
%numOfPx, dPeriodLong and dAvgLength are inputs
%xdFilter is the price series filtered through HP filter and super smoother
for nCount = 0 : M-1
X = xdSample(Nsamp-nCount);
Y = xdSample(Nsamp-nCount-nLag);
dSx = dSx + X;
dSy = dSy + Y;
dSxx = dSxx + X^2;
dSyy = dSyy + Y^2;
dSxy = dSxy + Y*X;
end
%//Compute correlation for each value of lag
if (M*dSxx-dSx^2)*(M*dSyy-dSy^2) > 0
%//Scale each correlation to range between 0 and 1
dCorr = (M*dSxy-dSx*dSy)/sqrt((M*dSxx-dSx*dSx)*(M*dSyy-dSy*dSy));
xdCorr(nLag+1,nBar) = dCorr;
xdCorrN(nLag+1,nBar) = .5*(dCorr+1);
end
end
xdDeltas(3:end,nBar) = or(and(xdCorrN(3:end,nBar)>0.5,xdCorr(3:end,nBar)0.5,xdCorrN(3:end,nBar) 24, so the Autocorrelation reversal is never reversing ... if someone …