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

Notification

Icon
Error

Options
Go to last post Go to first unread
Jose  
#1 Posted : Thursday, May 12, 2005 6:46:49 PM(UTC)
Jose

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)
Due to the incredible response to the Ellipse indicator series (at least two replies), below is the final indicator in the Ellipse trilogy: triple Boxed Ellipse. Note the re-use of variables to allow MetaStock to use 60 variables (x3 maximum). MetaStock -> Tools -> Indicator Builder -> New -> Copy and paste complete formula between "---8<---" lines. =========== Boxed Ellipses =========== ---8<-------------------------- { Boxed Ellipses v2.0 Box: High & Low of selected period. Ellipse: plots within Box boundaries.} { ©Copyright 2005 Jose Silva For personal use only. http://www.metastocktools.com } pds1:=Input("Ellipse/Box width periods", 2,2600,40); pds2:=Input("Ellipse/Box separation periods", -26000,2600,5); plot:=Input("plot: [1]Box, [2]Ellipse, [3]Both",1,3,3); pds2:=LastValue(If(pds2<=-pds1,-pds1+1,pds2)); { Box & Ellipse 1 } p2:=pds2; p1:=pds1+p2; start:=Cum(1)=LastValue(Cum(1))-p1; end:=Cum(1)=LastValue(Cum(1))-p2; restrict:=Ref(Ref(ValueWhen(1,start,1),-p2),p2); Hi:=LastValue(Highest(ValueWhen(1,restrict,H))) +restrict-1; Lo:=LastValue(Lowest(ValueWhen(1,restrict,L))) +restrict-1; top:=If(start OR end,Lo,Hi); bot:=If(start OR end,Hi,Lo); midX:=(p1-p2)/2; midY:=(Hi-Lo)/2; tX:=Cum(1)-midX-(LastValue(Cum(1))-p1); ellipse:= Sqrt(midY*midY*(1-Min(tX*tX/midX/midX,1))); upperE:=Lo+midY+ellipse; lowerE:=Hi-midY-ellipse; If(plot=2,upperE,Hi); If(plot=2,lowerE,Lo); If(plot=2,upperE,top); If(plot=2,lowerE,bot); If(plot=1,top,upperE); If(plot=1,bot,lowerE); { Box & Ellipse 2 } p2:=p1+pds2; p1:=pds1+p2; start:=Cum(1)=LastValue(Cum(1))-p1; end:=Cum(1)=LastValue(Cum(1))-p2; restrict:=Ref(Ref(ValueWhen(1,start,1),-p2),p2); Hi:=LastValue(Highest(ValueWhen(1,restrict,H))) +restrict-1; Lo:=LastValue(Lowest(ValueWhen(1,restrict,L))) +restrict-1; top:=If(start OR end,Lo,Hi); bot:=If(start OR end,Hi,Lo); midX:=(p1-p2)/2; midY:=(Hi-Lo)/2; tX:=Cum(1)-midX-(LastValue(Cum(1))-p1); ellipse:= Sqrt(midY*midY*(1-Min(tX*tX/midX/midX,1))); upperE:=Lo+midY+ellipse; lowerE:=Hi-midY-ellipse; If(plot=2,upperE,Hi); If(plot=2,lowerE,Lo); If(plot=2,upperE,top); If(plot=2,lowerE,bot); If(plot=1,top,upperE); If(plot=1,bot,lowerE); { Box & Ellipse 3 } p2:=p1+pds2; p1:=pds1+p2; start:=Cum(1)=LastValue(Cum(1))-p1; end:=Cum(1)=LastValue(Cum(1))-p2; restrict:=Ref(Ref(ValueWhen(1,start,1),-p2),p2); Hi:=LastValue(Highest(ValueWhen(1,restrict,H))) +restrict-1; Lo:=LastValue(Lowest(ValueWhen(1,restrict,L))) +restrict-1; top:=If(start OR end,Lo,Hi); bot:=If(start OR end,Hi,Lo); midX:=(p1-p2)/2; midY:=(Hi-Lo)/2; tX:=Cum(1)-midX-(LastValue(Cum(1))-p1); ellipse:= Sqrt(midY*midY*(1-Min(tX*tX/midX/midX,1))); upperE:=Lo+midY+ellipse; lowerE:=Hi-midY-ellipse; If(plot=2,upperE,Hi); If(plot=2,lowerE,Lo); If(plot=2,upperE,top); If(plot=2,lowerE,bot); If(plot=1,top,upperE ---8<-------------------------- jose '-) http://www.metastocktools.com
Patrick  
#2 Posted : Thursday, May 19, 2005 3:37:18 AM(UTC)
Patrick

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 9/8/2004(UTC)
Posts: 2,266

Was thanked: 1 time(s) in 1 post(s)
A little of topic but I'm intrigued by
Quote:
Note the re-use of variables to allow MetaStock to use 60 variables (x3 maximum).
Do you mean that you can reuse the 20max variables only 3 timesin a formula? What happens if you reuse the variables more ? Or did I completely misunderstood you? Patrick
Jose  
#3 Posted : Thursday, May 19, 2005 5:19:03 AM(UTC)
Jose

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, I mean that variable names have been re-used three times over, although they can be reused several times more if necessary, as long as the 2.5Kb character space is not exceeded. For example in this indicator, had I named each variable differently, the formula would have needed at least 60 variable names, which is beyond MetaStock's 20-variable limit. The trick is to re-use variables no longer needed by MetaStock in the calculation of new values. It helps if we understand that MetaStock processes data bars from left to right (with the exception of hindsight-based functions), and calculates from top to bottom of formula for each data bar. Now, for a more important question: Patrick, how do I get an Avatar like yours? ;) jose '-) http://www.metastocktools.com
Patrick  
#4 Posted : Thursday, May 19, 2005 5:30:42 AM(UTC)
Patrick

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 9/8/2004(UTC)
Posts: 2,266

Was thanked: 1 time(s) in 1 post(s)
Thanks for the clarification Jose. I knew about the limitation you speak of but I though you discovered another one :P To get an avatar like mine, log in to the forum, click on profile on the main menu bar ( At the top in the green part :lol: ), scroll all the way down and upload your avatar. It has to be a .jpg or a .gif and : "Displays a small graphic image below your details in posts. Only one image can be displayed at a time, its width can be no greater than 150 pixels, the height no greater than 150 pixels, and the file size no more than 12 KB." Patrick
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.