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

Notification

Icon
Error

Options
Go to last post Go to first unread
vaughn  
#1 Posted : Sunday, May 22, 2005 1:33:46 AM(UTC)
vaughn

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 3/16/2005(UTC)
Posts: 93
Location: Maryland,US

I would like to see a Case statement for conditionals with multiple results instead of using nested if statements. Select Case (mov(C, 9, E)) Case C>mov(c,9,e) do something Case C<mov(c,9,e) do something else Case else do something altogether different End Select This is a cheesy example, but trapping for different possible outcomes of an expression with a Case type statement is a whole lot simpler than nested if statements. Expressions that have many possible outcomes the nested if statements look to get insanely complex to follow.
Jose  
#2 Posted : Sunday, May 22, 2005 6:09:09 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)
That would be a great idea, along with a possible MetaStock loop routine.
Quote:
... insanely complex to follow.
You want insanity? Try this simple nested If() code: ---8<------------ x:=C; If(x>1,x, If(x>2,x, If(x>3,x, If(x>4,x, If(x>5,x, If(x>6,x, If(x>7,x, If(x>8,x, If(x>9,x, If(x>10,x, If(x>11,x, If(x>12,x, If(x>13,x, If(x>14,x, If(x>15,x, If(x>16,x, If(x>17,x, If(x>18,x, If(x>19,x, If(x>20,x, If(x>21,x, If(x>22,x, If(x>23,x, If(x>24,x, If(x>25,x, If(x>26,x, If(x>27,x, If(x>28,x, If(x>29,x, If(x>30,x, 1)))))))))))))))))))))))))))))) ---8<------------ ... and time it to see how long MetaStock needs to process and plot it. Each new nested If() condition adds an exponential amount of processing time - the final result makes the PREV function look lightning fast. :) jose http://www.metastocktools.com
StorkBite  
#3 Posted : Sunday, May 22, 2005 7:19:03 AM(UTC)
StorkBite

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 3/19/2005(UTC)
Posts: 3,003

Was thanked: 11 time(s) in 9 post(s)
The Case statement would be nice 8)
LongShot  
#4 Posted : Wednesday, September 6, 2006 9:06:00 AM(UTC)
LongShot

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 4/4/2005(UTC)
Posts: 31

I think that in general, Metastock would benefit from a transition to an actual programming type language rather than its current "macro" language. I have seen lots of other software that use a rudimentary subset of Basic, Pascal, etc that once learned are far easier to manage than the current system.
dieselpr  
#5 Posted : Wednesday, September 6, 2006 8:05:08 PM(UTC)
dieselpr

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 4/27/2005(UTC)
Posts: 130

Please,please pretty please add a loop to metastock!!! O with sugar on top! I'd part with my money for that! Life would be so simple.... Any idea when metastock is planning to update, upgrade or re-design its option scope platforum?
vienna  
#6 Posted : Wednesday, December 30, 2009 4:57:29 AM(UTC)
vienna

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 12/14/2009(UTC)
Posts: 140
Location: Austria

Five years later it's still a great wish to use CASE statements. I'm waiting hours for 16 nested IF's only to be parsed for errors (when I'm changing tab's e.g. from "Buy Order" to "Sell Order" ) in the system editor.

Code:

y:=if(opt2=1, FmlVar("tci1","BUY"),
if(opt2=2,FmlVar("tci2","BUY"),
if(opt2=3,FmlVar("tci3","BUY"),
if(opt2=4,FmlVar("tci4","BUY"),
if(opt2=5,FmlVar("tci5","BUY"),
if(opt2=6,FmlVar("tci6","BUY"),
if(opt2=7,FmlVar("tci7","BUY"),
if(opt2=8,FmlVar("tci8","BUY"),
if(opt2=9,FmlVar("tci9","BUY"),
FmlVar("tci10","BUY"))))))))));

mstt  
#7 Posted : Wednesday, December 30, 2009 8:13:13 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 Vienna

The "Case statement" is not going to happen so don't hold your breath any longer. Part of your problem is the imbedded If() functions (I've found that around 10 is a practical limit for my code), but also a problem is the large number of Fml() calls. Limiting Fml() or FmlVar() calls to one or two and squeezing all possible code into the EST window would make a significant difference to execution speed. Since space is also problem in with EST windows you could consider optimising outside the EST. It's a little messy though so you might not want to go there.

If you insist on using FmlVar() calls then I think your code could be written without any If() functions. Using opt2=X as a multiplier means that only one FmlVar() is active at anone time. While I haven't tested this exact scenario I've used the same method in stighly different siations without any problems. Hope this helps.

y:=(opt2=1)*FmlVar("tci1","BUY") +
(opt2=2)*FmlVar("tci2","BUY") +
(opt2=3)*FmlVar("tci3","BUY") +
(opt2=4)*FmlVar("tci4","BUY") +
(opt2=5)*FmlVar("tci5","BUY") +
(opt2=6)*FmlVar("tci6","BUY") +
(opt2=7)*FmlVar("tci7","BUY") +
(opt2=8)*FmlVar("tci8","BUY") +
(opt2=9)*FmlVar("tci9","BUY") +
(opt2=10)*FmlVar("tci10","BUY");

Just my thoughts.

Roy

vienna  
#8 Posted : Thursday, December 31, 2009 12:52:51 AM(UTC)
vienna

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 12/14/2009(UTC)
Posts: 140
Location: Austria

Hi Roy,
thanks for your answer.
Yesterday (after waiting for hours - and than terminated the process) I came to this solution:
y:=if(opt2=1, FmlVar("tci1","SELLSHORT"),0);
y:=if(opt2=2,FmlVar("tci2","SELLSHORT"),y);
y:=if(opt2=3,FmlVar("tci3","SELLSHORT"),y);
y:=if(opt2=4,FmlVar("tci4","SELLSHORT"),y);
:
:
y:=if(opt2=15,FmlVar("tci15","SELLSHORT"),y);
y:=if(opt2=16,FmlVar("tci16","SELLSHORT"),y);
But Yours is much better!

Optimizing outside of EST is possible? Is there any example how this can be done?

Beside I wish you a Happy New Year :)

Edit:
I have currently found your tipp about using the gv.dll - http://forum.equis.com/forums/thread/11116.aspx - to bad that equis do not include such genial solutions/workarounds (you and the others have developed already years ago) into the newer versions of metastock
mstt  
#9 Posted : Thursday, December 31, 2009 2:21:22 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 Vienna

Here's an extract from an MSTT newsletter article that I wrote in May 2005. It expands a little on the concept but I have to warn you that it was primarily designed to handle two or three OPT values, not 16. Write to me at rlarsen@quik.co.nz if you want more information about the process.

Roy

"Optimization Outside The EST

One of the differences between the original System Tester and the Enhanced System Tester (EST) is that all formula windows are now restricted to 1023 characters. That’s little more than 40% of what was available in MS 7.22 and earlier versions. The difficulty that arises from the smaller window size is that some formulas that would have fitted comfortably in the Buy and Sell windows previously are now simply too large. This problem is more pronounced, say, when an optimized entry signal is also required as part of the exit formula. In that situation there’s a good chance that, even if one formula fits into the available space, there won’t be room for both formulas.

For experienced MS 7.0 and above users there’s a solution that shouldn’t prove too difficult. Even newer users should be able to use "Optimization outside the System Tester" once they understand the underlying principles. The versatile GlobalVar dll, written by Mark Pyle and found in many of my Trade Equity formulas, allows the System Tester "OPT" values to be saved as "global variables". These OPT values can be accessed by indicator formulas (using ExtFml()), and optimization performed on those formulas just as if they were inside the System Tester. Some rearrangement of code is necessary, but in most cases that should be easier to accomplish than compressing the existing code to fit into the limited space available.

The basic concept is simple. The System Tester must store OPT values as global variables, then call modified indicators to formulate buy, sell and price signals using the globally available OPT values. That sounds simple enough doesn’t it? Before you can fully appreciate this method though, you’ll probably need to familiarize yourself with the simpler task of calling non-optimized formulas to execute buy, sell and price functions in the System Tester. For example, instead of coding the entry formula directly into the Buy window, you would assign the formula an indicator name, such as "My Entry Signal", and use Fml("My Entry Signal") in the Buy window to call that formula from the Indictor Builder.

Remember, indicator formulas are available to all MetaStock tools. Formulas from other tools are only available to a specific exploration, expert or systems test. However, once global variables are created by one tool they become available to all other tools. Storing EST OPT values as global variables makes them "globally" available within MS.

Only the System Tester can use OPT constants – indicators can’t. Happily that problem is easily solved by using a different naming convention. The GV values can be stored as OPTA, OPTB and so on. You and I know that they’re still optimizing values, but MetaStock neither knows nor cares, just as long as the OPT1 format is only used in the System Tester, and the OPTX format is used elsewhere."

vienna  
#10 Posted : Monday, January 4, 2010 1:54:26 AM(UTC)
vienna

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 12/14/2009(UTC)
Posts: 140
Location: Austria

Hi Roy
many thanks - I have tested it with 16 values and it worked perfekt. I think it makes no difference if there are 3 or 16 opt-iterations, as long as there is only one opt variable involved. (I haven't tested it with more different optimization variables)

Example for other users, who are maybe interested in the solution:
EST:
Code:

:
ExtFml("gv.SetVar", "opt1", opt1);
ybuy:=Fml("tci_select_buy");
 :


Formula tci_select_buy:
Code:


op:=ExtFml( "gv.GetVar", "opt1");
y:=(op=1)* FmlVar("tci1","BUY")+(op=2)*FmlVar("tci2","BUY")+.....;
:



Users browsing this topic
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.