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

Notification

Icon
Error

Options
Go to last post Go to first unread
MetaReader  
#1 Posted : Tuesday, July 16, 2013 8:18:13 AM(UTC)
MetaReader

Rank: Newbie

Groups: Registered, Registered Users
Joined: 7/16/2013(UTC)
Posts: 7

I need a following formula without using PREV function, Trying for many days but no luck.

Formula:
Factor:=Input("Factor",1.00,10.00,3.00);
Pd:=Input("ATR Periods",1,100,10);
Up:=MP()+(Factor*ATR(Pd));
Dn:=MP()-(Factor*ATR(Pd));
Td:=If(Cross(C,LLV(Up,13)),1,If(Cross(HHV(Dn,13),C ),-1,PREV));
Dnx:=If(Dn=HighestSince(1,Cross(Td,0),Dn),Dn,PREV) ;
Upx:=If(Up=LowestSince(1,Cross(0,Td),Up),Up,PREV);
ST:=If(Td=1,Dnx,If(Td=-1,Upx,PREV));
ST

Your help is highly appreciated.
Thanks in advance..
mstt  
#2 Posted : Tuesday, July 16, 2013 4:09:10 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 MetaReader

Here's my non-PREV version of your formula. I've checked this formula with default settings on one chart (10 years of daily bars on DJIA) and the results appear to be identical. On some charts you might find that the new plot has more N/A results on the left side, caused by a normal trait of ValueWhen() that I've not made any effort to correct.

All PREVs have been removed by using the ValueWhen() function as a way of remembering previous values as set by specific events. Not all PREV-based formulas lend themselves to this conversion method, but a surprising number do.

Roy

Factor:=Input("Factor",1.00,10.00,3.00);
Pd:=Input("ATR Periods",1,100,10);
Up:=MP()+(Factor*ATR(Pd));
Dn:=MP()-(Factor*ATR(Pd));
Tn:= Cross(C,LLV(Up,13));
Tp:= Cross(HHV(Dn,13),C);
Td:=ValueWhen(1,Tp-Tn,Tn-Tp);
Dxx:=HighestSince(1,Cross(Td,0),Dn);
Dnx:=ValueWhen(1,Dn=Dxx,Dn);
Upp:=LowestSince(1,Cross(0,Td),Up);
Upx:=ValueWhen(1,Up=Upp,Up);
ST:=ValueWhen(1,Td,If(Td=1,Dnx,Upx));
ST;

MetaReader  
#3 Posted : Wednesday, July 17, 2013 1:50:59 AM(UTC)
MetaReader

Rank: Newbie

Groups: Registered, Registered Users
Joined: 7/16/2013(UTC)
Posts: 7

Thanks a lot. This is what I was looking for. Thanks again.
MetaReader  
#4 Posted : Wednesday, July 17, 2013 1:58:41 AM(UTC)
MetaReader

Rank: Newbie

Groups: Registered, Registered Users
Joined: 7/16/2013(UTC)
Posts: 7

See if you can help me out on this too, Now I need a formula without using cum function, following formula is to identify WEDGE

Formula:
{Two Trend-lines Wedges Scale from right}

pv:= Input("VeryLong=4,Long=3,Med=2,Short=1",1,4,4);
pp:= LastValue(If(pv=4,4,If(pv=3,2,If(pv=2,1,0.5))));
r0:= If(MP()>=Ref(MP(),-1),ATR(1),0);
r1:= Log(If(r0>0,ATR(1),HIGH)/HIGH);
r2:= Cum(r1)/Max(1,Cum(If(r0>0,1,0)));
r3:= LastValue(100*Exp(LastValue(r2)))*pp;
r4:= LastValue(PeakBars(2,H,r3))-LastValue(PeakBars(1,H,r3));
r5:= (LastValue(Peak(1,H,r3))-LastValue(Peak(2, H,r3)))/r4; {slope}
r6:= LastValue(Peak(2, H,r3))+(r5*(Cum(1)-LastValue(Cum(1)- PeakBars(2,H,r3))));
r7:= If(Cum(1) <lastValue(Cum(1)-PeakBars(2,H,r3)),BarsSince(Cum(1)>=LastValue(Cum(1)-PeakBars( 2,H,r3))),r6);
s0:= If(MP()<=Ref(MP(),-1),ATR(1),0);
s1:= Log(If(s0>0,ATR(1),LOW)/LOW);
s2:= Cum(s1)/Max(1,Cum(If(s0>0,1,0)));
s3:= LastValue(100*Exp(LastValue(s2)))*pp;
s4:= LastValue(TroughBars(2,L,s3))-LastValue(TroughBars(1,L,s3));
s5:= (LastValue(Trough(1,L,s3))-LastValue(Trough(2,L,s3)))/s4; {slope}
s6:= LastValue(Trough(2,L,s3))+(s5*(Cum(1)-LastValue(Cum(1)-TroughBars(2,L,s3))));
s7:= If(Cum(1)<lastValue(Cum(1)-TroughBars(2,L,s3)),BarsSince(Cum(1)>=LastValue(Cum(1 )-TroughBars(2, L,s3))),s6);
r7;s7;
mstt  
#5 Posted : Wednesday, July 17, 2013 3:53:40 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 MetaReader

Might I ask what your reason is for wanting to get rid of the Cum() functions? Without knowing the reason it's rather a pointless exercise. I doubt that execution speed is an issue, so what's the problem?

Roy
MetaReader  
#6 Posted : Wednesday, July 17, 2013 5:04:07 AM(UTC)
MetaReader

Rank: Newbie

Groups: Registered, Registered Users
Joined: 7/16/2013(UTC)
Posts: 7

I am having metastock as well as FinTrader (local system), which has same formula language like metastock, But in that language there are few functions missing like cum and prev, I have managed to build some of my favourite formulas there, the reason I am working on FinTrader because they have there own system that works pretty well, and so putting my favorite indicators there. Please help me this time.. Thanks in advance.
mstt  
#7 Posted : Wednesday, July 17, 2013 6:19:11 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 MetaReader

The formula below no longer has any Cum() functions. Cum(1) has been replaced by the new C1 variable
C1:=BarsSince(IsUndefined(Ref(C,-1)))+1;
However it is not so easy to eliminate the remaining 4 Cum() functions. My quick solution probably won't run in FinTrader and more tha Cum() will, so there's potentially still a problem to be solved. The MetaStock solution for non-contiguous values is to use the Forum DLL Sum function. This allows a variable lookback period for summing all relevant values from bar one.

There's a distinct possibility that the IsDefined() and IsUndefined() are also absent from FinTrader, and if that's the case your solution is probably as far away as ever.

Here's my revised formula. I hope it helps.

Roy

{Two Trend-lines Wedges Scale from right}

pv:=Input("VeryLong=4,Long=3,Med=2,Short=1",1,4,4);
pp:= LastValue(If(pv=4,4,If(pv=3,2,If(pv=2,1,0.5))));
C1:=BarsSince(IsUndefined(Ref(C,-1)))+1;
r0:=If(MP()>=Ref(MP(),-1),ATR(1),0);
r1:= Log(If(r0>0,ATR(1),H)/H);
d:=ExtFml("Forum.SUM",r0>0,C1);
r2:=ExtFml("Forum.SUM",r1,C1)/(d+(d=0));
r3:=LastValue(100*Exp(LastValue(r2)))*pp;
r4:=LastValue(PeakBars(2,H,r3))-LastValue(PeakBars(1,H,r3));
r5:=(LastValue(Peak(1,H,r3))-LastValue(Peak(2, H,r3)))/r4; {slope}
r6:=LastValue(Peak(2,H,r3))+
(r5*(C1-LastValue(C1-PeakBars(2,H,r3))));
r7:=If(C1<LastValue(C1-PeakBars(2,H,r3)),BarsSince(C1>=LastValue(C1-PeakBars( 2,H,r3))),r6);
s0:= If(MP()<=Ref(MP(),-1),ATR(1),0);
s1:= Log(If(s0>0,ATR(1),L)/L);
d:=ExtFml("Forum.SUM",s0>0,C1);
s2:=ExtFml("Forum.SUM",s1,C1)/(d+(d=0));
s3:= LastValue(100*Exp(LastValue(s2)))*pp;
s4:=LastValue(TroughBars(2,L,s3))-LastValue(TroughBars(1,L,s3));
s5:= (LastValue(Trough(1,L,s3))-LastValue(Trough(2,L,s3)))/s4; {slope}
s6:=LastValue(Trough(2,L,s3))+
(s5*(C1-LastValue(C1-TroughBars(2,L,s3))));
s7:=If(C1<LastValue(C1-TroughBars(2,L,s3)),BarsSince(C1>=LastValue(C1-TroughBars(2,L,s3))),s6);
r7; s7;


MetaReader  
#8 Posted : Thursday, July 18, 2013 12:29:57 AM(UTC)
MetaReader

Rank: Newbie

Groups: Registered, Registered Users
Joined: 7/16/2013(UTC)
Posts: 7

Thanks man, I do not know if it works or not, but I really appreciate your help.
MetaReader  
#9 Posted : Thursday, July 18, 2013 2:53:51 AM(UTC)
MetaReader

Rank: Newbie

Groups: Registered, Registered Users
Joined: 7/16/2013(UTC)
Posts: 7

Hi,

d:=ExtFml("Forum.SUM",r0>0,C1);

can you please explain what this line do exactly? So I can get full understanding of "Forum.SUM" functionality..


mstt  
#10 Posted : Thursday, July 18, 2013 5:10:28 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 MetaTrader

The MetaStock ExtFml() function calls the named DLL from the "External Function DLLs" folder (under the MetaStock\Formulas folder for MS 12, or under the MetaStock folder for earlier versions). The Forum DLL can be downloaded from this site as the ForumDll_200 file in the Files section. This is a 188KB file. The file name must be changed to "Forum.DLL" to be compatible with my code, and MetaStock must be restarted before any newly installed (or copied) DLL will be recognized by MS.

The Sum function in this DLL is, for the most part at least, the same as the standard MetaStock Sum() function, and you can look that up in the User Manual if you're unsure of its syntax. The difference is that the DLL-based function allows the Periods parameter to be a variable number, whereas the standard Sum() function requires a constant as the Periods parameter.

So the "d" variable sums the number of times that the expression "r0>0" is TRUE, and the Periods parameter uses a variable that emulates the count value of Cum(1). That is, the lookback range (of the Sum function) will be 20 bars on the 20th bar, 100 bars on the 100th bar and 1000 bars on the 1000th bar. Neither Cum(1) nor my "C1" variable can be used as the lookback Periods parameter in the standard Sum function, and that's because neither of them are constants.

In the MetaStock version of the adapted formula the "ExtFml("Forum.SUM",r0>0,C1)" expression generates the same result as "Cum(r0>0)", i.e., it progressively counts the number of times "r0" is greater than zero at every point across the chart.

Roy
MetaReader  
#11 Posted : Friday, July 19, 2013 3:13:50 AM(UTC)
MetaReader

Rank: Newbie

Groups: Registered, Registered Users
Joined: 7/16/2013(UTC)
Posts: 7

Hi Roy,

Its a great help. Thanks
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.