PureBytes Links
Trading Reference Links
|
I believe the following is a direct translation of the for loops from the
EasyLanguage code to C (untested). It looks like however that you are not
writing a dll to be called from EasyLanguage. It looks more like you have a
standalone C program that will be calling a C function.
Not knowing how the main program is structured kind of complicates a
complete translation. I'm guessing in your example C code that *ans relates
to Filt, *v relates to Price, m relates to Length (?) and n relates to total
number of data points in *v (?). Also in your C example, it looks like your
outer for loop is doing what Easylanguage does behind the scene - loop thru
the whole data series.
//->samw
for (count=0; count<Length; count++)
{
distance2[count]=0;
for (lookback=1; lookback<Length; lookback++)
{
distance2[count]=distance2[count]+(Price[count]-
Price[count+lookback])*(Price[count]-Price[count+lookback]);
}
coef[count]=distance2[count];
}
for (count=0; count<Length; count++)
{
num+=coef[count]*Price[count];
sumCoef+=coef[count];
}
if (sumCoef<>0)
{
Filt = num/sumCoef;
}
----- Original Message -----
From: "Trey Johnson" <dickjohnson3@xxxxxxxxxxxxxx>
To: <omega-list@xxxxxxxxxx>
Sent: Thursday, December 11, 2003 8:58 AM
Subject: EL to C++
> Hello List,
> I was wondering if someone could help me convert this indicator
> from EL to C++. I'm new to C++ so I'm having trouble the multiple loops.
> Any help is greatly appreciated. I was able to convert a less
> complicated version that I'm including as reference.
> Thanks,
> Trey
>
> {--John Ehlers Nonlinear FIR filter using 5 bar momentum--}
>
> Inputs:Price((H+L)/2),Length(15);
> Vars:count(0),Lookback(0),SumCoef(0),Num(0),Filt(0);
>
> Array: Coef[40](0),Distance2[40](0);
>
> For count=0 to Length-1 begin
>
> Coef[count]=Absvalue(Price[count]-Price[count+5]);
> end;
>
> {Sum across the numerator and across all coefficients}
>
> Num=0;
> SumCoef=0;
> For count=0 to Length-1 begin
> Num=Num+Coef[count]*Price[count];
> SumCoef=SumCoef+Coef[count];
> End;
> If SumCoef<>0 then Filt=Num/SumCoef;
>
> Plot1(Filt,"Ehlers");
>
> In C++:
>
> void Filter (float *ans, float *v, int m, int n) {
> //Ehlers Filter based on Order Statistic FIR filters
> //ans -out: series [1...n] of filter values
> //v -in: series [1...n] of original data points
> //m -in: lookback period
> //n -in: number of data points in input series
> double coef, num, sumcoef; int i,j,k;
>
> for(i=1; i<=n; i++){
> for(j=0, num=0.0, sumcoef=0.0; j<m; j++){
> if((k=i-j)<1) break;
> coef=fabs(v[k]-v[k-5]);
> num+=coef*v[k];
> sumcoef+=coef;}
> ans[i]=(num/sumcoef);}}
>
>
> {--John Ehlers Nonlinear FIR filter This is the one I need converted--}
>
> Inputs:Price((H+L)/2),Length(15);
> Vars:count(0),Lookback(0),SumCoef(0),Num(0),Filt(0);
>
> Array: Coef[40](0),Distance2[40](0);
>
> For count=0 to length-1 begin
> Distance2[count]=0;
> For Lookback=1 to Length-1 begin
>
> Distance2[count]=Distance2[count]+(Price[count]-
> Price[count+Lookback])*(Price[count]-Price[count+Lookback]);
> End;
> Coef[count]=Distance2[count];
> End;
>
> {Sum across the numerator and across all coefficients}
>
> Num=0;
> SumCoef=0;
> For count=0 to Length-1 begin
> Num=Num+Coef[count]*Price[count];
> SumCoef=SumCoef+Coef[count];
> End;
> If SumCoef<>0 then Filt=Num/SumCoef;
>
> Plot1(Filt,"Ehlers");
>
>
>
>
|