ASP.NET / C#: Using Standard Deviation to Remove Extreme Items From List in Function

Using ASP.NET / C#, how can I use Standard Deviation with my function to remove the extreme numbers?

using System;
using System.Linq;
using System.Collections.Generic;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo.Robots
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class SampleSmartBotRobot : Robot

        protected override void OnTick()
            MarketSeries seriesHour = MarketData.GetSeries(MarketData.GetSymbol(Symbol.Code), TimeFrame.Hour);
            double r = GetRangeByHour(seriesHour, 20, 10);
            Print( r.ToString("N30") );

        private double GetRangeByHour(MarketSeries Series, int Hour, int X)
            List<double> RangeRange = new List<double>();

            int iii=0;
            for (int iiii = 0; iiii <= Series.Close.Count && iii <X; iiii++)
                if ( Hour == Convert.ToInt32(Series.OpenTime[iiii].ToString("%H")) ) {
            return RangeRange.Average();


Open in new window

This question is related to this:
LVL 10
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
I think Stephen Calabrese gave you an example in your previous question.
skijAuthor Commented:
He gave an example of a standard divination funtion, but how can it be incorporated with my function in the code posted above?
Stephen CalabreseCommented:
Are you trying to find the average with the extremes removed?
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

skijAuthor Commented:
Yes, I am trying to find the average with the extremes removed.
Stephen CalabreseCommented:
You are going to need to take two passes and an extra array. The first is to find the standard deviation of your data. Use the method of the second post. Then for each value i in the array you check if
i >= (average -2*standardDeviation) && i <= (average + 2*standardDeviation)

Open in new window

If this is the case then you add the element to the new list. Once you go through all the elements in the old list you can call  RangeRange.Average(); on the new list and you should have the correct average.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
skijAuthor Commented:
        List<double> RangeRange = new List<double>();

        double average = RangeRange.Average();
        double standardDeviation = getStandardDeviation(RangeRange);
        RangeRange.RemoveAll(x =>  x <= (average -1*standardDeviation) || x >= (average + 1*standardDeviation)  );

        private class Range
           public double RangeRange;
           public double RangeBounceNear;
           public double RangeBounceFar;

        private double getStandardDeviation(List<double> doubleList)  
           double average = doubleList.Average();  
           double sumOfDerivation = 0;  
           foreach (double value in doubleList)  
              sumOfDerivation += (value) * (value);  
           double sumOfDerivationAverage = sumOfDerivation / (doubleList.Count - 1);  
           return Math.Sqrt(sumOfDerivationAverage - (average*average));  

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.