PureBytes Links
Trading Reference Links
|
Hi David,
> Thanks for the replies. The example of cum(5) = 5 helps as I see
> the parameter is the increment?
No problem. The parameter is indeed the increment. Note that it
need not be a constant, but you could have
CC := cum(CLOSE)
to have
CC(t) := CC(t-1) + CLOSE(t)
You could even use a formula, say you want to calculate a volume
weighted average, you can do something like
CUM(CLOSE*VOLUME)/CUM(VOLUME)
Just some off-the-cuff examples, they may very well contain some bugs....
> {long}
> setbars:=3;
> entryadd:=1;
> ff:=Mov(Stoch(7,1),3,E);
> ss:=Mov(Mov(Stoch(16,1),3,E),3,E);
> cbuy:=If(ff<=Ref(ff,-1) AND ss>=Ref(ss,-1),Cum(1),0);
> bbuy:=If(cbuy>=setbars,H+entryadd, 99999);
> bbuy<99999
In terms of this, I think the heart of it is locked up in the last
three lines, so let us look at them, but I'll start from the last
one and work my way backwards! I think this will make things more
clear actually....
> bbuy<99999
This line basically returns a TRUE or FALSE, a yes or no if you want.
True if we are long, false if not. Note that it really hangs on just
one value, 99999. This value is just used as a type of a flag, so if
bbuy is equal to (or exceeds) this value, we are out.
> bbuy:=If(cbuy>=setbars,H+entryadd, 99999);
The second to last line sets this flag. If cbuy equals or exceeds
setbars then bbuy becomes H (High) + entryadd, probably the cost
plus some slippage. Otherwise, the flag value of 99999 is assigned
and we are out.
> cbuy:=If(ff<=Ref(ff,-1) AND ss>=Ref(ss,-1),Cum(1),0);
Here we have the actual decision rule. If ff is falling and ss is
rising, cbuy takes on the ever-increasing cum(1) value, otherwise it
will take on zero.
Now, here is a different way of writing the same code that will
make things a lot clearer I think. Note that I have liberally changed
names and stuff to deliberately make it clearer. Again, some bugs may
remain. Please review the disclaimer.
Original version
----------------
> cbuy:=If(ff<=Ref(ff,-1) AND ss>=Ref(ss,-1),Cum(1),0);
> bbuy:=If(cbuy>=setbars,H+entryadd, 99999);
> bbuy<99999
New version
-----------
isLong := (Cum(1)>=setbars) AND (ff<=Ref(ff,-1)) AND (ss>=Ref(ss,-1));
costLong := isLong * ( HIGH + entryadd );
isLong
Regards
MG Ferreira
TsaTsa EOD Programmer and trading model builder
http://www.ferra4models.com
http://fun.ferra4models.com
--- In equismetastock@xxxxxxxxxxxxxxx, "dpleydel" <dpleydel@xxxx> wrote:
>
>
> Thanks for the replies. The example of cum(5) = 5 helps as I see
> the parameter is the increment?
>
> This is the full code I was trying to understand: (it's Linda
> Bradfords - Anti Indicator)
>
> {long}
> setbars:=3;
> entryadd:=1;
> ff:=Mov(Stoch(7,1),3,E);
> ss:=Mov(Mov(Stoch(16,1),3,E),3,E);
> cbuy:=If(ff<=Ref(ff,-1) AND ss>=Ref(ss,-1),Cum(1),0);
> bbuy:=If(cbuy>=setbars,H+entryadd, 99999);
> bbuy<99999
>
> Hence why I didn't understand why you would want to just accumlate
> the periods, like if it was period 100, 101, 103 etc as the test
> where cbuy >=3(setbar) seems strange as cum(1) will always be
> greater once we have more than 3 days (so the setbar seems
> unnecessary) unless as per your example where a mod functions was
> used to reset the sequence.
>
> David
>
> --- In equismetastock@xxxxxxxxxxxxxxx, "MG Ferreira" <quant@xxxx>
> wrote:
> >
> > Again, there is a bug in the code I posted previously. I have to
> > sincerely apologise - it seems each time I reread a posting I pick
> up
> > some errors in it! Please do accept my apologies.
> >
> > The mod function's arguments have to be swapped around, as follows:
> >
> > c = mod(cum(1)-1,n)
> >
> > to create a cycle of length 'n' and the example becomes
> >
> > c = mod(cum(1)-1,10)
> >
> > to create a cycle of length 10.
> >
> > Regards
> > MG Ferreira
> > TsaTsa EOD Programmer and trading model builder
> > http://www.ferra4models.com
> > http://fun.ferra4models.com
> >
> >
> > --- In equismetastock@xxxxxxxxxxxxxxx, "MG Ferreira" <quant@xxxx>
> wrote:
> > >
> > > Oops, just change
> > >
> > > C1(1) = 0
> > >
> > > to
> > >
> > > C1(1) = 1
> > >
> > > We often use
> > >
> > > cum(1) - 1
> > >
> > > which yields of course 0, 1, 2, ...
> > >
> > > This makes some of the math a lot easier, especially if you use
> mods,
> > > which is very useful in cyclical analysis. If you have something
> > > like
> > >
> > > c = mod(n,cum(1)-1)
> > >
> > > then c will be 0, 1, 2, ... n-1. Say you want to look at a
> cycle of
> > > length 10, then
> > >
> > > mod(10,cum(1)-1)
> > >
> > > will give 0, 1, 2 ... 9, 0, 1, 2 ... 9, 0, 1 and so on.
> > >
> > > Regards
> > > MG Ferreira
> > > TsaTsa EOD Programmer and trading model builder
> > > http://www.ferra4models.com
> > > http://fun.ferra4models.com
> > >
> > >
> > > --- In equismetastock@xxxxxxxxxxxxxxx, "MG Ferreira"
> <quant@xxxx> wrote:
> > > >
> > > > OK, this is just on the example specifically - see Roy's reply
> as
> > > > well for better examples of using the cum(1) function.
> > > >
> > > > > buy:=If (some boolean test),cum(1),0)
> > > > >
> > > > > Does this mean it's like this
> > > > > If TRUE then
> > > > > buy = buy + 1;
> > > > > else
> > > > > buy = 0;
> > > >
> > > > This is actually NOT what the MS statement does. It starts off
> > > > by creating a time series that accumulates by 1 each bar. Let
> us
> > > > call this C1 to clarify, say
> > > >
> > > > C1 = cum(1)
> > > >
> > > > so
> > > >
> > > > C1(1) = 0
> > > >
> > > > and
> > > >
> > > > C1(t) = C1(t-1) + 1
> > > >
> > > > or, simply,
> > > >
> > > > C1 = 1, 2, 3, 4 ....
> > > >
> > > > Note (this is sometimes useful) if you had something like
> > > >
> > > > C2 = cum(5)
> > > >
> > > > then
> > > >
> > > > C2 = 5, 10, 15, 20 ...
> > > >
> > > > Now, what that MS line of code you gave does, is to switch
> between
> > > > either zero or C1. So if you are at time period 100, and
> previously
> > > > the boolean test was false, but now is true, that function
> will return
> > > > 100, then 101, 102 ..., and not 1, 2, 3 ... as your code
> implies. So
> > > > maybe the code should be
> > > >
> > > > increment c1 REGARDLESS
> > > > if true then
> > > > result = c1
> > > > else
> > > > result = zero
> > > >
> > > > Regards
> > > > MG Ferreira
> > > > TsaTsa EOD Programmer and trading model builder
> > > > http://www.ferra4models.com
> > > > http://fun.ferra4models.com
> > > >
> > > >
> > > > --- In equismetastock@xxxxxxxxxxxxxxx, "dpleydel"
> <dpleydel@xxxx>
> > wrote:
> > > > >
> > > > >
> > > > > Hi
> > > > >
> > > > > I've looked at the primer but I still don't quite get what
> this
> > > > > function is doing.
> > > > >
> > > > > for example I've seen it used in a this this regard:
> > > > >
> > > > > buy:=If (some boolean test),cum(1),0)
> > > > >
> > > > > Does this mean it's like this
> > > > > If TRUE then
> > > > > buy = buy + 1;
> > > > > else
> > > > > buy = 0;
> > > > >
> > > > > Thanks
> > > > > David
------------------------ Yahoo! Groups Sponsor --------------------~-->
Has someone you know been affected by illness or disease?
Network for Good is THE place to support health awareness efforts!
http://us.click.yahoo.com/Rcy2bD/UOnJAA/cosFAA/BefplB/TM
--------------------------------------------------------------------~->
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/equismetastock/
<*> To unsubscribe from this group, send an email to:
equismetastock-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|