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

Notification

Icon
Error

Options
Go to last post Go to first unread
bigboom  
#1 Posted : Saturday, July 22, 2006 6:47:36 PM(UTC)
bigboom

Rank: Newbie

Groups: Registered, Registered Users
Joined: 7/13/2006(UTC)
Posts: 5

I want to use a certain formula that scans and filters certains securities wheter being true or not. The problem i encounter is that my formula is too long in length. The formula is entered in the filtersection of the explorer. Does anyone have a clue to work around this? Should i split the formula in seperate functions for instance? If so, can someone help me get started how this works?
Jose  
#2 Posted : Saturday, July 22, 2006 7:40:39 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)
Post your code here, and we'll take a look at possible ways to make it fit into the 2,500 character formula limit. jose '-)
mstt  
#3 Posted : Saturday, July 22, 2006 7:46:09 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)
Bigboom There are a number of ways you can economise on space to get your formula to fit. Splitting the formula and using Fml() calls is one way but not necessarily the best way. I'd suggest that you first shorten variable names. This can make a huge saving. There are, I think, 14 letters in the alphabet that can serve as names, A, B, D, F, G, I etc. Another ploy is to use * as a substitute for AND, and you can also use + as a substitute for OR. Savings with these two methods are usually eroded somewhat by the extra brackets needed to keep the formula logically correct. Eliminate spurious spaces and brackets wherever you can, same for comments if the formula is only for your own use. There are various other tricks that that can also make small space savings or allow you to pack more functionality into the allotted space. Roy MetaStock Tips & Tools
Jose  
#4 Posted : Saturday, July 22, 2006 8:12:43 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)
Roy wrote:
Another ploy is to use * as a substitute for AND, and you can also use + as a substitute for OR. Savings with these two methods are usually eroded somewhat by the extra brackets needed to keep the formula logically correct.
Roy, I can't think of a situation where additional brackets are needed when replacing AND/OR for */+. If anything, operator precedence usually means less parentheses are needed when using */+.
MetaStock help wrote:
When parentheses are not used, the precedence is as follows: - Negative values * Multiplication / Division + Addition - Subtraction < Less than > Greater than <= Less than or equal to >= Greater than or equal to = Equal to <> Not equal to And Logical "And" Or Logical "Or" := Variable assignment operator
Also, beware when replacing OR with +, as in some instances this creates unexpected results. jose '-)
bigboom  
#5 Posted : Saturday, July 22, 2006 10:12:41 PM(UTC)
bigboom

Rank: Newbie

Groups: Registered, Registered Users
Joined: 7/13/2006(UTC)
Posts: 5

Well thanks already guys! I am happily suprised to get feedback this fast :-) I will check out the Fml() function some more as i already came across this in the manual. And further i will check out the substitutes for AND and OR. Thanks Roy for this advice! Anyway, i am really a newbie to metastock. I have a background as a programmer, therefore my interest in this amazing program! What i try to do is convert my existing code that i've used before in telechart (maybe somewhat familiar to some of you guys) In Telechart i was able to scan securities with an algorithm using so called Personal Criteria Formula's. As far as i've discovered this is the same as you can do with the Explorer. What I thusfar found (with shortened versions of the code) was that it took much more time with Metastock to calculate this formula. The formula I use is to plot different kinds of morning/eveningstars. The code is right now only adjusted to the different syntax. For instance the Close of two days ago i usually wrote C2 and now Ref(C,-2). Because of the limited length you can use in a formula i was thinking of creating a different formula for the seperate stars. The formula below is for all kinds of morningstars (doji, kicker etc.) [code:1:9ad7398d88] (O >= Ref(C,-1) AND C > O AND Ref(O,-1) = Ref(C,-1) AND Ref(C,-1) <= Ref(C,-2) AND C > Ref(C,-2) AND Ref(C,-2) < Ref(O,-2) AND Ref(C,-2) < Ref(C,-3) AND V > Ref(V,-1) AND Stoch(12,3) <= 30 AND C > 10 AND C >= (((Ref(O,-2) - Ref(C,-2)) * 0.40) + Ref(C,-2)) AND ((Mov(C,30,S) =< C) OR (((Mov(C,30,S) - C) / C) => 0.058) OR (((Mov(C,30,S) - C) / C) =< 0.01)) AND ((C – O) / O) => 0.009) OR (Ref(O,-2) > Ref(C,-2) AND Ref(O,-1) = Ref(C,-1) AND Ref(C,-1) > Ref(C,-2) AND O < C AND O < Ref(O,-1) AND C > Ref(C,-1) AND Ref(C,-2) < Ref(C,-3) AND V > Ref(V,-1) AND Stoch(12,3) <= 30 AND C > 10 AND C >= (((Ref(O,-2) - Ref(C,-2)) * 0.40) + Ref(C,-2)) AND ((Mov(C,30,S) =< C) OR (((Mov(C,30,S) - C) / C) => 0.058) OR (((Mov(C,30,S) - C) / C) =< 0.01)) AND ((C – O) / O) => 0.009) OR (Ref(C,-2) < Ref(O,-2) AND Ref(O,-1) < Ref(C,-1) AND C > O AND O >= Ref(C,-1) AND Ref(C,-1) <= Ref(C,-2) AND Ref(C,-2) < Ref(C,-3) AND C > Ref(C,-2) AND V > Ref(V,-1) AND Stoch(12,3) <= 30 AND C > 10 AND C >= (((Ref(O,-2) - Ref(C,-2)) * 0.40) + Ref(C,-2)) AND ((Mov(C,30,S) =< C) OR (((Mov(C,30,S) - C) / C) => 0.058) OR (((Mov(C,30,S) - C) / C) =< 0.01)) AND ((C – O) / O) => 0.009) OR (Ref(C,-2) < Ref(O,-2) AND Ref(O,-1) < Ref(C,-1) AND C > O AND O <= Ref(O,-1) AND Ref(C,-2) <= Ref(O,-1) AND C > Ref(C,-1) AND Ref(C,-1) > Ref(C,-2) AND Ref(C,-2) < Ref(C,-3) AND V > Ref(V,-1) AND Stoch(12,3) <= 30 AND C > 10 AND C >= (((Ref(O,-2) - Ref(C,-2)) * 0.40) + Ref(C,-2)) AND ((Mov(C,30,S) =< C) OR (((Mov(C,30,S) - C) / C) => 0.058) OR (((Mov(C,30,S) - C) / C) =< 0.01)) AND ((C – O) / O) => 0.009) OR (Ref(C,-2) < Ref(O,-2) AND Ref(O,-1) =< Ref(C,-1) AND C > O AND Ref(O,-2) > Ref(C,-1) AND C > Ref(C,-1) AND Ref(C,-2) < Ref(C,-3) AND C > Ref(C,-2) AND Ref(O,-2) > Ref(O,-1) AND V > Ref(V,-1) AND Stoch(12,3) <= 30 AND C > 10 AND C >= (((Ref(O,-2) - Ref(C,-2)) * 0.40) + Ref(C,-2)) AND ((Mov(C,30,S) =< C) OR (((Mov(C,30,S) - C) / C) => 0.058) OR (((Mov(C,30,S) - C) / C) =< 0.01)) AND ((C – O) / O) => 0.009) OR (Ref(C,-2) < Ref(O,-2) AND C > O AND Ref(O,-2) > Ref(C,-1) AND C > Ref(C,-1) AND Ref(C,-2) < Ref(C,-3) AND C > Ref(C,-2) AND Ref(O,-2) > Ref(O,-1) AND O < Ref(O,-1) AND O < Ref(C,-1) AND V > Ref(V,-1) AND Stoch(12,3) <= 30 AND C > 10 AND C >= (((Ref(O,-2) - Ref(C,-2)) * 0.40) + Ref(C,-2)) AND ((Mov(C,30,S) =< C) OR (((Mov(C,30,S) - C) / C) => 0.058) OR (((Mov(C,30,S) - C) / C) =< 0.01)) AND ((C – O) / O) => 0.009) OR (Ref(C,-2) = Ref(O,-2) AND C > O AND Ref(O,-2) > Ref(C,-1) AND C > Ref(C,-1) AND Ref(C,-2) < Ref(C,-3) AND C > Ref(C,-2) AND Ref(O,-2) > Ref(O,-1) AND Ref(O,-2) => Ref(O,-1) AND V > Ref(V,-1) AND Stoch(12,3) <= 30 AND C > 10 AND C >= (((Ref(O,-2) - Ref(C,-2)) * 0.40) + Ref(C,-2)) AND ((Mov(C,30,S) =< C) OR (((Mov(C,30,S) - C) / C) => 0.058) OR (((Mov(C,30,S) - C) / C) =< 0.01)) AND ((C – O) / O) => 0.009) OR (Ref(C,-2) < Ref(O,-2) AND Ref(O,-1) > Ref(C,-1) AND C > O AND C > Ref(O,-1) AND Ref(C,-1) <= O AND Ref(C,-1) <= Ref(C,-2) AND C > Ref(C,-2) AND Ref(C,-2) < Ref(C,-3) AND V > Ref(V,-1) AND Stoch(12,3) <= 30 AND C > 10 AND C >= (((Ref(O,-2) - Ref(C,-2)) * 0.40) + Ref(C,-2)) AND ((Mov(C,30,S) =< C) OR (((Mov(C,30,S) - C) / C) => 0.058) OR (((Mov(C,30,S) - C) / C) =< 0.01)) AND ((C – O) / O) => 0.009) [/code:1:9ad7398d88]
mstt  
#6 Posted : Saturday, July 22, 2006 10:33:31 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)
Bigboom Expressions such as "((Mov(C,30,S)" should be assigned a variable name and then referred to using that variable name. Not only does that use less space but it also makes a formula much easier to follow and/or troubleshoot. Ma30:=((Mov(C,30,S); NextVar:= {... part of formula} AND (MA30=<C OR {... next part of formula, etc} Breaking the formula down into a number of variables would seem to be what's most needed here, and having someone else do that for you is not going to be as educational as struggling through the process for yourself will be. The User Manula has one or two examples of simplifying formulas and that is probably something you should check out fairly soon too. Roy MetaStock Tips & Tools
bigboom  
#7 Posted : Saturday, July 22, 2006 11:22:30 PM(UTC)
bigboom

Rank: Newbie

Groups: Registered, Registered Users
Joined: 7/13/2006(UTC)
Posts: 5

I am aware of it. The reason i posted is to get as much alternatives as possible to work around this. I am not quite familiar with the syntax of metastock. But indeed, breaking down the formula in more effecitve pieces with the use of variables is certainly a good idea. But my question was not to break it down for me as you stated in your reply. Thanks, i will dig into it.
mstt  
#8 Posted : Sunday, July 23, 2006 12:34:11 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)
Jose Precedence can work for us but it can also work against is. The compressed version of the following variable is meaningless and invalid unless brackets are added. There is a space saving, even with the brackets, so it works for me. Check:=X>2 AND Y>3 AND Z>4; Compressed down to a logical equivalent using "*" in place of "AND". Check:=(X>2)*(Y>3)*(Z>4); For those not in the know the following illustrations might help (or not as the case may be). TRUE AND TRUE returns a TRUE result. TRUE * TRUE returns a TRUE result (1*1 = 1). TRUE AND FALSE returns a FALSE result. TRUE * FALSE returns a FALSE result (1*0 = 0). FALSE AND TRUE returns a FALSE result. FALSE * TRUE returns a FALSE result (0*1 = 0). TRUE OR TRUE returns a TRUE result. TRUE + TRUE returns a TRUE result (1+1 = 2). TRUE OR FALSE returns a TRUE result. TRUE + FALSE returns a TRUE result (1+0 = 1). FALSE OR FALSE returns a FALSE result. FALSE + FALSE returns a FALSE result (0+0 = 0). Most MetaStock tools regard zero as a logical FALSE and all other values, even negative ones. as a logical TRUE. The Enhanced System Tester is a little different in that negative values and zero are all regarded as FALSE when used in a logical context. Knowing this, we can manipulate any series of numbers to deliver a "logical" result. Multiplying a series of numbers other than zero will always give a non-zero result. Even a negative result is regarded as a logical TRUE by all tools except the EST. One has to be a little more careful when substituting + for OR. That's because any negative component may allow a zero result, even when none of the constituents are zero. There's no problem when only positive numbers are used as it only takes one positive number to give a positive (TRUE) result. Roy MetaStock Tips & Tools
hayseed  
#9 Posted : Sunday, July 23, 2006 1:17:49 AM(UTC)
hayseed

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 3/7/2005(UTC)
Posts: 1,346

hey bigboom..... codes are not my forte, yet, but i believe your correct in saying , ' creating a different formula for the seperate stars ' .... it's easier to correct errors when its bite size pieces... noticed you have [color=red:88fa9f2599] =<[/color] several times, should that be reversed to <= .... noticed roy has it the same way, so perhaps its okay.... the explorer has 6 columns, so placing 3 or 4 per, could return the results easy enough and in a manageable form... are you after candlestick formations..... if so, meta already has about 50 common forms preprogramed in an easy to relate manner.... look in the functions section.... most often they are written by name, such as, TweezerTops() or MorningStar() or ShootingStar() or GravestoneDoji() or LongLeggedDoji() .... and it appears you've coded the nightmaredoji() for us..... h
Jose  
#10 Posted : Sunday, July 23, 2006 1:45:14 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)
mstt wrote:
One has to be a little more careful when substituting + for OR. That's because any negative component may allow a zero result, even when none of the constituents are zero. There's no problem when only positive numbers are used as it only takes one positive number to give a positive (TRUE) result.
Not quite - negative numbers don't come into the logical OR equation, and yet there can be a problem even with all positive integers: condition1 OR condition2 If any or both of these conditions are true, then a correct true result is given. condition1 + condition2 If more than one of these conditions is true, this results in a non-true (<>1) condition. (condition1 + condition2)>0 is messy, and quite easy to miss. Substituting OR with + is dangerous. jose '-
Jose  
#11 Posted : Sunday, July 23, 2006 1:50:40 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)
[code:1:593966bf78] (O >= Ref(C,-1) AND C > O AND Ref(O,-1) = Ref(C,-1) AND Ref(C,-1) <= Ref(C,-2) AND C > Ref(C,-2) AND Ref(C,-2) < Ref(O,-2) AND Ref(C,-2) < Ref(C,-3) AND V > Ref(V,-1) AND Stoch(12,3) <= 30 AND C > 10 AND C >= (((Ref(O,-2) - Ref(C,-2)) * 0.40) + Ref(C,-2)) AND ((Mov(C,30,S) =< C) OR (((Mov(C,30,S) - C) / C) => 0.058) OR (((Mov(C,30,S) - C) / C) =< 0.01)) AND ((C – O) / O) => 0.009) OR (Ref(O,-2) > Ref(C,-2) AND Ref(O,-1) = Ref(C,-1) AND Ref(C,-1) > Ref(C,-2) AND O < C AND O < Ref(O,-1) AND C > Ref(C,-1) AND Ref(C,-2) < Ref(C,-3) AND V > Ref(V,-1) AND Stoch(12,3) <= 30 AND C > 10 AND C >= (((Ref(O,-2) - Ref(C,-2)) * 0.40) + Ref(C,-2)) AND ((Mov(C,30,S) =< C) OR (((Mov(C,30,S) - C) / C) => 0.058) OR (((Mov(C,30,S) - C) / C) =< 0.01)) AND ((C – O) / O) => 0.009) OR (Ref(C,-2) < Ref(O,-2) AND Ref(O,-1) < Ref(C,-1) AND C > O AND O >= Ref(C,-1) AND Ref(C,-1) <= Ref(C,-2) AND Ref(C,-2) < Ref(C,-3) AND C > Ref(C,-2) AND V > Ref(V,-1) AND Stoch(12,3) <= 30 AND C > 10 AND C >= (((Ref(O,-2) - Ref(C,-2)) * 0.40) + Ref(C,-2)) AND ((Mov(C,30,S) =< C) OR (((Mov(C,30,S) - C) / C) => 0.058) OR (((Mov(C,30,S) - C) / C) =< 0.01)) AND ((C – O) / O) => 0.009) OR (Ref(C,-2) < Ref(O,-2) AND Ref(O,-1) < Ref(C,-1) AND C > O AND O <= Ref(O,-1) AND Ref(C,-2) <= Ref(O,-1) AND C > Ref(C,-1) AND Ref(C,-1) > Ref(C,-2) AND Ref(C,-2) < Ref(C,-3) AND V > Ref(V,-1) AND Stoch(12,3) <= 30 AND C > 10 AND C >= (((Ref(O,-2) - Ref(C,-2)) * 0.40) + Ref(C,-2)) AND ((Mov(C,30,S) =< C) OR (((Mov(C,30,S) - C) / C) => 0.058) OR (((Mov(C,30,S) - C) / C) =< 0.01)) AND ((C – O) / O) => 0.009) OR (Ref(C,-2) < Ref(O,-2) AND Ref(O,-1) =< Ref(C,-1) AND C > O AND Ref(O,-2) > Ref(C,-1) AND C > Ref(C,-1) AND Ref(C,-2) < Ref(C,-3) AND C > Ref(C,-2) AND Ref(O,-2) > Ref(O,-1) AND V > Ref(V,-1) AND Stoch(12,3) <= 30 AND C > 10 AND C >= (((Ref(O,-2) - Ref(C,-2)) * 0.40) + Ref(C,-2)) AND ((Mov(C,30,S) =< C) OR (((Mov(C,30,S) - C) / C) => 0.058) OR (((Mov(C,30,S) - C) / C) =< 0.01)) AND ((C – O) / O) => 0.009) OR (Ref(C,-2) < Ref(O,-2) AND C > O AND Ref(O,-2) > Ref(C,-1) AND C > Ref(C,-1) AND Ref(C,-2) < Ref(C,-3) AND C > Ref(C,-2) AND Ref(O,-2) > Ref(O,-1) AND O < Ref(O,-1) AND O < Ref(C,-1) AND V > Ref(V,-1) AND Stoch(12,3) <= 30 AND C > 10 AND C >= (((Ref(O,-2) - Ref(C,-2)) * 0.40) + Ref(C,-2)) AND ((Mov(C,30,S) =< C) OR (((Mov(C,30,S) - C) / C) => 0.058) OR (((Mov(C,30,S) - C) / C) =< 0.01)) AND ((C – O) / O) => 0.009) OR (Ref(C,-2) = Ref(O,-2) AND C > O AND Ref(O,-2) > Ref(C,-1) AND C > Ref(C,-1) AND Ref(C,-2) < Ref(C,-3) AND C > Ref(C,-2) AND Ref(O,-2) > Ref(O,-1) AND Ref(O,-2) => Ref(O,-1) AND V > Ref(V,-1) AND Stoch(12,3) <= 30 AND C > 10 AND C >= (((Ref(O,-2) - Ref(C,-2)) * 0.40) + Ref(C,-2)) AND ((Mov(C,30,S) =< C) OR (((Mov(C,30,S) - C) / C) => 0.058) OR (((Mov(C,30,S) - C) / C) =< 0.01)) AND ((C – O) / O) => 0.009) OR (Ref(C,-2) < Ref(O,-2) AND Ref(O,-1) > Ref(C,-1) AND C > O AND C > Ref(O,-1) AND Ref(C,-1) <= O AND Ref(C,-1) <= Ref(C,-2) AND C > Ref(C,-2) AND Ref(C,-2) < Ref(C,-3) AND V > Ref(V,-1) AND Stoch(12,3) <= 30 AND C > 10 AND C >= (((Ref(O,-2) - Ref(C,-2)) * 0.40) + Ref(C,-2)) AND ((Mov(C,30,S) =< C) OR (((Mov(C,30,S) - C) / C) => 0.058) OR (((Mov(C,30,S) - C) / C) =< 0.01)) AND ((C – O) / O) => 0.009) [/code:1:593966bf78] I suspect that the above code is someone's attempt at a practical joke, but for the sake of educational purposes, let's see what we can do to: 1) Make it readable; 2) Understand the logic; 3) Speed up processing.
Jose  
#12 Posted : Sunday, July 23, 2006 1:52:49 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)
[code:1:5d25b0bf0f] O>=Ref(C,-1) AND C>O AND Ref(O,-1)=Ref(C,-1) AND Ref(C,-1)<=Ref(C,-2) AND C>Ref(C,-2) AND Ref(C,-2)<Ref(O,-2) AND Ref(C,-2)<Ref(C,-3) AND V>Ref(V,-1) AND Stoch(12,3)<=30 AND C>10 AND C>=((Ref(O,-2)-Ref(C,-2))*.4+Ref(C,-2)) AND (Mov(C,30,S)<=C OR (Mov(C,30,S)-C)/C>=.058 OR (Mov(C,30,S)-C)/C<=.01) AND (C-O)/O>=.009 OR Ref(O,-2)>Ref(C,-2) AND Ref(O,-1)=Ref(C,-1) AND Ref(C,-1)>Ref(C,-2) AND O<C AND O<Ref(O,-1) AND C>Ref(C,-1) AND Ref(C,-2)<Ref(C,-3) AND V>Ref(V,-1) AND Stoch(12,3)<=30 AND C>10 AND C>=((Ref(O,-2)-Ref(C,-2))*.4+Ref(C,-2)) AND (Mov(C,30,S)<=C OR (Mov(C,30,S)-C)/C>=.058 OR (Mov(C,30,S)-C)/C<=.01) AND (C-O)/O>=.009 OR Ref(C,-2)<Ref(O,-2) AND Ref(O,-1)<Ref(C,-1) AND C>O AND O>=Ref(C,-1) AND Ref(C,-1)<=Ref(C,-2) AND Ref(C,-2)<Ref(C,-3) AND C>Ref(C,-2) AND V>Ref(V,-1) AND Stoch(12,3)<=30 AND C>10 AND C>=((Ref(O,-2)-Ref(C,-2))*.4+Ref(C,-2)) AND (Mov(C,30,S)<=C OR (Mov(C,30,S)-C)/C>=.058 OR (Mov(C,30,S)-C)/C<=.01) AND (C-O)/O>=.009 OR Ref(C,-2)<Ref(O,-2) AND Ref(O,-1)<Ref(C,-1) AND C>O AND O<=Ref(O,-1) AND Ref(C,-2)<=Ref(O,-1) AND C>Ref(C,-1) AND Ref(C,-1)>Ref(C,-2) AND Ref(C,-2)<Ref(C,-3) AND V>Ref(V,-1) AND Stoch(12,3)<=30 AND C>10 AND C>=((Ref(O,-2)-Ref(C,-2))*.4+Ref(C,-2)) AND (Mov(C,30,S)<=C OR (Mov(C,30,S)-C)/C>=.058 OR (Mov(C,30,S)-C)/C<=.01) AND (C-O)/O>=.009 OR Ref(C,-2)<Ref(O,-2) AND Ref(O,-1)<=Ref(C,-1) AND C>O AND Ref(O,-2)>Ref(C,-1) AND C>Ref(C,-1) AND Ref(C,-2)<Ref(C,-3) AND C>Ref(C,-2) AND Ref(O,-2)>Ref(O,-1) AND V>Ref(V,-1) AND Stoch(12,3)<=30 AND C>10 AND C>=((Ref(O,-2)-Ref(C,-2))*.4+Ref(C,-2)) AND (Mov(C,30,S)<=C OR (Mov(C,30,S)-C)/C>=.058 OR (Mov(C,30,S)-C)/C<=.01) AND (C-O)/O>=.009 OR Ref(C,-2)<Ref(O,-2) AND C>O AND Ref(O,-2)>Ref(C,-1) AND C>Ref(C,-1) AND Ref(C,-2)<Ref(C,-3) AND C>Ref(C,-2) AND Ref(O,-2)>Ref(O,-1) AND O<Ref(O,-1) AND O<Ref(C,-1) AND V>Ref(V,-1) AND Stoch(12,3)<=30 AND C>10 AND C>=((Ref(O,-2)-Ref(C,-2))*.4+Ref(C,-2)) AND (Mov(C,30,S)<=C OR (Mov(C,30,S)-C)/C>=.058 OR (Mov(C,30,S)-C)/C<=.01) AND (C-O)/O>=.009 OR Ref(C,-2)=Ref(O,-2) AND C>O AND Ref(O,-2)>Ref(C,-1) AND C>Ref(C,-1) AND Ref(C,-2)<Ref(C,-3) AND C>Ref(C,-2) AND Ref(O,-2)>Ref(O,-1) AND Ref(O,-2)>=Ref(O,-1) AND V>Ref(V,-1) AND Stoch(12,3)<=30 AND C>10 AND C>=((Ref(O,-2)-Ref(C,-2))*.4+Ref(C,-2)) AND (Mov(C,30,S)<=C OR (Mov(C,30,S)-C)/C>=.058 OR (Mov(C,30,S)-C)/C<=.01) AND (C-O)/O>=.009 OR Ref(C,-2)<Ref(O,-2) AND Ref(O,-1)>Ref(C,-1) AND C>O AND C>Ref(O,-1) AND Ref(C,-1)<=O AND Ref(C,-1)<=Ref(C,-2) AND C>Ref(C,-2) AND Ref(C,-2)<Ref(C,-3) AND V>Ref(V,-1) AND Stoch(12,3)<=30 AND C>10 AND C>=((Ref(O,-2)-Ref(C,-2))*.4+Ref(C,-2)) AND (Mov(C,30,S)<=C OR (Mov(C,30,S)-C)/C>=.058 OR (Mov(C,30,S)-C)/C<=.01) AND (C-O)/O>=.009 [/code:1:5d25b0bf0f]
Jose  
#13 Posted : Sunday, July 23, 2006 1:55: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)
[code:1:541b6d44a3] { Declare variables } Op1:=Ref(O,-1); Op2:=Ref(O,-2); Cl1:=Ref(C,-1); Cl2:=Ref(C,-2); Cl3:=Ref(C,-3); SMA:=Mov(C,30,S); { Common (universal) condition } cond:=C>10 AND C>O AND C>=((Op2-Cl2)*.4+Cl2) AND (C-O)/O>=.009 AND Cl2<Cl3 AND V>Ref(V,-1) AND (SMA<=C OR (SMA-C)/C>=.058 OR (SMA-C)/C<=.01) AND Stoch(12,3)<=30; { Condition 1 } cond1:=O>=Cl1 AND Op1=Cl1 AND Op2>Cl2 AND C>Cl2 AND Cl1<=Cl2; { Condition 2 } cond2:=O<Op1 AND Op1=Cl1 AND Op2>Cl2 AND Sum(C>Cl1,2)=2; { Condition 3 } cond3:=O>=Cl1 AND Op1<Cl1 AND Op2>Cl2 AND C>Cl2 AND Cl1<=Cl2; { Condition 4 } cond4:=O<=Op1 AND Op1<Cl1 AND Op1>=Cl2 AND Op2>Cl2 AND Sum(C>Cl1,2)=2; { Condition 5 } cond5:=Op1<Op2 AND Op1<=Cl1 AND Op2>Cl1 AND Op2>Cl2 AND C=HHV(C,3); { Condition 6 } cond6:=Sum(O<Op1,2)=2 AND O<Cl1 AND Op2>Cl1 AND Op2>Cl2 AND C=HHV(C,3); { Condition 7 } cond7:=Op1<=Op2 AND Op2>Cl1 AND Op2=Cl2 AND C=HHV(C,3); { Condition 8 } cond8:=O>=Cl1 AND Sum(Op1>Cl1,2)=2 AND C>Op1 AND C>Cl2 AND Cl1<=Cl2; { Plot signals in own window } cond*(cond1 OR cond2 OR cond3 OR cond4 OR cond5 OR cond6 OR cond7 OR cond8) [/code:1:541b6d44a3] jose '-)
Jose  
#14 Posted : Sunday, July 23, 2006 2:12:05 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)
Roy, to further illustrate that + is not a good replacement for OR, compare the output of these two (almost identical) indicators: [code:1:75fa79d41c]x:=true; y:=true; condition:=x OR y; If(condition=true,true,false) [/code:1:75fa79d41c] [code:1:75fa79d41c]x:=true; y:=true; condition:=x + y; If(condition=true,true,false) [/code:1:75fa79d41c] jose '-)
wabbit  
#15 Posted : Sunday, July 23, 2006 3:46:49 AM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
bigboom, I have taken a part your code and can save you about two thirds.... just be using better LOGIC. I have to go to golf now, but I will post my code for you, and the explanation of how to make your system better, tonight when I get home, or maybe tomorrow if I have to much to drink tonight! wabbit :D
mstt  
#16 Posted : Sunday, July 23, 2006 5:25:11 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)
Jose "Equality" is not the same thing as "logical equivalent of". Your code sets and tests for a value EQUAL to 1 (which is normally but not always used as the logical equivalent of TRUE). If you remove the test for equality from your example and instead test for the logical state I think you'll find that a value of 2 (1+1) is considered to be a logical TRUE, just as the value of 1 is. x:=true; y:=true; condition:=x + y; If(condition,true,false); Testing for equality is something that can deliver unexpected results. Most of us know how easily precision errors creep in with fractional numbers, and I'd warn users against testing for equality where the possibility of such errors exists (admittedly that's a quite different problem from that demonstrated by your example). The expression (3 AND -5) returns a logical TRUE. That's 1, not zero or -2. The AND forces MetaStock to treat each number as a logical state rather than a number, and the conclusion that MS comes to is that each number is a logical TRUE. MetaStock assigns values of zero or one (0 or 1) to logical results, but it certainly isn't restricted to interpreting only those two numbers as logical values. I think it's helpful for MS users to understand when and where a number can be used as a logical state. Not only will this keep them out of trouble through sloppy coding but it opens up new ways of solving some formula problems (space or whatever). Roy MetaStock Tips & Tools
Jose  
#17 Posted : Sunday, July 23, 2006 6:52:10 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)
My advice to anyone wishing to avoid any potential MS problems is simple: Use logical operators (AND/OR) exclusively for logical conditions, and keep mathematical operators (+-*/) for mathematical calculations. jose '-)
bigboom  
#18 Posted : Sunday, July 23, 2006 3:00:30 PM(UTC)
bigboom

Rank: Newbie

Groups: Registered, Registered Users
Joined: 7/13/2006(UTC)
Posts: 5

Quote:
I suspect that the above code is someone's attempt at a practical joke, but for the sake of educational purposes, let's see what we can do to: 1) Make it readable; 2) Understand the logic; 3) Speed up processing.
Well actually it's not an attempt at a practial joke but looking through the eyes of an experienced programmer that code is ofcourse terribly unefficient and messy. Anyway, the program I used before does not have the flexible programminginterface as MetaStock has. The only possibillity was to write the code in a simple linear way. Thanks Jose for breaking down the code. It indeed represents the 8 different kind of morningstars that the code supposed to filter out. Thanks for the help.
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.