REM *------------ SUBROUTINE STKPLOT --------------*
REM *             ------------------		   *
REM * UPDATED: February 5, 1983			   *
REM *	   BY: Edward A. Valenzuela		   *
REM * VERSION: 1.31				   *
REM *----------------------------------------------*

rem ..... VARIABLE LIST ......
rem ... min, max
rem ... y(nstk%) ... prices
rem ... nr%      ... number of returns (np%-1)
rem ... np%      ... number of prices in price file
rem ... points%  ... number of prices used in plot
 
298 rem ... find max and min ...
 np% = nr% + 1
 new%=1
 if np% <= 52 then points%=np% else points%=52
 if np% <= 52 then goto 303

   new% = np%-52
303 l%=0
  for k%=new% to np%
    l%=l%+1
    yr(l%) = y(k%)   
  next k%

    min=yr(1)
    max=yr(1)
 for k%=2 to points%
  if yr(k%) > max then max=yr(k%)
  if yr(k%) < min then min=yr(k%)
 next k%

range = max - min
if auto.scale$="A" then goto 314

if max > 10.5 then goto 309
 max = 10.5
 top0$ = "10"
 top1$ = " 7"
 mid0$ = " 5"
 mid1$ = " 2"
 GOTO 321

309 if max > 21 then goto 311
 max = 21
 top0$ = "20"
 top1$ = "15"
 mid0$ = "10"
 mid1$ = " 5"
 GOTO 321

311 if max > 42 then goto 312
 max = 42
 top0$ = "40"
 top1$ = "30"
 mid0$ = "20"
 mid1$ = "10"
 GOTO 321

312 if max > 84 then goto 313
 max = 84
 top0$ = "80"
 top1$ = "60"
 mid0$ = "40"
 mid1$ = "20"
 GOTO 321

313 if max > 168 then goto 314
 max = 168
 top0$ = "160"
 top1$ = "120"
 mid0$ = "80"
 mid1$ = "40"
 GOTO 321
 
rem ... automatic scaling of the axes ...
314  scale.factor = (max - min )/21.0
     sf = 1.0 / scale.factor
     offset = min
     
     top0$ = left$( str$( max ),4 ) 
     top1$ = left$( str$( min + range*0.75 ),4 ) 
     mid0$ = left$( str$( min + range*0.5  ),4 )
     mid1$ = left$( str$( min + range*0.25 ),4 )
     zero$ = left$( str$( min ),4 )
     goto 322

321 rem ... transform into 0-21
 scale.factor = (max)/21.0
 sf = 1.0 / scale.factor
 offset = 0
 zero$ = " 0"

322 for k%=1 to points%
ynew = (yr(k%)-offset)*sf
ynew%(k%) = int%( YNEW )
next k%

rem ... do bar chart ...

rem ... clear screen, position cursor at upper left ...

console : rem ... print y-axis scale ...
 dash$ = "--------------------------------------------------"
 print clear$; tab(10); namstk$ 
  print fn.line$(3) ; fn.right$(6); dash$
  print fn.line$(8) ; fn.right$(6); dash$
  print fn.line$(13); fn.right$(6); dash$
  print fn.line$(18); fn.right$(6); dash$
   print fn.line$(3) ; top0$ 
   print fn.line$(8) ; top1$
   print fn.line$(13); mid0$
   print fn.line$(18); mid1$
   print fn.line$(23); zero$; home$

scr=61444 
rem ... form y-axis line ...
  for k%=1 to 22
    j%=22-k%
    if ( fn.mod%(j%,5) eq 5 ) then ch%=12 else ch%=11
    scr=scr+128
    poke scr,ch%
  next k%

rem ... form x-axis line
  for k%=1 to 52
    if ( fn.mod%(k%,5) eq 5 ) then ch%=12 else ch%=27
    scr=scr+1
    poke scr,ch% 
  next k%

print fn.line$(23); tab(10); "5"; "   10"; \
     "   15"; "   20"; "   25"; "   30"; "   35"; \
     "   40"; "   45"; "   50"; home$

rem ... position cursor at bottom left ...
scr=64133 
ch%=127
for l%=1 to points%
  k% = ynew%(l%)
    for j%=1 to k%
      if k% = 0 then goto 329
      poke scr,ch%
      329 scr=scr-128
      if scr < 61440 then goto 299
    next j%
  scr=64133+l% 
    if scr > 65535 then goto 299
next l%

RETURN

299 print "error in graphics";scr;ch%
RETURN
