logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
mutkan  
#1 Posted : Monday, December 14, 2015 4:55:59 PM(UTC)
mutkan

Rank: Newbie

Groups: Registered Users, Subscribers, Unverified Users
Joined: 12/14/2015(UTC)
Posts: 6

Thanks: 1 times

Hi,

 

I am having trouble in getting rid of PREV. Can you help out advising another formula to replace PREV.

 

ma1:=Mov(ROC(C,1,$)*V,14,S);

ma2:=Mov(ROC(C,1,$)*V,28,S);
bset:=Cross(ma1,ma2);
sset:=Cross(ma2,ma1) AND Max(ma1,ma2)<0;
setup:=If(bset,1, If(sset,-1,PREV));
xs:=Cross(C,ValueWhen(1,bset,H)) AND setup=1;
es:=Cross(ValueWhen(1,sset,L),C) AND
BarsSince(sset)<=20 AND setup=-1;
trade:=If(es,1,If(xs,0,PREV));
Cross(trade=1,0.5)
mstt  
#2 Posted : Monday, December 14, 2015 8:45:04 PM(UTC)
mstt

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 mutkan This modified code will miss the first signal but all other signals agree with the code you include. The offset lines of setup and trade have been changed and now use ValueWhen() rather than PREV. It's possible to include the first (missing) signal bit it requires the the use of what I call the "I" or "Initialize" variable to allow the first signal to be recognized.What the I variable does is mark the bar when two (or more if used) inputs (both or all) generate a valid rather than N/A signal. An I variable prevents an active signal from being masked by an N/A plot elsewhere in your code. I can give examples, but not right now. Write to me at rlarsen@quik.co.nz if you need more information. I notice that this code is only generating entry signals, and not any exit signals, so i suspect what you've posted is not the complete original formula.. ma1:=Mov(ROC(C,1,$)*V,14,S); ma2:=Mov(ROC(C,1,$)*V,28,S); bset:=Cross(ma1,ma2); sset:=Cross(ma2,ma1) AND Max(ma1,ma2)<0; setup:=ValueWhen(1,bset OR sset,bset-sset); xs:=Cross(C,ValueWhen(1,bset,H)) AND setup=1; es:=Cross(ValueWhen(1,sset,L),C) AND BarsSince(sset)<=20 AND setup=-1; trade:=ValueWhen(1,es OR xs,If(es,1,0)); Cross(trade=1,0.5); Roy
musician  
#3 Posted : Thursday, December 17, 2015 2:19:24 PM(UTC)
musician

Rank: Newbie

Groups: Registered Users, Subscribers
Joined: 12/17/2015(UTC)
Posts: 1

Hi Guys,

I have a similir problem like mutkan. Please see my codes below, i neen to eliminate all of the PREVs.
İ would be grateful to anyone can help me about it.

A1:=Mov( C,7,E) ;

A2:=If(A1*0.9>PREV,A1*0.9,If(A1*0.95<PREV,A1*0.95,PREV));

Int(A2/0.025+0.50)*0.025



Edited by user Friday, December 18, 2015 7:20:29 AM(UTC)  | Reason: the last line of the formula have not been copy-pasted.

mstt  
#4 Posted : Wednesday, May 11, 2016 2:16:26 AM(UTC)
mstt

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)
mstt  
#5 Posted : Thursday, May 12, 2016 2:06:27 AM(UTC)
mstt

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)
The following two "Darvas" indicators no longer have PREV in the code. Note also that the indicator names have been changed so that the old and new do not get mixed up. Roy {MS11 (2) - Darvas Box High} periods:= 100; dh:=Ref(H,-3) >= Ref(HHV(H,Periods),-4) AND Ref(H,-3) > HHV(H,3); def:=Cum(IsDefined(dh))=1; dh:= If(dh, Ref(H,-3), ValueWhen(1,def OR dh, 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); dbhi:=ValueWhen(1,def OR dbe*IsDefined(ValueWhen(2,1,dbe)),dh); z:=BarsSince(Cum(dbe)=2)>=0; If(dbhi=0,H+0.0000001,dbhi)*z {MS11 (2) - Darvas Box Low} periods:= 100; dh:=ValueWhen(4,1,H); dh:=dh>=Ref(HHV(H,Periods),-4) AND dh>HHV(H,3); def:=Cum(IsDefined(dh))=1; dh:=ValueWhen(1,def OR dh,Ref(H,-3)); dl:=ValueWhen(4,1,L)<LLV(L,3) AND HHV(H,3)<dh; def:=ValueWhen(2,1,Cross(IsDefined(dh),0.5)); ndh:=Cross(def,0.5) OR ROC(dh,1,$)<>0; ndl:=Cross(def OR dl,0.5); end:=BarsSince(ndh) < BarsSince(ValueWhen(2,1,ndl)); def2:=Cum(IsDefined(end))=1; dbe:=Cross(def2,0.5) OR (end AND ndl); L3:=Ref(L,-3); I:=Cum(ndl+L3>-1)=1; dl2:=If(ndl,L3,ValueWhen(1,I+ndl,L3)); dblo:=ValueWhen(1,dbe AND IsDefined(ValueWhen(2,1,dbe)),dl2); z:=BarsSince(Cum(dbe)=2)>=0; If(dblo=0,L-0.0000001,dblo)*z
mstt  
#6 Posted : Friday, May 13, 2016 4:43:04 AM(UTC)
mstt

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)
Here's another couple of MS 11 "Helper" formulas with PREV removed and ValueWhen() effectively substituting for PREV {# Equis (2) - Stop Chandelier Buy Stop} {This indicator is not designed to be plotted .It exists to assist other equis formula calculations} ATRFactor:=(1+(ATR(9)/C)); I:=Fml("# Equis - Helper Pivot High")=1; Pivot:=If(I,HHV(H,2),ValueWhen(1,I,HHV(H,2))); stop:=LowestSince(1,pivot=Ref(H,-1) ,L)*ATRFactor; stop; {# Equis (2) - Stop Chandelier Sell Stop} {This indicator is not designed to be plotted .It exists to assist other equis formula calculations} ATRFactor:=(1-(ATR(9)/C)); I:=Fml("# Equis - Helper Pivot Low")=1; Pivot:=If(I,LLV(L,2),ValueWhen(1,I,LLV(L,2))); stop:=HighestSince(1,pivot=Ref(L,-1) ,H)*ATRFactor; stop; Here's another formula that works well but has absolutely too many PREV functions, 18 in fact. The problem with this code is not the fault of the author because this formula could not be coded without PREV. At the time it was created there was no DLL function to take over the PREV calculations. A later version of the formula follows after the original and it uses the MSTT DLL created by Scott Bunny. The TS2 function in the DLL combines both long and short trailing stops. {Quantitive Qualitative Estimation (QQE)} {Smoothed RSI} {Coding by Preston Umrysh} RSIndex:= Mov(RSI(C,14), 2, E); {Smoothed ATR of Smoothed RSI} TH:= If(Ref(RSIndex,-1) > RSIndex, Ref(RSIndex,-1), RSIndex); TL:= If(Ref(RSIndex,-1) < RSIndex, Ref(RSIndex,-1), RSIndex); TR:= TH-TL; AtrRsi:= Wilders(TR, 14); SmoothedAtrRsi:= Wilders(AtrRsi, 14); {Fast and Slow ATR Trailing Levels} DeltaFastAtrRsi:= SmoothedAtrRsi*2.6180; DeltaSlowAtrRsi:= SmoothedAtrRsi*4.2360; FastAtrRsiTL:=If(Ref(RSIndex,-1) > PREV AND RSIndex > PREV, Max(PREV, RSIndex-DeltaFastAtrRsi), If(Ref(RSIndex,-1) < PREV AND RSIndex < PREV, Min(PREV, RSIndex + DeltaFastAtrRsi), If(Cross(RSIndex, PREV), RSIndex - DeltaFastAtrRsi, If(Cross(PREV, RSIndex), RSIndex + DeltaFastAtrRsi, PREV)))); SlowAtrRsiTL:=If(Ref(RSIndex,-1) > PREV AND RSIndex > PREV, Max(PREV, RSIndex-DeltaSlowAtrRsi), If(Ref(RSIndex,-1) < PREV AND RSIndex < PREV, Min(PREV, RSIndex + DeltaSlowAtrRsi), If(Cross(RSIndex,PREV), RSIndex - DeltaSlowAtrRsi, If(Cross(PREV,RSIndex), RSIndex + DeltaSlowAtrRsi, PREV)))); RSIndex; FastAtrRsiTL; SlowAtrRsiTL; {end} {Quantitive Qualitative Estimation QQE (NP)} {Original code by Preston Umrysh} {Modified by Scott Bunny & Roy Larsen} {Smoothed RSI} RSIndex:=Mov(RSI(C,14),2,E); {Smoothed ATR of Smoothed RSI} TH:=Max(Ref(RSIndex,-1), RSIndex); TL:=Min(Ref(RSIndex,-1), RSIndex); TR:=TH-TL; AtrRsi:= Wilders(TR, 14); SmoothedAtrRsi:=Wilders(AtrRsi,14); {Fast and Slow ATR Trailing Levels} FastAtrRsiTL:=ExtFml("MSTT.TS2",RSIndex,SmoothedAtrRsi,2.618); SlowAtrRsiTL:=ExtFml("MSTT.TS2",RSIndex,SmoothedAtrRsi,4.236); {Plot} RSIndex; FastAtrRsiTL; SlowAtrRsiTL; Roy
Users browsing this topic
Guest (Hidden)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.