[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: EasyLanguage Question about weekly EMA overlay on Daily Chart....



PureBytes Links

Trading Reference Links

> >I have a question that I hope someone on this list can answer.  I’m
> >trying to calculate a 26 WEEK EMA while using a daily chart but I can’t
>
> For an EMA, the best thing is simply to use the daily chart.  If you
> want a 26-week EMA, that's 130 daily bars, so use xAverage(Close,
> 130);

That's not quite the same as a 26-period EMA on a weekly chart.
The weekly chart ignores the daily closes (except for Friday) but
the 130-period daily EMA doesn't.  But it may be close enough for
your needs.

> >I’ve tried putting a weekly
> >chart up in DATA2 and using the following syntax:
> > 
> >Value1 = XAverage(Close of data2,26);
>
> This won't work because XAverage will still be evaluated every daily
> bar, using your weekly bars.  So you're actually using just the last
> 5 weekly bars, multiple times on each bar.

No, not true.  Since the Xaverage refers to the Close of data2,
it only computes a new value when data2 has a bar.  (And data1
must have a bar too, or TS doesn't evaluate code on that bar at
all.)

See the attached small GIF, which has daily data in data1 and
weekly data in data2 (hidden).  The yellow line is a 130-bar EMA
of the daily close.  The white and cyan lines, which are almost
identical but not quite, are two ways of computing a weekly EMA.
The white is xaverage(Close of data2, 26) with weekly data in
data2, and the cyan is the result of computing the weekly EMA
using only daily or intraday data:

vars: factor(2 / (len + 1)), EMA(Close);
if DayOfWeek(Date) < DayOfWeek(Date[1]) then
    EMA = factor * Close[1] + (1-factor) * EMA;

Notice how the yellow line (130-bar EMA) moves smoothly, and also
how the white line (which refers to data2) updates only once a
week.

Why are the white and cyan lines different?  The white line
updates a bar sooner, on the close of the week, whereas the cyan
line doesn't update until the first bar of the NEW week.  But
other than that one-bar difference, they're virtually identical.

Actually there *is* a slight difference, about 0.1%, between
them.  That's due to 9/11.  The markets closed on 9/10 (Monday)
and re-opened on 9/17 (another Monday).  Because of that
unprecedented week-long closure, the simple test above missed the
fact that 9/11 was actually the end of the week's data.  You
could account for things like this by checking to see if the
Julian date has incremented by more than 7, if you wanted:

if DayOfWeek(Date) < DayOfWeek(Date[1])
  or DateToJulian(Date) >= DateToJulian(Date[1])+7 then
    EMA = factor * Close[1] + (1-factor) * EMA;

Here are some example values from the different methods:

Column A is "xaverage(C data2, 26), with weekly data in data2."
Column B is "xaverage(C,26) on weekly chart with no data2."
Column C is "computed weekly EMA on 60min data with weekly data
in data2."

          A          B          C
5/31   1417.19    1417.19    1419.15
6/7    1396.95    1396.95    1398.77
6/14   1376.14    1376.14    1377.82
6/21   1351.24    1351.24    1352.80

etc.  So:  xaverage(C data2, 26) is identical to xaverage(C,26)
on a weekly chart.  The computed EMA is off by a smidgen due to
9/11, but it's identical before that, and the difference should
settle down to less than a point within a few months.  With the
Julian-date check above, there is no difference.  Either one
computes the correct weekly EMA, but I'd go with the computed
EMA.  Life is simpler if you can avoid multiple data streams.

Gary


Attachment: Description: "EMA.gif"