home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / finance / tas515dm.zip / EXAMPLES.ZIP / LINPR2.TAS < prev    next >
Text File  |  1993-01-19  |  4KB  |  116 lines

  1. {=====================================================================}
  2. {DESCRIPTION }
  3. {=====================================================================}
  4. {LINPR2.TAS
  5.  
  6.  WRITTEN BY STEVE HEDLUND 818-368-2897
  7.  
  8.  This is a a script I use for testing Linear Progressions using
  9.  2 seperate progressions and different moving averages on each.
  10.  It has profit testing built into it so you can optimize for each
  11.  equity or index.
  12.  
  13.  Signals are given when one moving average crosses the other.
  14.  
  15.  What I do is shift the averages back one day for timely signals and
  16.  project what the equity or index must do to create a signal, then I  
  17.  play it the same day the signal is given.
  18.  
  19.  THE RESULTS JUST MIGHT ASTOUND YOU. PLEASE GIVE ME ALL THE FEED 
  20.  BACK YOU CAN AS WELL AS THE TIME PERIODS YOU FIND USEFUL.
  21.  
  22.  Below you can change time periods for each of the regressions and
  23.  moving averages, as well as the max_quotes.
  24.  }
  25. {=====================================================================}
  26. {SET UP USER DEFINED VARIABLES}
  27. {=====================================================================}
  28. Ln:=5;   {First Regression Time Periods}
  29. pn:=1;   {periods for first moving aver. of regression}
  30. ln1:=5;  {Second Regression Time Periods}
  31. pn1:=2;  {periods for second moving avg. of regression}
  32. s:=1;    {shift averages back}
  33. pr:=1;   {set to 1 for profit test}
  34. gr:=1;   {set to 1 to graph}
  35. qc:=100; {set the same as max_quotes}
  36. #MAX_QUOTES 100
  37. {=====================================================================}
  38. {PROFIT TESTING SETUP}
  39. {=====================================================================}
  40.   #PROFIT_TEST both 10000 2 - next open
  41.   #profit_comm nocomm oneshare 0
  42.   #profit_output tickersummary
  43.   #output_file 'slope.lst'
  44. {=====================================================================}
  45. {SET UP ARRAYS AND VARIABLES}
  46. {=====================================================================}
  47. cx : array;       {Linreg array}
  48. cx1 : array;      {Forecast array}
  49. ccon: array;      {Stores the Constant of the linreg}
  50. cxx : array;      {Slope array}
  51. m1 : array;       {Moving Averge of forecast}
  52. m3 : array;       {Moving Average of forecast}
  53. m4: array;
  54. cg : array;       {Linreg array}
  55. av : array;
  56. cx11 : array;     {Forecast array}
  57. cx6 :array;
  58. ccon1: array;     {Stores the Constant of the linreg}
  59. cxx1 : array;     {Slope array}
  60. {=====================================================================}
  61. {LINEAR REGRESSIONS - APPROXIMATE LINES
  62. {=====================================================================}
  63. plot begin
  64. {************ First Regression **********************}
  65.   st:=0;
  66.   lt:=LN;
  67.   for i=LN;i<=qc;i=i+1;
  68.   BEGIN
  69.    av:=divby(ADD(l,h),2);
  70.    cX[I] := LINREG(C,ST,LT);
  71.    ccon[i] := p[(lt-(ln-1))];
  72.    cxx[i] := SLOPE(LINREG(C,ST,LT));    {TO GET CONSTANT FROM LINREG}
  73.    cx1[i-s]:= ccon[i]+(cxx[I]*(LN+1));   {compute forecast}
  74.    sT:=ST+1;
  75.    LT:=LT+1;
  76.   end;
  77. {*********** Second Regression ************************}
  78.  st1:=0;
  79.  lt1:=LN1;
  80.  for i=LN1;i<=qc;i=i+1;
  81.  BEGIN
  82.    cg[I] := LINREG(C,ST1,LT1);
  83.    ccon1[i] := p[(lt1-(ln1-1))];
  84.    cx6[i]=corrcoef()/100;
  85.    cxx1[i] := SLOPE(LINREG(C,ST1,LT1));    {TO GET CONSTANT FROM LINREG}
  86.    cx11[i-s]:= ccon1[i]+(cxx1[I]*(LN1+1));   {compute forecast}
  87.    ST1:=ST1+1;
  88.    LT1:=LT1+1;
  89.   end;
  90. {=====================================================================}
  91. {CALCULATIONS FOR CONDITIONS}
  92. {=====================================================================}
  93.  m1:=mov(cx1,pn,'s');
  94.  m3:=mov(cx11,pn1,'s');
  95.  m4:=sub(m1,m3);
  96. {=====================================================================}
  97. {GRAPHS}
  98. {=====================================================================}
  99. le:=(qc-ln1)*(-1);
  100. SS:=S*(-1);
  101. if gr=1 then opengraph(2,LE,SS);
  102. if gr=1 then  sizegraph(2,1);
  103. if gr=1 then  graph(1,m1,m3);
  104. if gr=1 then graph(cx6,'Correlation Index');
  105. if gr=1 then  closegraph();
  106. end;
  107. {=====================================================================}
  108. {CONDITIONS FOR PROFIT TEST}
  109. {=====================================================================}
  110.  bUY WHEN (m1[-1] <= m3[-1]) and (m1[0] >m3[0]){and (cx6[0]<=.1 or cx6[-1]
  111. <=.1 or cx6[-2]<=.1)} ;
  112.  SELL WHEN (m1[-1]>= m3[-1]) and (m1[0] <m3[0]){and (cx6[0]<=.1 or cx6[-1]
  113. <=.1 or cx6[-2]<=.1)};
  114.  stop short when (m1[-1] <= m3[-1]) and (m1[0] >=m3[0]);
  115.  stop long when (m1[-1]>= m3[-1]) and (m1[0] <=m3[0]);
  116.