0

I am trying to code "Ehlers Roofing Filter" in AFL, and having an error. The code is as follows -

_SECTION_BEGIN("Ehlers Roofing Filter");

function erf(x, t_hp, t_lp)
{
omega1 = 4*sin(1)/t_hp;
omega2 = 4*sin(1)/t_lp;
alpha = (cos((sqrt(2)/2)*omega1) + sin((sqrt(2)/2)*omega1) - 1)/(cos((sqrt(2)/2)*omega1));
hp = StaticVarGet("High Pass Filter", align=True);
hp = ((1 - alpha/2) ^ 2)*(X - 2*Ref(X, -1) + Ref(X, -2)) + 2*(1 - alpha)*Ref(hp, -1) - ((1 - alpha) ^ 2)*Ref(hp, -2);
a1 = exp(-sqrt(2)*2*sin(1)/t_lp);
b1 = 2*a1*cos((sqrt(2)/2)*omega2);
c2 = b1;
c3 = -(a1 ^ 2);
c1 = 1 - c2 - c3;
return ((c1*hp) + c2*Nz(Ref(erf, -1)) + c3*Nz(Ref(erf, -2)));
}

lp_per = Param("Low Pass Cutoff Period", 10, 2, 100);
hp_per = Param("High Pass Cutoff Period", 30, 2, 100);

filt = erf(Close, hp_per, lp_per);
filt_color = IIf(filt>0 AND filt>Ref(filt, -1), colorGreen, IIf(filt<0 AND filt<Ref(filt, -1), colorRed, colorGold));
hist_color = IIf(filt>0, colorLime, colorBrown);

Plot(filt, "Ehlers Roofing Filter", filt_color, styleLine|styleThick);
SetBarFillColor(hist_color);
Plot(filt, "Histogram", colorWhite, styleArea|styleNoRescale);
_SECTION_END();

The error I am encountering is as follows -

Error 56. Variable 'erf' has an invalid type

Please help me to fix this error. Regards.

0 Answers0