Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers Joined: 7/25/2005(UTC) Posts: 1,042
Was thanked: 57 time(s) in 54 post(s)
|
Hi musician
At the time you posted your formula I tried to eliminate PREV bur was unable to, and nothing has changed in that regard. The trick to eliminating PREV is to find a different way of capturing a previous value without actually using the PREV function. MetaStock version 11 (and I presume later versions too) arrived (some years ago) with a number of new formulas, notably "MS11 Adaptive" formulas and a few "Helper" formulas. A number of other new formulas were password protected so the acyual formulas are unknown quantities as far as users are concerned. There are two "Helper" formulas in particular that use several PREV functions. The original formulas can probably be found in later MS versions as well, and the formula names are ...
# Equis - Helper Darvas buy
# Equis - Helper Darvas sell
And here are modified versions of the originals that do not use PREV. The names are slightly different (for obvious reasons) but all signals agree with the original versions. The "trick" used here is essentially to replace PREV with a ValueWhen() function. This method is not applicable to all formulas with PREV, but it does work for those variables that have only one PREV function that generates a delayed version of the initial expression. There can be timing issues when PREV is eliminated, hence the use of the "z" variables which provide a signal starting point, usually an initial signal that all variables are defined (generating a real value or result rather than an N/A result).
Roy
{# Equis (2) - Helper Darvas buy}
{This indicator is not designed to be plotted. It exists to assist other Equis formula calculations}
Pds:= 100;
dh:=(Ref(H,-3) >=Ref(HHV(H,Pds),-4)) AND Ref(H,-3) > HHV(H,3);
z:=Cum(IsDefined(dh))=1;
dh:=If(dh,Ref(H,-3),ValueWhen(1,Z+dh,If(Z,0,Ref(H,-3))));
dl:=(Ref(L,-3)<LLV(L,3) AND HHV(H,3)<dh);
def:=Ref(Cross(IsDefined(dh),0.5),-1);
ndh:=Cross(def,0.5) OR ROC(dh,1,$)<>0;
ndl:=Cross(def,0.5) OR Cross(dl,0.5);
end:=BarsSince(ndh) < BarsSince(Ref(ndl,-1));
def2:=IsDefined(end)*IsUndefined(Ref(end,-1));
dbe:=Cross(def2,0.5)+(end*ndl);
dl2:=If(ndl,Ref(L,-3),ValueWhen(1,ndl,Ref(L,-3)));
z:=dbe*IsDefined(Ref(dbe,-1));
dblo:=If(z,dl2,ValueWhen(1,z*dl2, dl2 ));
dbhi:=If(z,dh,ValueWhen(1,z*dh,dh));
z:=BarsSince(Cum(dbe)=2)>=0;
dbl:=If(dblo=0,L-0.0000001,dblo)*Z;
dbh:=If(dbhi=0,H+0.0000001,dbhi)*Z;
dps:= Cross(L < dbl, 0.5);
sell:=BarsSince(dbe)<BarsSince(dps);
dc:=(sell=0)*Alert(sell,2);
db:=C>dbh AND (BarsSince(dbe)<BarsSince(dc));
dto:=If(db,1,If(dc,0,ValueWhen(1,db+dc,If(db,1,0))));
Cross(dto,0.5);
{# Equis (2) - Helper Darvas sell}
{This indicator is not designed to be plotted. It exists to assist other equis formula calculations}
pds:= 100;
dh:=(Ref(H,-3) >=Ref(HHV(H,Pds),-4)) AND Ref(H,-3) > HHV(H,3);
z:=Cum(IsDefined(dh))=1;
dh:=If(dh,Ref(H,-3),ValueWhen(1,Z+dh,If(Z,0,Ref(H,-3))));
dl:=(Ref(L,-3) < LLV(L,3) AND HHV(H,3) < dh);
def:=Ref(Cross(IsDefined(dh),0.5),-1);
ndh:=Cross(def,0.5) OR ROC(dh,1,$)<>0;
ndl:=Cross(def,0.5) OR Cross(dl,0.5);
end:=BarsSince(ndh) < BarsSince(Ref(ndl,-1));
def2:=IsDefined(end) AND IsUndefined(Ref(end,-1));
dbe:=Cross(def2,0.5) OR (end AND ndl);
dl2:=If(ndl,Ref(L,-3),ValueWhen(1,ndl,Ref(L,-3)));
z:=dbe*IsDefined(Ref(dbe,-1));
dblo:=If(z,dl2,ValueWhen(1,z*dl2, dl2 ));
z:=BarsSince(Cum(dbe)=2)>=0;
dbl:=If(dblo=0,L-0.0000001,dblo)*z;
dps:= Cross(L < dbl, 0.5);
sell:=BarsSince(dbe) < BarsSince(dps);
Cross(0.5,sell)
|