Traders' Tips from TASC Magazine

Targeting Your Pattern

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:

  1. In the Tools menu, select Expert Advisor.
  2. Click New to open the Expert Editor for a new expert.
  3. In the Tools menu, select Expert Advisor.
  4. Type a name for the expert, like "Pattern Analysis"
  5. Click the Commentary tab.
  6. Enter the following text:
  7. 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:

    1. Select the Symbols tab
    2. Click New to make a new symbol.
    3. Type the name of the symbol. (for example:"3535 pattern")
    4. 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

    5. Select the Graphics tab
    6. Choose a symbol (like diamond).
    7. Select a color for the symbol
    8. Choose whether to display the symbol above or below the price bar
    9. Click OK
    10. 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.
    11. Click OK to close the Expert Editor.

Contents