PureBytes Links
Trading Reference Links
|
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");
|