home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / finance / tas515dm.zip / TAS514.EXE / lha / PA1.TAS < prev    next >
Text File  |  1993-03-18  |  10KB  |  325 lines

  1. #TITLE Performance Analysis Script to show top 10/bottom 10 changes
  2. { PA1.TAS
  3.     Script to create Performance Analytics report 1
  4.                     The Week in Review
  5.         Top Ten Positive % Change   Top Ten Negative % Change
  6.         Top Ten $ Gainers             Top Ten $ Losers
  7.         Top Ten Volume % Gainers for Week
  8.         Top Ten Technical Improvement   Top Ten Technically Deteriorating
  9. }
  10. #output_file pa1.lst N
  11. #max_quotes 100
  12. if not defined(Pause_Time) Then 
  13.     Pause_Time = 10;    { Pause for 10 seconds }
  14. if quote_count < 100 Then Goto notEnough;
  15. customer = 'Your name here';
  16. if period = 0 then
  17.     period = 5;     { use a 5 day period by default}
  18. if first_ticker then    { get the right date}
  19.     gooddate = date;
  20. if date <> gooddate then return;
  21. gosub BinaryWave;
  22. pctchg = roc(c,period,'%');
  23. dolchg = roc(c,period,'$');
  24. volchg = roc(sum(v,period),period,'%');
  25. sortout(ticker,fullname,pctchg,dolchg,volchg,c,t_bwave,y_bwave,
  26. {         1      2        3      4      5    6    7       8   }
  27.         t_bwave-y_bwave);
  28. {          9            }
  29. :NotEnough
  30. if last_ticker = 0 then return;
  31. page = 1;
  32. gosub heading0;
  33. rpttype = 'Positive % Change';
  34. gosub heading1;
  35. gosub heading2;
  36. sorton(3,'D');
  37. gosub listline;
  38. Pause(Pause_Time);
  39. rpttype = 'Negative % Change';
  40. gosub heading1;
  41. gosub heading2;
  42. sorton(3,'A');
  43. gosub listline;
  44. Pause(Pause_Time);
  45.  
  46. gosub newpage;
  47. rpttype = 'Dollar Gainers';
  48. gosub heading1;
  49. gosub heading2;
  50. sorton(4,'D');
  51. gosub listline;
  52. Pause(Pause_Time);
  53. rpttype = 'Dollar Losers';
  54. gosub heading1;
  55. gosub heading2;
  56. sorton(4,'A');
  57. gosub listline;
  58. Pause(Pause_Time);
  59. rpttype = '% Volume Gainers';
  60. gosub heading1;
  61. gosub heading2;
  62. sorton(5,'D');
  63. gosub listline;
  64. Pause(Pause_Time);
  65.  
  66. gosub newpage;
  67. rpttype = 'Technical Improvement';
  68. gosub heading1;
  69. gosub heading2;
  70. sorton(9,'D');
  71. gosub listline;
  72. Pause(Pause_Time);
  73.  
  74. rpttype = 'Technical Deterioration';
  75. gosub heading1;
  76. gosub heading2;
  77. sorton(9,'A');
  78. gosub listline;
  79. Pause(Pause_Time);
  80. return;
  81. :listline
  82. for i=1; i <= 10; i = i+1;
  83. begin
  84.     sortget(tickname,compname,pctchg,dolchg,volchg,currcls,
  85.         t_bwave,y_bwave,diff);
  86.     writeln(expand(
  87.         '%-8s %-16s %6.2f%% %7.2f %6.0f%% %8.2f %6.0f %5.0f %5.0f',
  88.             tickname,
  89.             compname,
  90.             pctchg,
  91.             dolchg,
  92.             volchg,
  93.             currcls,
  94.             t_bwave,
  95.             y_bwave,
  96.             diff));
  97.  
  98. end;
  99. return;
  100. :newpage
  101. writeln('\p');
  102. page = page+1;
  103. gosub heading0;
  104. return;
  105. :heading0
  106. write('Performance Analytics - Report ID PA1');
  107. writeln('\t\t\t\t\t\t\t\tPage ',format(page,'%2.0f'));
  108. writeln('Prepared for ',customer,' on ',date);
  109. writeln();
  110. return;
  111. :heading1
  112. writeln();
  113. writeln('\t\t\t\t\t\tTop Ten ',rpttype);
  114. writeln('\t\t\t\t\t\tFor Week Ending ',datestr(dates[0]));
  115. writeln();
  116. return;
  117. :heading2
  118. writeln('\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t--Performance--');
  119. writeln('Ticker   Company or        Percent  Dollar  Volume Current        Week');
  120. writeln('Symbol   Security Name      Change  Change  Change  Close   Today  Ago Change');
  121. writeln('-------- ----------------- ------- -------  ------ -------  ----- ----- -----');
  122. writeln();
  123. return;
  124.  
  125. {
  126.    This script contains the "Achelis Binary Wave(tm)" calculation
  127.    shown in the Metastock(*) 2.0 distribution system. It has been
  128.    modified to include the following indicators as well:
  129.                                     BUY         SELL
  130.       Chaikin's Oscillator          > 0         < 0
  131.       Parabolic SAR                 < C         > C
  132.       Commodity Channel Index      > 100       < -100
  133.    It is here to give an example of the kind of analysis
  134.    available with the TAS Script language.
  135.    The Metastock manual discusses this binary wave system on
  136.    page 187 of the User's Manual.
  137.    The script will put out a message if the value of the binary
  138.    wave changes from yesterday to today (the terms 'today' and
  139.    'yesterday' are used loosely, but meant to be the 'latest day'
  140.    and the 'day before', respectively).
  141.    Two variables are defined and updated as each of the four
  142.    individual binary wave formulas are checked.
  143.    They are:
  144.    "t_bwave" which is today's binary wave value (-7 to +7)
  145.             and
  146.    "y_bwave" which is yesterday's binary wave value (-7 to +7)
  147.    What we are looking for is a TRANSITION from yesterday to
  148.    today. If the stock moved to +7 today and it was lower yesterday,
  149.    perhaps this is a buying opportunity. If the stock moved to -7
  150.    perhaps it is a short sell.
  151. }
  152.  
  153. { This subroutine takes a variable PERIOD as the number of days to 
  154.   look back in computing "y_bwave" }
  155.  
  156. :BinaryWave
  157. lb = -period;            { Compute "look back" index }
  158. y_total : number;        { yesterday's total bwave }
  159. t_total : number;        { today's total bwave value }
  160. c_total : number;        { total changed bwave values}
  161. tick_total : number;     { ticker count }
  162. sell_count : number;     { total SELL's given }
  163. buy_count : number;      { total BUY's given }
  164. MACD_ARRAY : ARRAY;    { Place to put values for TODAY }
  165. MACDTRIG_ARRAY : ARRAY;
  166. MA20 : ARRAY;
  167. ROC12 : ARRAY;           { PLACE TO PUT RATE OF CHANGE }
  168. STOCH53 : ARRAY;                { PLACE TO PUT STOCH(5,3) VALUES }
  169. CO_ARRAY : ARRAY;
  170. CCI14 : ARRAY;          { PLACE TO PUT CCI(14) VALUES }
  171. SAR_A : ARRAY;          { PARABOLIC SAR ARRAY}
  172. y_bwave := 0;     { this is our 'score' yesterday}
  173. t_bwave := 0;     { this is our 'score' today}
  174. alert   := '         ';
  175. if FIRST_TICKER then
  176. begin
  177.     y_total = 0;        { yesterday's total bwave }
  178.     t_total = 0;        { today's total bwave value }
  179.     c_total = 0;        { total changed bwave values}
  180.     tick_total = 0;     { ticker count }
  181.     sell_count = 0;     { SELL count }
  182.     buy_count = 0;      { BUY count }
  183. end;
  184. BEGIN
  185.     {
  186.        First compute MACD Binary Wave for yesterday and today
  187.        Note that MACD() computes the 12 day EMA - 26 day EMA and places
  188.        the result in the array MACD_ARRAY. The 9 day EMA is computed
  189.        and placed in the result array MACDTRIG_ARRAY
  190.     }
  191.     MACD_ARRAY = MACD();
  192.     MACDTRIG_ARRAY = MACDTRIGGER();
  193.     {
  194.        Now compute 20-MA B-Wave
  195.     }
  196.     MA20 := mov(c,20,'E');   { Compute 20 unit EMA of close }
  197.     {
  198.        Now compute 12-ROC B-Wave
  199.     }
  200.     ROC12 := roc(c,12,'%');
  201.     {
  202.        Now compute 5-3 stochastic B-wave
  203.     }
  204.     STOCH53 := stoch(5,3);          { compute stoch(%K period, %K slow) }
  205.     {
  206.         check if Chaikin's AD oscillator is above or below 0
  207.     }
  208.     CO_ARRAY := CO();       { PLACE CHAIKIN'S OSCILLATOR IN CO_ARRAY}
  209.     {
  210.         check if CCI(14)  above +100 or below -100
  211.     }
  212.     CCI14 := cci(14);
  213.     {
  214.        check if Wilder's Parabolic is greater or less than close
  215.     }
  216.     SAR_A := SAR(.02,.20);
  217.  
  218.    { All arrays are calculated. Now do the checking of change }
  219.     IF MACD_ARRAY[0] > MACDTRIG_ARRAY[0] THEN
  220.        t_bwave := t_bwave + 1    { macd greater than trigger }
  221.     else
  222.        t_bwave := t_bwave - 1;   { macd less than trigger    }
  223.     if MACD_ARRAY[lb] > MACDTRIG_ARRAY[lb] then
  224.        y_bwave := y_bwave + 1    { macd greater than trigger }
  225.     else
  226.        y_bwave := y_bwave - 1;   { macd less than trigger    }
  227.     if c[0] > MA20 then    { compare today's close to today's ema}
  228.        t_bwave := t_bwave + 1    { ema greater than close }
  229.     else
  230.        t_bwave := t_bwave - 1;   { ema less than close    }
  231.    { compare yesterday's close to today's ema}
  232.     if c[lb] > MA20[lb] then 
  233.        y_bwave := y_bwave + 1    { ema greater than close }
  234.     else
  235.        y_bwave := y_bwave - 1;   { ema less than close    }
  236.     if ROC12 > 0 then
  237.        t_bwave := t_bwave + 1    { roc greater than 0 }
  238.     else
  239.        t_bwave := t_bwave - 1;   { roc less than 0    }
  240.     if ROC12[lb] > 0 then
  241.        y_bwave := y_bwave + 1    { roc greater than 0 }
  242.     else
  243.        y_bwave := y_bwave - 1;   { roc less than 0    }
  244.     if STOCH53[0] > 50 then
  245.        t_bwave := t_bwave + 1    { stoch greater than 50 }
  246.     else
  247.        t_bwave := t_bwave - 1;   { stoch less than 50    }
  248.     if STOCH53[lb] > 50 then
  249.        y_bwave := y_bwave + 1    { stoch greater than 50 }
  250.     else
  251.            y_bwave := y_bwave - 1;   { stoch less than 50    }
  252.     IF CO_ARRAY[0] > 0 THEN
  253.         t_bwave := t_bwave + 1
  254.     else
  255.         t_bwave := t_bwave - 1;
  256.     IF CO_ARRAY[lb] > 0 THEN
  257.         y_bwave := y_bwave + 1
  258.     else
  259.         y_bwave := y_bwave - 1;
  260.     if CCI14[0] < -100 then
  261.        t_bwave := t_bwave - 1
  262.     else
  263.     if CCI14[0] > 100 then
  264.        t_bwave := t_bwave + 1;
  265.     if CCI14[lb] < -100 then
  266.        y_bwave := y_bwave - 1
  267.     else
  268.     if CCI14[lb] > 100 then
  269.        y_bwave := y_bwave + 1;
  270.     if SAR_A[0] > C then    { if SAR above close, position is SHORT}
  271.        t_bwave := t_bwave-1
  272.     else
  273.        t_bwave := t_bwave+1;
  274.     if SAR_A[lb] > C[lb] then    { if SAR above close, position is SHORT}
  275.        y_bwave := y_bwave-1
  276.     else
  277.        y_bwave := y_bwave+1;
  278.     {
  279.        Okay, here we are at the end of the script. We have boiled
  280.        the formulas down to two values:
  281.        "t_bwave" which is today's binary wave value (-7 to +7)
  282.                 and
  283.        "y_bwave" which is yesterday's binary wave value (-7 to +7)
  284.     }
  285.     {
  286.        First, let's check if the wave moved to +7..if so, let's print
  287.        out it's value then and now
  288.     }
  289.     tick_total = tick_total + 1;    { add to count of tickers }
  290.     y_total = y_total + y_bwave;    { add yesterday's bwave to total}
  291.     t_total = t_total + t_bwave;    { add today's bwave to total}
  292.     c_total = c_total + diff;    { add diff in bwave to total}
  293.     buy_flag = 0;
  294.     sell_flag = 0;
  295.     alert = '         ';
  296.     if ((y_bwave < 7) and (t_bwave = 7)) then
  297.     begin
  298.         buy_flag = 1;
  299.         alert = '   BUY   ';
  300.         buy_count = buy_count + 1;
  301.     end
  302.     {
  303.        Now, let's check if the wave moved to -7..if so, let's print
  304.        out it's value then and now
  305.     }
  306.     else
  307.     if ((y_bwave > -7) and (t_bwave = -7)) then
  308.     begin
  309.         sell_flag =  1;
  310.         alert = '   SELL  ';
  311.         sell_count = sell_count + 1;
  312.     end;
  313. END;     { of if good_date = date }
  314. RETURN;
  315. if last_ticker then
  316. begin
  317.    writeln('\t\t\n\n------------- SUMMARY--------------------');
  318.    writeln('\tTickers Processed             ',INT(tick_total));
  319.    writeln('\tYesterday Binary Wave Average ',y_total/tick_total);
  320.    writeln('\tToday Binary Wave Average     ',t_total/tick_total);
  321.    writeln('\tAverage Change in Binary Wave ',c_total/tick_total);
  322.    writeln('\t',INT(buy_count),' BUY Signals');
  323.    writeln('\t',INT(sell_count),' SELL Signals');
  324. end;
  325.