Added to wish list.
It is sometimes hard to forsee this type of needs, that's why we value your input so much. And that's the main reason I contribute to this forum, to hear from you.
Here is the code I wrote for this. As you can see I stop when I find a rule that fails but it can easily be modified to continue:
private bool WecoRulesPassed (double sigma,double mean)
{
int over2SigmaCount = 0,under2SigmaCount = 0,over1SigmaCount = 0,under1SigmaCount = 0;
int underMeanCount = 0,overMeanCount = 0,trendUpCount = 0,trendDownCount = 0,trendAlternateCount = 0;
double xPrevious = m_data[0];
int i;
for (i = 0; i < m_N; i++) {
double x = m_data[i];
// 3 Sigma
if ((x > (mean + 3 * sigma)) || (x < (mean - 3 * sigma)))
break;
// 2 Sigma
if (x > (mean + 2 * sigma)) {
over2SigmaCount++;
if (over2SigmaCount >= 2)
break;
} else
over2SigmaCount = 0;
if (x < (mean - 2 * sigma)) {
under2SigmaCount++;
if (under2SigmaCount >= 2)
break;
} else
under2SigmaCount = 0;
// 1 Sigma
if (x > (mean + sigma)) {
over1SigmaCount++;
if (over1SigmaCount >= 4)
break;
} else
over1SigmaCount = 0;
if (x < (mean - sigma)) {
under1SigmaCount++;
if (under1SigmaCount >= 4)
break;
} else
under1SigmaCount = 0;
// Mean
if (x > mean) {
overMeanCount++;
if (overMeanCount >= 8)
break;
} else
overMeanCount = 0;
if (x < mean) {
underMeanCount++;
if (underMeanCount >= 8)
break;
} else
underMeanCount = 0;
// Trends
if (x > xPrevious) {
if (trendDownCount > 0)
trendAlternateCount++;
else
trendAlternateCount = 0;
trendUpCount++;
if (trendUpCount >= 6)
break;
} else
trendUpCount = 0;
if (x < xPrevious) {
if (trendUpCount > 0)
trendAlternateCount++;
else
trendAlternateCount = 0;
trendDownCount++;
if (trendDownCount >= 6)
break;
} else
trendDownCount = 0;
if (trendAlternateCount >= 14)
break;
xPrevious = x;
}
return (i >= m_N);
}
This should save you some time.