Hi cav
I'll post the commented version of weekly MACD
later today.
There's a big difference between Ref() and
PREV.
PREV can be used in a formula variable to call the
previous value of itself while this variable is still in the process of being
defined.
Ref(), on the other hand, can only call variables
that have already been defined. A variable with Ref() can be subsequently
modified to change or give it a completely new definition, but when the formula
is processed for the next data bar the first definition must be applied again
before it can be modified or redefined. This process repeats for every
bar.
King regards
Roy
----- Original Message -----
Sent: Friday, April 22, 2005 3:32
AM
Subject: [Metastockusers] Re: Weekly MACD
- Close
Hi Roy
Its good of you to take the time to go
through this. Thanks a lot.
If it isnt too much trouble a
commented weekly MACD code would be very useful to exactly understand how
the weekly timing mechanism works.
On a separate but related
note: whats the difference between using the PREV function and using say a
REF(XXX,-1) function, given that the PREV function can be slow?
Best regards
cav
--- In
Metastockusers@xxxxxxxxxxxxxxx, "Roy Larsen" <rlarsen@xxxx>
wrote: > Hi cav > > For your interest here's a 5-bar
rolling frame MACD. Frame boundaries are based on the last bar of >
data. > > {Rolling 5-Bar-Frame
MACD} > {2005 Roy Larsen, rlarsen@xxxx} >
N:=Input("MACD Signal Frames",1,19,9); >
BarCount:=LastValue(Cum(1))-Cum(1); > J:=Frac(BarCount/5)=0; {end of
frame} > K:=ValueWhen(1,J,C); {frame CLOSE} > X:=0.15; Y:=0.075;
N:=2/(N+1); >
X:=If(Cum(J>0)=1,K,ValueWhen(1,J,PREV)*(1-X)+K*X); >
Y:=If(Cum(J>0)=1,K,ValueWhen(1,J,PREV)*(1-Y)+K*Y); > R:=X-Y; >
Z:=If(Cum(J>0)=1,R,ValueWhen(1,J,PREV)*(1-N)+R*N); > R;
{MACD} > Z; {Signal} > > Change the BarCount variable to
this to tie frame boundaries to the first bar of data in a chart or
> exploration. > > BarCount:=Cum(1); > >
> > Thanks for the input. Understand what you mean about "most
of the > > code defining the weekly timeframe" .. lol, tried
unpicking it, but > > haven't done it right. > >
Defining frame boundries for weekly data means identifying the first and
last bar of each week, and > compensating when the last bar is other
than Friday. To replicate MetaStock's weekly data the last > week
must also be dynamic - i.e. the end of the frame rolls from Monday to
Friday. That in itself is > something of a problem. Consider the Easter
holiday weekend when both Friday and Monday are > non-trading days.
Calculating an EMA, for example, is a little tricky when both Thursday and
the > following Tuesady must each be regarded as the end of their
respective weeks, assuming Tuesday is > the last bar of data. Just
using Tuesday to signal a new week, and looking back to the previous bar
> for the end of the previous week isn't sufficient to retrieve the
two data samples required. > > Would a commented Weekly MACD
code help your understanding of how the weekly timing mechanism
works? > > > I take your point about tying the frame to the
first bar - no > > point. Sorry if this sounds dumb, but by
tying the frame to the > > last bar - yes, every new bit of data will
change the picture every > > day, but isn't this what happens in
a moving average anyway? > > No it isn't what happens with a
moving average. Existing values in a moving average stay fixed as >
new data is added, regardless of the periodicity, because the contents of
each frame (bar or week) > stays fixed. A rolling frame keeps moving
the start and end points of each frame. It's quite >
different. > > > I guess where my thinking is leading me is
that a Mon-Fri MACD is a > > bit artificial? Fridays trend
change is relevant to the following > > Monday? So why set
up the frame as Mon-Fri, rather than the last 5 > > trading days?
Any views would be most welcome .. > > Maybe, but I think not. I
guess most of the worlds population base their activity on a very rigid
> 7-day cycle. Everyone has a start of the week, and everyone has a
finish of the week. This is so > deeply ingrained into our psyche
that it has a huge influence on how traders and everyone else
acts. > > > Kind regards > > Roy >
www.metstocktips.co.nz
Yahoo! Groups Links
|