# 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),
Amplitude(0),
Range(0);
If CurrentBar > 8 then begin
{Detrend Price}
Value1 = Price - Price;
{Compute “Noise” as the average range}
Range = .2*(H - L) + .8*Range;
{Compute Hilbert Transform outputs}
Inphase = 1.25*(Value1 - Imult*Value1) +
Imult*InPhase;
Quadrature = Value1 - Qmult*Value1 +
{Compute smoothed signal amplitude}
Value2 = .2*(InPhase*InPhase +
{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;
{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),
Phase(0),
DeltaPhase(0),
count(0),
InstPeriod(0),
Period(0);
If CurrentBar > 5 then begin
{Detrend Price}
Value3 = Price - Price;
Inphase = 1.25*(Value3 - Imult*Value3) +
Imult*InPhase;
Quadrature = Value3 - Qmult*Value3 +
{Use ArcTangent to compute the current phase}
If AbsValue(InPhase +InPhase) > 0 then Phase =
(InPhase+InPhase)));
{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 - Phase;
If Phase < 90 and Phase > 270 then DeltaPhase =
360 + Phase - 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;
Period = .25*(InstPeriod) + .75*Period;
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