home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / finance / tas515dm.zip / EXAMPLES.ZIP / PA1.TAS < prev    next >
Text File  |  1992-11-20  |  10KB  |  312 lines

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