Rank: Advanced Member
Groups: Registered, Registered Users Joined: 1/19/2005(UTC) Posts: 1,065 Location: Koh Pha-Ngan, Earth
Was thanked: 2 time(s) in 2 post(s)
|
Patrick, probably some of the most useful variable-input functions would be the Ref(), HHV(), LLV(), BarsSince(), ValueWhen() and MA functions.
Ok, let's take an EMA with variable periods for example:
This won't work, as MetaStock's Moving Average function won't accept variable period inputs:
[code:1:d7705381b1]
{ Chart's ZigZag cycle length }
zz:=Zig(x,2,%);
zzpk:=Ref(zz,-1)>zz AND Ref(zz,-1)>Ref(zz,-2);
zztr:=Ref(zz,-1)<zz AND Ref(zz,-1)<Ref(zz,-2);
PkTr:=zzpk OR zztr;
CycleLength:=PkTr*(Ref(BarsSince(PkTr),-1)+1);
{ Variable-period EMA }
Mov(TrueRange,CycleLength,E)
[/code:1:d7705381b1]
This may work (I don't have MetaStock with me on holidays):
[code:1:d7705381b1]
{ Chart's ZigZag cycle length }
zz:=Zig(x,2,%);
zzpk:=Ref(zz,-1)>zz AND Ref(zz,-1)>Ref(zz,-2);
zztr:=Ref(zz,-1)<zz AND Ref(zz,-1)<Ref(zz,-2);
PkTr:=zzpk OR zztr;
CycleLength:=PkTr*(Ref(BarsSince(PkTr),-1)+1);
{ Convert CycleLength variable to static value }
CycleLength:=LastValue(CycleLength+PREV-PREV);
{ Variable-period EMA }
Mov(TrueRange,CycleLength,E)
[/code:1:d7705381b1]
Now, using an imaginery staticVar.dll to lock the CycleLength:
[code:1:d7705381b1]
{ Chart's ZigZag cycle length }
zz:=Zig(x,2,%);
zzpk:=Ref(zz,-1)>zz AND Ref(zz,-1)>Ref(zz,-2);
zztr:=Ref(zz,-1)<zz AND Ref(zz,-1)<Ref(zz,-2);
PkTr:=zzpk OR zztr;
CycleLength:=PkTr*(Ref(BarsSince(PkTr),-1)+1);
{ Convert CycleLength variable to static value}
CycleLength:=ExtFml("Const","CycleLength");
{ Variable-period EMA }
Mov(TrueRange,CycleLength,E)
[/code:1:d7705381b1]
jose '-)
http://metastocktools.com/#metastock
|