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

Notification

Icon
Error

Options
Go to last post Go to first unread
KTP2  
#1 Posted : Tuesday, May 11, 2010 2:24:04 PM(UTC)
KTP2

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 2/2/2007(UTC)
Posts: 367

Was thanked: 1 time(s) in 1 post(s)

Massimiliano Scorpio’s article, “Targeting Your Pattern,” describes a Easy Language Show Me study to analyze price patterns. Below is the formula to create a MetaStock Expert Advisor version of this study. Most of the Expert Advisor is contained in the Commentary and will produce a display similar to the example shown here. This is a mix of formatted text and formulas. You do not have to format your display to exactly match the sample output. Bolded and underlined text and bullets were used for esthetics but are not required.

To create the Expert Advisor in MetaStock:

    <li>In the Tools menu, select Expert Advisor. <li>Click New to open the Expert Editor for a new expert. <li>In the Tools menu, select Expert Advisor. <li>Type a name for the expert, like "Pattern Analysis" <li>Click the Commentary tab. <li>Enter the following text:

    Analysis of <NAME> (<symbol>)as of <date> The current bar has the Open/High/Low/Close pattern Writeval(p1:=Ref(L,-1)-ATR(10); p2:=Ref(L,-1); p3:=Ref((H+L)/2,-1); p4:=Ref(H,-1); p5:=Ref(H,-1)+ATR(10); If(O<=p1,0, If(O>p1 AND O<=p2,1, If(O>p2 AND O<=p3,2, If(O>p3 AND O<=p4,3, If(O>p4 AND O<=p5,4, 5))))),5.0) Writeval(p1:=Ref(L,-1)-ATR(10); p2:=Ref(L,-1); p3:=Ref((H+L)/2,-1); p4:=Ref(H,-1); p5:=Ref(H,-1)+ATR(10); If(H<=p1,0, If(H>p1 AND H<=p2,1, If(H>p2 AND H<=p3,2, If(H>p3 AND H<=p4,3, If(H>p4 AND H<=p5,4, 5))))),0.0) Writeval(p1:=Ref(L,-1)-ATR(10); p2:=Ref(L,-1); p3:=Ref((H+L)/2,-1); p4:=Ref(H,-1); p5:=Ref(H,-1)+ATR(10); If(L<=p1,0, If(L>p1 AND L<=p2,1, If(L>p2 AND L<=p3,2, If(L>p3 AND L<=p4,3, If(L>p4 AND L<=p5,4, 5))))),0.0) Writeval(p1:=Ref(L,-1)-ATR(10); p2:=Ref(L,-1); p3:=Ref((H+L)/2,-1); p4:=Ref(H,-1); p5:=Ref(H,-1)+ATR(10); If(C<=p1,0, If(C>p1 AND C<=p2,1, If(C>p2 AND C<=p3,2, If(C>p3 AND C<=p4,3, If(C>p4 AND C<=p5,4, 5))))),0.0) This means:

    • The Open is writeif(O<=Ref(L,-1)-ATR(10),"less than the previous bar's Low minus a 10-period Average True Range","writeif((O>Ref(L,-1)-ATR(10)) AND O<=Ref(L,-1),"less than the previous bar's Low but greater than the previous Low minus a 10-period Average True Range","writeif(O>Ref(L,-1) AND O<=Ref((H+L)/2,-1),"less than the previous bar's midpoint but greater than the previous Low","writeif(O>Ref((H+L)/2,-1) AND O<=Ref(H,-1),"greater than the previous bar's midpoint but less than the previous bar's High","writeif(O>Ref(H,-1) AND (O<=Ref(H,-1)+ATR(10)),"greater than the previous bar's High but less than the previous High plus a 10-period Average True Range","writeif(O>Ref(H,-1)+ATR(10),"greater than the previous bar's High plus a 10-period Average True Range.")")")")")")

    • The High is writeif(H<=Ref(L,-1)-ATR(10),"less than the previous bar's Low minus a 10-period Average True Range","writeif((H>Ref(L,-1)-ATR(10)) AND H<=Ref(L,-1),"less than the previous bar's Low but greater than the previous Low minus a 10-period Average True Range","writeif(H>Ref(L,-1) AND H<=Ref((H+L)/2,-1),"less than the previous bar's midpoint but greater than the previous Low","writeif(H>Ref((H+L)/2,-1) AND H<=Ref(H,-1),"greater than the previous bar's midpoint but less than the previous bar's High","writeif(H>Ref(H,-1) AND (H<=Ref(H,-1)+ATR(10)),"greater than the previous bar's High but less than the previous High plus a 10-period Average True Range","writeif(H>Ref(H,-1)+ATR(10),"greater than the previous bar's High plus a 10-period Average True Range.")")")")")")

    • The Low is writeif(L<=Ref(L,-1)-ATR(10),"less than the previous bar's Low minus a 10-period Average True Range","writeif((L>Ref(L,-1)-ATR(10)) AND L<=Ref(L,-1),"less than the previous bar's Low but greater than the previous Low minus a 10-period Average True Range","writeif(L>Ref(L,-1) AND L<=Ref((H+L)/2,-1),"less than the previous bar's midpoint but greater than the previous Low","writeif(L>Ref((H+L)/2,-1) AND L<=Ref(H,-1),"greater than the previous bar's midpoint but less than the previous bar's High","writeif(L>Ref(H,-1) AND (L<=Ref(H,-1)+ATR(10)),"greater than the previous bar's High but less than the previous High plus a 10-period Average True Range","writeif(L>Ref(H,-1)+ATR(10),"greater than the previous bar's High plus a 10-period Average True Range.")")")")")")

    • The Close is writeif(C<=Ref(L,-1)-ATR(10),"less than the previous bar's Low minus a 10-period Average True Range","writeif((C>Ref(L,-1)-ATR(10)) AND C<=Ref(L,-1),"less than the previous bar's Low but greater than the previous Low minus a 10-period Average True Range","writeif(C>Ref(L,-1) AND C<=Ref((H+L)/2,-1),"less than the previous bar's midpoint but greater than the previous Low","writeif(C>Ref((H+L)/2,-1) AND C<=Ref(H,-1),"greater than the previous bar's midpoint but less than the previous bar's High","writeif(C>Ref(H,-1) AND (C<=Ref(H,-1)+ATR(10)),"greater than the previous bar's High but less than the previous High plus a 10-period Average True Range","writeif(C>Ref(H,-1)+ATR(10),"greater than the previous bar's High plus a 10-period Average True Range.")")")")")")

    Out of the writeval(cum(1),0.0) prior bars, this pattern was repeated writeval( p1:=Ref(L,-1)-ATR(10); p2:=Ref(L,-1); p3:=Ref((H+L)/2,-1); p4:=Ref(H,-1); p5:=Ref(H,-1)+ATR(10); patpos:= If(O<=p1,0, If(O>p1 AND O<=p2,1, If(O>p2 AND O<=p3,2, If(O>p3 AND O<=p4,3, If(O>p4 AND O<=p5,4, 5)))))*1000 + If(H<=p1,0, If(H>p1 AND H<=p2,1, If(H>p2 AND H<=p3,2, If(H>p3 AND H<=p4,3, If(H>p4 AND H<=p5,4, 5)))))* 100 + If(L<=p1,0, If(L>p1 AND L<=p2,1, If(L>p2 AND L<=p3,2, If(L>p3 AND L<=p4,3, If(L>p4 AND L<=p5,4, 5)))))* 10 + If(C<=p1,0, If(C>p1 AND C<=p2,1, If(C>p2 AND C<=p3,2, If(C>p3 AND C<=p4,3, If(C>p4 AND C<=p5,4, 5))))); cum(patpos=lastvalue(patpos+prev-prev)),0.0) times.
    For this data the pattern has occured writeval( p1:=Ref(L,-1)-ATR(10); p2:=Ref(L,-1); p3:=Ref((H+L)/2,-1); p4:=Ref(H,-1); p5:=Ref(H,-1)+ATR(10); patpos:= If(O<=p1,0, If(O>p1 AND O<=p2,1, If(O>p2 AND O<=p3,2, If(O>p3 AND O<=p4,3, If(O>p4 AND O<=p5,4, 5)))))*1000 + If(H<=p1,0, If(H>p1 AND H<=p2,1, If(H>p2 AND H<=p3,2, If(H>p3 AND H<=p4,3, If(H>p4 AND H<=p5,4, 5)))))* 100 + If(L<=p1,0, If(L>p1 AND L<=p2,1, If(L>p2 AND L<=p3,2, If(L>p3 AND L<=p4,3, If(L>p4 AND L<=p5,4, 5)))))* 10 + If(C<=p1,0, If(C>p1 AND C<=p2,1, If(C>p2 AND C<=p3,2, If(C>p3 AND C<=p4,3, If(C>p4 AND C<=p5,4, 5))))); (cum(patpos=lastvalue(patpos+prev-prev))/cum(1))*100,5.1) percent of the time.
    On the writeval( p1:=Ref(L,-1)-ATR(10); p2:=Ref(L,-1); p3:=Ref((H+L)/2,-1); p4:=Ref(H,-1); p5:=Ref(H,-1)+ATR(10); patpos:= If(O<=p1,0, If(O>p1 AND O<=p2,1, If(O>p2 AND O<=p3,2, If(O>p3 AND O<=p4,3, If(O>p4 AND O<=p5,4, 5)))))*1000 + If(H<=p1,0, If(H>p1 AND H<=p2,1, If(H>p2 AND H<=p3,2, If(H>p3 AND H<=p4,3, If(H>p4 AND H<=p5,4, 5)))))* 100 + If(L<=p1,0, If(L>p1 AND L<=p2,1, If(L>p2 AND L<=p3,2, If(L>p3 AND L<=p4,3, If(L>p4 AND L<=p5,4, 5)))))* 10 + If(C<=p1,0, If(C>p1 AND C<=p2,1, If(C>p2 AND C<=p3,2, If(C>p3 AND C<=p4,3, If(C>p4 AND C<=p5,4, 5))))); cum(patpos=lastvalue(patpos+prev-prev))-1,0.0) previous occurrences of this pattern:
    The next days close was greater than its open writeval(p1:=Ref(L,-1)-ATR(10); p2:=Ref(L,-1); p3:=Ref((H+L)/2,-1); p4:=Ref(H,-1); p5:=Ref(H,-1)+ATR(10);
    patpos:= If(O<=p1,0, If(O>p1 AND O<=p2,1, If(O>p2 AND O<=p3,2, If(O>p3 AND O<=p4,3, If(O>p4 AND O<=p5,4, 5)))))*1000 + If(H<=p1,0, If(H>p1 AND H<=p2,1, If(H>p2 AND H<=p3,2, If(H>p3 AND H<=p4,3, If(H>p4 AND H<=p5,4, 5)))))* 100 + If(L<=p1,0, If(L>p1 AND L<=p2,1, If(L>p2 AND L<=p3,2, If(L>p3 AND L<=p4,3, If(L>p4 AND L<=p5,4, 5)))))* 10 + If(C<=p1,0, If(C>p1 AND C<=p2,1, If(C>p2 AND C<=p3,2, If(C>p3 AND C<=p4,3, If(C>p4 AND C<=p5,4, 5))))); cum(ref(patpos,-1)=lastvalue(patpos+prev-prev) AND C>O),0.0) time(s) or writeval(p1:=Ref(L,-1)-ATR(10); p2:=Ref(L,-1); p3:=Ref((H+L)/2,-1); p4:=Ref(H,-1); p5:=Ref(H,-1)+ATR(10); patpos:= If(O<=p1,0, If(O>p1 AND O<=p2,1, If(O>p2 AND O<=p3,2, If(O>p3 AND O<=p4,3, If(O>p4 AND O<=p5,4, 5)))))*1000 + If(H<=p1,0, If(H>p1 AND H<=p2,1, If(H>p2 AND H<=p3,2, If(H>p3 AND H<=p4,3, If(H>p4 AND H<=p5,4, 5)))))* 100 + If(L<=p1,0, If(L>p1 AND L<=p2,1, If(L>p2 AND L<=p3,2, If(L>p3 AND L<=p4,3, If(L>p4 AND L<=p5,4, 5)))))* 10 + If(C<=p1,0, If(C>p1 AND C<=p2,1, If(C>p2 AND C<=p3,2, If(C>p3 AND C<=p4,3, If(C>p4 AND C<=p5,4, 5))))); (cum(ref(patpos,-1)=lastvalue(patpos+prev-prev) and c>O))/cum(ref(patpos,-1)=lastvalue(patpos+prev-prev))*100,5.1)
    percent.

    The next days close was less than its open writeval(p1:=Ref(L,-1)-ATR(10); p2:=Ref(L,-1); p3:=Ref((H+L)/2,-1); p4:=Ref(H,-1); p5:=Ref(H,-1)+ATR(10); patpos:= If(O<=p1,0, If(O>p1 AND O<=p2,1, If(O>p2 AND O<=p3,2, If(O>p3 AND O<=p4,3, If(O>p4 AND O<=p5,4, 5)))))*1000 + If(H<=p1,0, If(H>p1 AND H<=p2,1, If(H>p2 AND H<=p3,2, If(H>p3 AND H<=p4,3, If(H>p4 AND H<=p5,4, 5)))))* 100 + If(L<=p1,0, If(L>p1 AND L<=p2,1, If(L>p2 AND L<=p3,2, If(L>p3 AND L<=p4,3, If(L>p4 AND L<=p5,4, 5)))))* 10 + If(C<=p1,0, If(C>p1 AND C<=p2,1, If(C>p2 AND C<=p3,2, If(C>p3 AND C<=p4,3, If(C>p4 AND C<=p5,4, 5))))); cum(ref(patpos,-1)=lastvalue(patpos+prev-prev) AND C < O),0.0) time(s) or writeval(p1:=Ref(L,-1)-ATR(10); p2:=Ref(L,-1); p3:=Ref((H+L)/2,-1); p4:=Ref(H,-1); p5:=Ref(H,-1)+ATR(10); patpos:= If(O <=p1,0, If(O>p1 AND O<=p2,1, If(O>p2 AND O<=p3,2, If(O>p3 AND O<=p4,3, If(O>p4 AND O<=p5,4, 5)))))*1000 + If(H<=p1,0, If(H>p1 AND H<=p2,1, If(H>p2 AND H<=p3,2, If(H>p3 AND H<=p4,3, If(H>p4 AND H<=p5,4, 5)))))* 100 + If(L<=p1,0, If(L>p1 AND L<=p2,1, If(L>p2 AND L<=p3,2, If(L>p3 AND L<=p4,3, If(L>p4 AND L<=p5,4, 5)))))* 10 + If(C<=p1,0, If(C>p1 AND C<=p2,1, If(C>p2 AND C<=p3,2, If(C>p3 AND C<=p4,3, If(C>p4 AND C<=p5,4, 5))))); (cum(ref(patpos,-1)=lastvalue(patpos+prev-prev) and c < O))/cum(ref(patpos,-1)=lastvalue(patpos+prev-prev))*100,5.1) percent.

    The next days close was equal to its open writeval(p1:=Ref(L,-1)-ATR(10); p2:=Ref(L,-1); p3:=Ref((H+L)/2,-1); p4:=Ref(H,-1); p5:=Ref(H,-1)+ATR(10); patpos:= If(O<=p1,0, If(O>p1 AND O<=p2,1, If(O>p2 AND O<=p3,2, If(O>p3 AND O<=p4,3, If(O>p4 AND O<=p5,4, 5)))))*1000 + If(H<=p1,0, If(H>p1 AND H<=p2,1, If(H>p2 AND H<=p3,2, If(H>p3 AND H<=p4,3, If(H>p4 AND H<=p5,4, 5)))))* 100 + If(L<=p1,0, If(L>p1 AND L<=p2,1, If(L>p2 AND L<=p3,2, If(L>p3 AND L<=p4,3, If(L>p4 AND L<=p5,4, 5)))))* 10 + If(C<=p1,0, If(C>p1 AND C<=p2,1, If(C>p2 AND C<=p3,2, If(C>p3 AND C<=p4,3, If(C>p4 AND C<=p5,4, 5))))); cum(ref(patpos,-1)=lastvalue(patpos+prev-prev) AND C=O),0.0) time(s) or writeval(p1:=Ref(L,-1)-ATR(10); p2:=Ref(L,-1); p3:=Ref((H+L)/2,-1); p4:=Ref(H,-1); p5:=Ref(H,-1)+ATR(10); patpos:= If(O<=p1,0, If(O>p1 AND O<=p2,1, If(O>p2 AND O<=p3,2, If(O>p3 AND O<=p4,3, If(O>p4 AND O<=p5,4, 5)))))*1000 + If(H<=p1,0, If(H>p1 AND H<=p2,1, If(H>p2 AND H<=p3,2, If(H>p3 AND H<=p4,3, If(H>p4 AND H<=p5,4, 5)))))* 100 + If(L<=p1,0, If(L>p1 AND L<=p2,1, If(L>p2 AND L<=p3,2, If(L>p3 AND L<=p4,3, If(L>p4 AND L<=p5,4, 5)))))* 10 + If(C<=p1,0, If(C>p1 AND C<=p2,1, If(C>p2 AND C<=p3,2, If(C>p3 AND C<=p4,3, If(C>p4 AND C<=p5,4, 5))))); (cum(ref(patpos,-1)=lastvalue(patpos+prev-prev) and c=O))/cum(ref(patpos,-1)=lastvalue(patpos+prev-prev))*100,5.1) percent.

    As a reminder, here are the definitions of the six numbers: 0: below the previous bar's low minus the value of the 10-bar ATR 1: between the previous bar's low and its low minus the value of the 10-bar ATR 2: between the previous bar's low and the middle of its range 3: between the previous bar's high and the middle of its range 4: between the previous bar's high and the high plus the value of the 10-bar ATR 5: above the previous bar's high plus the value of the 10-bar ATR

    After entering the above text, you may click OK to close the Expert Editor, or you may create symbols to show where specific patterns are occurring. For the latter:

      <li>Select the Symbols tab <li>Click New to make a new symbol. <li>Type the name of the symbol. (for example: "3535 pattern") <li>Click in the condition window and type in the following formula:

      target:=3535; p1:=Ref(L,-1)-ATR(10); p2:=Ref(L,-1); p3:=Ref((H+L)/2,-1); p4:=Ref(H,-1); p5:=Ref(H,-1)+ATR(10); patpos:=If(O<=p1,0, If(O>p1 AND O<=p2,1, If(O>p2 AND O<=p3,2, If(O>p3 AND O<=p4,3, If(O>p4 AND O<=p5,4, 5)))))*1000 + If(H<=p1,0, If(H>p1 AND H<=p2,1, If(H>p2 AND H<=p3,2, If(H>p3 AND H<=p4,3, If(H>p4 AND H<=p5,4, 5)))))* 100 + If(L<=p1,0, If(L>p1 AND L<=p2,1, If(L>p2 AND L<=p3,2, If(L>p3 AND L<=p4,3, If(L>p4 AND L<=p5,4, 5)))))* 10 + If(C<=p1,0, If(C>p1 AND C<=p2,1, If(C>p2 AND C<=p3,2, If(C>p3 AND C<=p4,3, If(C>p4 AND C<=p5,4, 5))))); patpos=target

      <li>Select the Graphics tab <li>Choose a symbol (like diamond). <li>Select a color for the symbol <li>Choose whether to display the symbol above or below the price bar <li>Click OK <li>Additional symbols can be created by repeating steps 7-14. To find different patterns, change the number on the first line to the desired pattern. Make sure this line ends with a semi-colon. <li>Click OK to close the Expert Editor.
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.