**johnny (5/11/2007)**

Hi.

1. A simple moving average indicator implementation (implementing the whole calculation in itself - running the input array, adding each value to n previous values and diviving each sum by n).

I've re-written our normal SMA to show a single indicator doing all of it's own calculations. Please do not take this as an example of a the correct way to write this particular indicator. For 200 periods it's about 200 times slower than the actual implementation

Also, check the results of this, I just hacked i out and have not even compiled it.

using System;

using System.Drawing;

using System.Collections.Generic;

using System.ComponentModel;

using RightEdge.Common;

namespace RightEdge.Indicators

{

/// <summary>

/// Simple Moving Average (SMA) indicator.

/// </summary>

[YYEIndicatorAttribute(System.Drawing.KnownColor.LightBlue,

YYEIndicatorAttribute.EIndicatorGroup.Trend,

Name = "SLOW SMA",

Description = "Mean value, as calculated over a rolling previous period of fixed length.",

Id = "SLOW-AE5B81CF-9717-49e7-857A-786D67181B5E",

HelpText = "Slow SMA")]

[Serializable]

[SeriesInputAttribute("Input", 1, Value = BarElement.Close)]

public class SlowSMA : SeriesCalculatorBaseWithValues

{

private int periods = 50;

private int validCount = 0;

// Constructs an Simple Moving Average (SMA) indicator instance.

[ConstructorArgument("Periods", ConstructorArgumentType.Integer, "50", 1)]public SlowSMA(int periods) : base(1)

{

if (periods <= 0)

{

throw new ArgumentException("Periods must be greater than zero");

}

this.periods = periods;

}

// Calculates a new value for the series.

protected override double CalcNewValue(int index){

double returnValue = double.NaN;

validCount++;

// We don't start calculating until we have enough

// values in our array to go back by our number of

// periods.

if (validCount >= periods)

{

double sum = 0.0;

// We need to iterate back through the last "periods" bars

// and take an average. We move back one bar per iteration.

for(int cnt = 0; cnt < periods; cnt++)

{

// Build our big sum

sum = sum + inputs[0][index - cnt];

}

// Divide by periods to get the average.

returnValue = sum / periods;

}

return returnValue;

}

// Resets the series.

protected override void Reset(){

validCount = 0;

}

}

}