I have a set of data stored into an array. Say if I wanted to filter out data at the extremes of, i.e. anything greater or less than 90% of the rest of the data, is there an easy way to go about it?
For example, I am trying to do this in a rather exhaustive way with a for loop, and I must be doing something wrong as it is locking up with only a few bars on my chart. But you can see the two 'for' loops there, and the intent was to replace the two highest values with the average value.
Example.....
private void FilterExtremes()
{
//Get the median of last 21 numbers in sD and lD DataSeries
medsD = System.Convert.ToInt32(GetMedian(sD, lookBack));
medlD = System.Convert.ToInt32(GetMedian(lD, lookBack));
for(int j =0; j < 2; j--)
{
//remove two highest outliers and replace with median value
for (int i =0; i < 21; i--) //
{
if(sD[i] == MAX(sD,21)[0])
{
sD[i] = medsD;
}
if(lD[i] == MAX(lD,21)[0])
{
lD[i] = medlD;
}
}
}
}

Comment