#### Topic: Smoothed Moving Average

I need to now how to calculate a Smoothed Moving Average for a data tester Im making on a spreadsheet.

How does FSB calculate the Smoothed MA Method

#### Re: Smoothed Moving Average

``````/// <summary>
/// Calculates a Moving Average
/// </summary>
/// <param name="iPeriod">Period</param>
/// <param name="iShift">Shift</param>
/// <param name="maMethod">Method of calculation</param>
/// <param name="afSource">The array of source data</param>
/// <returns>the Moving Average</returns>
protected static double[] MovingAverage(int iPeriod, int iShift, MAMethod maMethod, double[] adSource)
{
int      iBar;
double   sum;

if (iPeriod <= 1 && iShift == 0)
{   // There is no smoothing
}

if (iPeriod > Bars || iPeriod + iShift <= 0 || iPeriod + iShift > Bars)
{   // Error in the parameters
return null;
}

for (iBar = 0; iBar < iPeriod + iShift - 1; iBar++)
{
}

for (iBar = 0, sum = 0; iBar < iPeriod; iBar++)
{
}

adTarget[iPeriod + iShift - 1] = sum / iPeriod;

// Simple Moving Average
if (maMethod == MAMethod.Simple)
{
for (iBar = iPeriod; iBar < Math.Min(Bars, Bars - iShift); iBar++)
{
}
}

// Exponential Moving Average
else if (maMethod == MAMethod.Exponential)
{
double pr = 2d / (iPeriod + 1);

for (iBar = iPeriod; iBar < Math.Min(Bars, Bars - iShift); iBar++)
{
adTarget[iBar + iShift] = adSource[iBar] * pr + adTarget[iBar + iShift - 1] * (1 - pr);
}
}

// Weighted Moving Average
else if (maMethod == MAMethod.Weighted)
{
double dWeight = iPeriod * (iPeriod + 1) / 2d;

for (iBar = iPeriod; iBar < Math.Min(Bars, Bars - iShift); iBar++)
{
sum = 0;
for (int i = 0; i < iPeriod; i++)
{
sum += adSource[iBar - i] * (iPeriod - i);
}

adTarget[iBar + iShift] = sum / dWeight;
}
}

// Smoothed Moving Average
else if (maMethod == MAMethod.Smoothed)
{
for (iBar = iPeriod; iBar < Math.Min(Bars, Bars - iShift); iBar++)
{
adTarget[iBar + iShift] = (adTarget[iBar + iShift - 1] * (iPeriod - 1) + adSource[iBar]) / iPeriod;
}
}

for (iBar = Bars + iShift; iBar < Bars; iBar++)
{