<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Forex Software — Smoothed Moving Average]]></title>
		<link>https://forexsb.com/forum/topic/2887/smoothed-moving-average/</link>
		<atom:link href="https://forexsb.com/forum/feed/rss/topic/2887/" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Smoothed Moving Average.]]></description>
		<lastBuildDate>Wed, 28 Dec 2011 15:13:06 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Smoothed Moving Average]]></title>
			<link>https://forexsb.com/forum/post/12024/#p12024</link>
			<description><![CDATA[<div class="codebox"><pre><code>/// &lt;summary&gt;
        /// Calculates a Moving Average
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;iPeriod&quot;&gt;Period&lt;/param&gt;
        /// &lt;param name=&quot;iShift&quot;&gt;Shift&lt;/param&gt;
        /// &lt;param name=&quot;maMethod&quot;&gt;Method of calculation&lt;/param&gt;
        /// &lt;param name=&quot;afSource&quot;&gt;The array of source data&lt;/param&gt;
        /// &lt;returns&gt;the Moving Average&lt;/returns&gt;
        protected static double[] MovingAverage(int iPeriod, int iShift, MAMethod maMethod, double[] adSource)
        {
            int      iBar;
            double   sum;
            double[] adTarget = new double[Bars];
 
            if (iPeriod &lt;= 1 &amp;&amp; iShift == 0)
            {   // There is no smoothing
                return adSource;
            }
 
            if (iPeriod &gt; Bars || iPeriod + iShift &lt;= 0 || iPeriod + iShift &gt; Bars)
            {   // Error in the parameters
                return null;
            }
 
            for (iBar = 0; iBar &lt; iPeriod + iShift - 1; iBar++)
            {
                adTarget[iBar] = 0;
            }
 
            for (iBar = 0, sum = 0; iBar &lt; iPeriod; iBar++)
            {
                sum += adSource[iBar];
            }
 
            adTarget[iPeriod + iShift - 1] = sum / iPeriod;
 
            // Simple Moving Average
            if (maMethod == MAMethod.Simple)
            {   
                for (iBar = iPeriod; iBar &lt; Math.Min(Bars, Bars - iShift); iBar++)
                {
                    adTarget[iBar + iShift] = adTarget[iBar + iShift - 1] + adSource[iBar] / iPeriod - adSource[iBar - iPeriod] / iPeriod;
                }
            }
 
            // Exponential Moving Average
            else if (maMethod == MAMethod.Exponential)
            {   
                double pr = 2d / (iPeriod + 1);
 
                for (iBar = iPeriod; iBar &lt; 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 &lt; Math.Min(Bars, Bars - iShift); iBar++)
                {
                    sum = 0;
                    for (int i = 0; i &lt; 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 &lt; Math.Min(Bars, Bars - iShift); iBar++)
                {
                    adTarget[iBar + iShift] = (adTarget[iBar + iShift - 1] * (iPeriod - 1) + adSource[iBar]) / iPeriod;
                }
            }
 
            for (iBar = Bars + iShift; iBar &lt; Bars; iBar++)
            {
                adTarget[iBar] = 0;
            }
 
            return adTarget;
        }</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (footon)]]></author>
			<pubDate>Wed, 28 Dec 2011 15:13:06 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/12024/#p12024</guid>
		</item>
		<item>
			<title><![CDATA[Smoothed Moving Average]]></title>
			<link>https://forexsb.com/forum/post/12023/#p12023</link>
			<description><![CDATA[<p>I need to now how to calculate a Smoothed Moving Average for a data tester Im making on a spreadsheet.</p><p>How does FSB calculate the Smoothed MA Method</p>]]></description>
			<author><![CDATA[null@example.com (mixmanmatt)]]></author>
			<pubDate>Wed, 28 Dec 2011 15:09:47 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/12023/#p12023</guid>
		</item>
	</channel>
</rss>
