Code: Select all
public static T Extremum<T>(this ISeries<T> seria1, int length, int offset, IComparer<T> comparator, ref int extremeBar)
{
if (length <= 0)
throw new ArgumentOutOfRangeException("length", "Parameter should be > 0.");
int num = 0;
T y = seria1[0];
for (int index = 1; index < length; ++index)
{
if (comparator.Compare(seria1[index], y) > 0)
{
y = seria1[index];
num = index;
}
}
extremeBar = offset + num;
return y;
}
Update: I believe the code should look something like this *UNTESTED*:
Code: Select all
public static T Extremum<T>(this ISeries<T> seria1, int length, int offset, IComparer<T> comparator, ref int extremeBar)
{
if (length <= 0)
throw new ArgumentOutOfRangeException("length", "Parameter should be > 0.");
int num = [b]offset[/b];
T y = seria1[[b]offset[/b]];
for (int index = 1[b]+offset[/b]; index < length[b]+offset[/b]; ++index)
{
if (comparator.Compare(seria1[index], y) > 0)
{
y = seria1[index];
num = index;
}
}
extremeBar [b]= num;[/b]
return y;
}