# Cattle Table

This example prints a table of cattle prices from the April contract for each of the last 19 years.  The December 15th price and the March 15th prices are printed along with the change in price between these two dates.  If the desired dates happen to be on the weekend, then the prices are obtained from Monday.

function NearDate(d: integer): real;
var j: integer;
begin
j:=Bar(eIndex,d);
if j=0 then begin inc(d); j:=Bar(eIndex,d); end;
if j=0 then begin inc(d); j:=Bar(eIndex,d); end;
if j=0 then begin inc(d); j:=Bar(eIndex,d); end;
if j>0 then Result:=Bar(eLast,j) else Result:=0;
end;

procedure CattleTable;
var
yr,mo: integer;
s,s1,s2: string;
j,k,iDate1,iDate2: integer;
price1,price2: real;
begin
Output(eClear);
writeln('Contract Dec 15th March 15th Change');
for yr:=80 to 98 do begin
for mo:=2 to 2 do begin
s:='LC'+inttostr(yr)+Copy('GJMQVZ',mo,1);
chart(s);
iDate1:=pred(yr)*10000+1215; {Dec 15th}
iDate2:=yr*10000+0315; {Mar 15th}
price1:=NearDate(iDate1);
price2:=NearDate(iDate2);
s1:=FormatPrice(price1,true,3,eFuture);
s2:=FormatPrice(price2,true,3,eFuture);
writeln(s,' ',s1,' ',s2,Align((price2-price1)/1000,8));
mnuCloseWindow.click;
end;
end;
end;

begin
if Who=2 then CattleTable;
end;