Ehlers hilbert SNR afl code

I was reading volume 18th of TASC magazine and it was about Hilbert transform and using to identify cycle strength and period.
the article was provided with easy language code.
can anyone please transform it to afl ?

FOR SNR INDICATOR
Here’s the EasyLanguage code for the signal-to-noise ratio indicator.
Inputs: Price((H+L)/2);
Vars: Imult (.635),
Qmult (.338),
InPhase(0),
Quadrature(0),
Amplitude(0),
Range(0);
If CurrentBar > 8 then begin
{Detrend Price}
Value1 = Price - Price[7];
{Compute “Noise” as the average range}
Range = .2*(H - L) + .8*Range[1];
{Compute Hilbert Transform outputs}
Inphase = 1.25*(Value1[4] - Imult*Value1[2]) +
Imult*InPhase[3];
Quadrature = Value1[2] - Qmult*Value1 +
Qmult*Quadrature[2];
{Compute smoothed signal amplitude}
Value2 = .2*(InPhase*InPhase +
Quadrature*Quadrature) + .8*Value2[1];
{Compute smoothed SNR in Decibels, guarding against
a divide by zero error, and compensating for filter loss}
If Value2 < .001 then Value2 = .001;
If Range > 0 then Amplitude = .25*(10*Log(Value2/
(Range*Range))/Log(10) + 1.9) + .75*Amplitude[1];
{Plot Results}
Plot1(Amplitude, “Amp”);
Plot2(6, “Ref”);
end;
Here’s the EasyLanguage code to compute and plot the
instantaneous phase.
Inputs: Price((H+L)/2);
Vars: Imult (.635),
Qmult (.338),
InPhase(0),
Quadrature(0),
Phase(0),
DeltaPhase(0),
count(0),
InstPeriod(0),
Period(0);
If CurrentBar > 5 then begin
{Detrend Price}
Value3 = Price - Price[7];
{Compute InPhase and Quadrature components}
Inphase = 1.25*(Value3[4] - Imult*Value3[2]) +
Imult*InPhase[3];
Quadrature = Value3[2] - Qmult*Value3 +
Qmult*Quadrature[2];
{Use ArcTangent to compute the current phase}
If AbsValue(InPhase +InPhase[1]) > 0 then Phase =
ArcTangent(AbsValue((Quadrature+Quadrature[1]) /
(InPhase+InPhase[1])));
{Resolve the ArcTangent ambiguity}
If InPhase < 0 and Quadrature > 0 then Phase = 180 - Phase;
If InPhase < 0 and Quadrature < 0 then Phase = 180 +
Phase;
If InPhase > 0 and Quadrature < 0 then Phase = 360 -
Phase;
{Compute a differential phase, resolve phase wraparound, and limit delta phase errors}
DeltaPhase = Phase[1] - Phase;
If Phase[1] < 90 and Phase > 270 then DeltaPhase =
360 + Phase[1] - Phase;
If DeltaPhase < 1 then DeltaPhase = 1;
If DeltaPhase > 60 then DeltaPhase = 60;
{Sum DeltaPhases to reach 360 degrees. The sum is
the instantaneous period.}
InstPeriod = 0;
Value4 = 0;
For count = 0 to 50 begin
Value4 = Value4 + DeltaPhase[count];
If Value4 > 360 and InstPeriod = 0 then begin
InstPeriod = count;
end;
end;
{Resolve Instantaneous Period errors and smooth}
If InstPeriod = 0 then InstPeriod = InstPeriod[1];
Period = .25*(InstPeriod) + .75*Period[1];
Plot1(Period, “DC”);
end;

@jkhodadi several of those older Ehlers indicators were also in his books and various users have posted codes in the User Library.

A version that may be what you are looking for can be found here,
http://www.amibroker.com/members/library/formula.php?id=1399

1 Like