PDA

View Full Version : Not all code paths return a value error ?


tinkerz
02-19-2010, 09:05 AM
Sorry really overposting

Not all code paths return a value error?

my input array is 128 items, so is my _smoothHp.
_hp is also an array of 129

I cant see my error? i return on an IF statement to _smoothHp array?

private double HPfilter(double []InputArray)
{ // Detrend data by High Pass Filtering
double alpha = (1-Math.Sin(twoPi/30))/Math.Cos(twoPi/30);
for (int bar = 1; bar >128; bar++)
{
_hp[bar] = 0.5*(1+alpha)*(InputArray[bar]-InputArray[bar-1])+alpha*_hp[bar-1];
if (bar>6)
{
return _smoothHp[bar-1] = (_hp[bar-1]+2*_hp[bar-2]+3*_hp[bar-3]+3*_hp[bar-4]+2*_hp[bar-5]+_hp[bar-6])/12;
}
else
{
return _smoothHp[bar-1]=0;
}
}
}

NinjaTrader_Josh
02-19-2010, 10:04 AM
I believe you would likely need to return from outside of the for loop.

Ralph
02-19-2010, 12:41 PM
for (int bar = 1; bar >128; bar++)

This loop never starts because the very first value of bar is never >128.
And in this case: like Josh mentioned already ...