home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / t / tas501.zip / H&S.TAS < prev    next >
Text File  |  1993-02-25  |  3KB  |  91 lines

  1. #TITLE Locate and graph Head and Shoulders patterns                   
  2. { H&S.TAS 
  3.        Head and Shoulders recognition script. 
  4.  
  5.        Note : This script requires TAS 4.08 or later to run
  6.  
  7.        This script will locate a "head and shoulders" pattern 
  8.        in the closing prices. It will also draw a graph of the
  9.        closing price array along with a line drawn across the 
  10.        neckline of the h&s formation.
  11.  
  12.        The script presently does not locate the h&s with a volume
  13.        filter. That will be added at some point.
  14.  
  15.        Author : Martin Moore
  16.        Date   : Oct 1991
  17.        Revision 1.0 - Original script
  18.        Revision 1.1 - Modified to take account of the angle of the
  19.                       neckline. Command line parameter @NeckAngle=n
  20.                       will set the angle under which the H&S is 
  21.                       considered selected.
  22.                       Modified to eliminate those cases where the
  23.                       left shoulder is beyond the first day of data.
  24.                       Modified to find first trough between right
  25.                       shoulder and head.
  26.        
  27.        Invocation:
  28.               TAS H&S tickername @NG=g; NeckAngle=n, CutOff=f
  29.               where  'g' is 1 if no graphs are to be produced
  30.                      'n' is the angle under which the neckline must
  31.                          be drawn
  32.                      'f' is the ZigZag percentage movement to draw on
  33.                          the closing prices
  34. }
  35. #max_quotes 200
  36. #output_file h&s.lst
  37.  
  38. ziga is an array;
  39. neckline is an array;
  40.  
  41. if cutoff = 0 then
  42.        cutoff = 5;
  43. if NeckAngle = 0 then
  44.        NeckAngle = 3;
  45. ziga = zig(c,cutoff,'%');
  46. pkr = peak(ziga,1);
  47. pkh = peak(ziga,2);
  48. pkl = peak(ziga,3);
  49. nopeak = -(quote_count)+1;
  50. { Make sure that all peaks are found..if no peak found, then
  51.   peak returns a positive number, otherwise it returns the
  52.   days in the past that the peak occurred at. Also, check to
  53.   be sure that we have all three peaks.}
  54. if (pkr = nopeak) or (pkh = nopeak) or (pkl = nopeak) then
  55.        return;
  56. cr = c[pkr];    { close price on right shoulder}
  57. ch = c[pkh];    { close price on head }
  58. cl = c[pkl];    { close price on left shoulder}
  59. if (cl < ch) and (ch > cr) then  {we have a H & S}
  60. begin
  61.        trough_number = 0;
  62.        trr = 0;
  63.        while (pkr < trr)
  64.        begin
  65.               trough_number = trough_number+1;
  66.            trr = trough(ziga,trough_number);
  67.        end;              
  68.     trl = trough(ziga,trough_number+1);
  69.     ctrr = c[trr];  { close on right shoulder trough}
  70.     ctrl = c[trl];  { close on left shoulder trough}
  71.        dydx = (ctrl-ctrr)/(trl-trr);
  72.        { Create a line parallel to the neckline so we can use the 
  73.          angle function}
  74.        for i = 1; i <= quote_count; i = i+1;
  75.               neckline[i] = dydx * i;
  76.        angleOfneckline = angle(neckline);
  77.        { Skip those with too steep a neckline angle}
  78.        if (angleOfneckline > NeckAngle) or (angleOfneckline < -NeckAngle) 
  79.               then return;
  80.        {writeln(ticker,dydx,angle(neckline));}
  81.        if NG = 1 return;
  82.        opengraph(3);
  83.        sizegraph(5,1,1)
  84.        graph(1,ziga);
  85.        {drawline(15,trl,ctrl,trr,ctrr);}
  86.        drawline(15,trl,ctrl,trr,ctrr,trl-10,0);  { FOR TAS 5.0 only}
  87.        graph(v,'volume',tsf(v,5),'Volume TSF');
  88.        graph(obv(),'On Balance Volume');
  89.        closegraph();
  90. end;
  91.