title: Calculate Exponential Moving Average on a Queue in C#
body: <p>I have a simple class for calculating the moving average of values I add to it. I use it like this:</p>
  
  <pre><code>MovingAverage ma = new MovingAverage();
  ma.push(value1);
  ma.push(value2);
  ... 
  Console.Writeline(average.Average);
  
  //the class
  public class MovingAverage
  {
      public int Period = 5;
      private Queue&lt;double&gt; Quotes = new Queue&lt;double&gt;();
  
      public void Push(double quote)
      {
          if (Quotes.Count == Period)
              Quotes.Dequeue();
          Quotes.Enqueue(quote);
  
      }
      public void Clear()
      {
          Quotes.Clear();
      }
      public double Average { get { if (Quotes.Count == 0) return 0; return Quotes.Average(); } }
      public double ExponentialMovingAverage
      {
          get
          {
              ???
          }
      }
  }
  </code></pre>
  
  <p>I would like to extend this class to also return the ExponentialMovingAverage. How would you write return the Exponential Average of the Queued items in Quotes?  </p>
  
  <p>I realize you will need to add an Alpha property to the class but I'm not sure how to complete the math for the calculation.</p>