Greetings --

There may be two questions in this thread.

Question 1 -- What is the relationship between the smoothing constant and
the lag.

Given a Simple Moving Average with a lookback of SMALength (say, 10 bars),
what is the smoothing constant for an Exponential Moving Average that
performs approximately the same smoothing as the SMA?

The name given to the smoothing constant is alpha.

An EMA is defined by a recursive relationship, here based on Closing price,
C:
E[0] = C[0];
E[i] = alpha*C[i] + (1-alpha)*E[i-1];

i is the index that starts at the oldest data point and continues through
the most recent data point.

alpha is the smoothing constant that defines the EMA.
alpha is approximately 2/(SMALength+1)

A SMA using a lookback of 10 bars is roughly equivalent to an EMA using an
alpha of 2/(10+1) = 2/11 = 0.1818.

When a formula using an Exponential Moving Average is specified, it is
defined by its lookback period, EMALength.  For example:
EMALength = 10;
Sm = EMA(C,EMALength);
Within the compiler, ELALength is used to compute alpha, and the series Sm
is computed using the recursive relationship.

You can compute your own EMA using this afl code:
EMALength = 10;
alpha = 2/(EMALength+1);
CustomEMA[0] = C[0];
for (i=1; i<BarCount; i++)
{
  CustomEMA[i] = alpha*C[i] + (1-alpha)*CustomEMA[i-1];
}
Plot(CustomEMA,"CustomEMA",colorblue,styleline);



Question 2 -- When optimizing a system based on the crossover of two moving
averages, how to keep the length of the second period greater than the
length of the first.

FastLength = Optimize("FastLength",5,1,10,1);
SlowIncrement = Optimize("SlowIncrement",1,1,20,1);
SlowLength = FastLength + SlowIncrement;
FastMA = EMA(C,FastLength);
SlowMA = EMA(C,SlowLength);
Buy = Cross(FastMA,SlowMA);
Sell = Cross(SlowMA,FastMA);

----------

Thanks,
Howard

On Fri, Mar 26, 2010 at 9:31 PM, Mike <sfclimb...@yahoo.com> wrote:

>
>
> Keith,
>
> He was asking for the smoothing factor, not the period. The smoothing
> factor is a value between 0 and 1, as described in the document pointed to
> by his link.
>
> It is a good question. After some brief searching, I could not find the
> answer. Though, I suppose you could fire up a chart using a short period and
> do the math, as per the comments of DEMA.
>
> http://www.amibroker.com/guide/afl/afl_view.php?id=42
>
> Mike
>
>
> --- In amibroker@yahoogroups.com <amibroker%40yahoogroups.com>, Keith
> McCombs <kmcco...@...> wrote:
> >
> > It's settable by you. Right click in the chart that is displaying ema.
> > Select "edit formula", and find EMA(n) -- n is the period and you can
> > set it to whatever you want.
> >
> > On 3/26/2010 18:48, mpdx58 wrote:
> > >
> > > Does anyone know what the smoothing factor is that Amibroker uses when
> > > calculating the exponential moving average?
> > >
> > >
> http://en.wikipedia.org/wiki/Exponential_smoothing#The_exponential_moving_average
> > > <
> http://en.wikipedia.org/wiki/Exponential_smoothing#The_exponential_moving_average
> >
> > >
> > >
> >
>
>  
>

Reply via email to