Post by A.D. FundumPost by Will Honeahttp://moneytide.com/hans/index.asp
If I release an EXE without (c), I'll actually release the C
source.
Once answering yet another is-there-a-free-website-which-...-question.
Required: gDiagramm.EXE, the latest version is recommended. And at
least 2 Metastock'ish files, e.g. 2011.PRN and 2012,PRN. Not tested,
but it should already work with this data:
2011.PRN:
<TICKER>,<PER>,<DTYYYYMMDD>,<OPEN>,<HIGH>,<LOW>,<CLOSE>,<VOL>,<OI>
SBT,D,20111231,0.29,0.29,0.29,0.29,1
2012.PRN:
<TICKER>,<PER>,<DTYYYYMMDD>,<OPEN>,<HIGH>,<LOW>,<CLOSE>,<VOL>,<OI>
SBT,D,20120101,0.295,0.295,0.295,0.295,1
SBT,D,20120102,0.28,0.28,0.28,0.28,1
The line with "if (verschil[i]>0)" avoids a gDiagramm bug. ISTR it
won't draw a graph with a flat data line (and it has to draw a line).
As usual, the HTML file it produces can be viewed just fine with
Netscape.
Possible improvements, other than an UI, and so on: the date argument
isn't checked, albeit that's not that important. More lines, more
settings. IRL an improvement is fixing the gDiagramm flat line-bug
(some source code available, but AFAICT it doesn't create the original
EXE out-of-the-box). And even more important a DLL version of
gDiagramm, so the EXE isn't loaded twice per processed symbol.
gDiagramm itself is pretty fast indeed, certainly the newer versions,
but this is by far the slowest market overviewing-releated app I've
got.
BTW, "BIN" refers to the directory where GDIAGRAMM.EXE can be found,
to speed things up. It has nothing to do with Unix at all, I'm not
using Unix nor any Unix file or directory structure.
--
/* Graphs.C - Creates small and large graphs */
#define INCL_DOSFILEMGR
#define INCL_NOCOMMON
#define INCL_WINWINDOWMGR
#pragma import(WinQueryDesktopWorkArea,,"PMMERGE",5469)
#include <io.h>
#include <os2.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
BOOL APIENTRY WinQueryDesktopWorkArea(HWND,PRECTL);
#define BIN ""
#define MAXFONDSEN 256
#define PAD ""
#define REGELLENGTE 128
typedef struct _TICK {char ticker[11];ULONG vanaf;} TICK;
int main(int argc, char *argv[])
{
char buffer[CCHMAXPATH],buffer2[15],csv[]=",",*d,*decimalen;
char kopieregel[32],posities,regel[REGELLENGTE],*s,*t;
char verschil[MAXFONDSEN],vorige[32],wissel[11];
FILE *bron,*doel;
long orgdatum,schermbreedte=1024,schermhoogte=768;
RECTL pD;
short i,j,jaar;
ULONG dag,hulp,vanaf;
USHORT breedte,einde,hoogte,teller=0,teller2;
TICK fonds[MAXFONDSEN];
if (argc!=2)
{
printf("Small and large graphs\n\n");
printf(" Usage: GRAPHS.EXE <YYYYMMDD>\n");
return 1;
}
orgdatum=atol(argv[1]);
if (orgdatum<20070101||orgdatum>20971231)
{
printf("Small and large graphs\n\n");
printf(" Usage: GRAPHS.EXE <YYYYMMDD>\n");
return 0;
}
if (WinQueryDesktopWorkArea(HWND_DESKTOP,&pD))
{
schermbreedte=pD.xRight-pD.xLeft;
schermhoogte=pD.yTop-pD.yBottom;
}
if ((schermbreedte/4)*3>schermhoogte)
schermbreedte=(schermhoogte/3)*4;
else if ((schermbreedte/4)*3<schermhoogte)
schermhoogte=(schermbreedte/4)*3;
vanaf=orgdatum-10000;
einde=orgdatum/10000;
for (i=0;i<MAXFONDSEN;i++)
fonds[i].vanaf=99999999;
for (jaar=einde-1;jaar<=einde;jaar++)
{
sprintf(buffer,"%s%04u.PRN",PAD,jaar);
printf("Busy processing file %s...\n",buffer);
if ((bron=fopen(buffer,"r"))==NULL)
{
printf("Error: cannot open file %s\n",buffer);
return 0;
}
fgets(regel,REGELLENGTE,bron);
while (fgets(regel,REGELLENGTE,bron)!=NULL)
{
if ((t=strtok(regel,csv))!=NULL)
{
strtok(NULL,csv);
if ((d=strtok(NULL,csv))!=NULL)
{
dag=atol(d);
if (dag>vanaf&&dag<=orgdatum)
{
strtok(NULL,csv);
strtok(NULL,csv);
strtok(NULL,csv);
if ((s=strtok(NULL,csv))!=NULL)
{
sprintf(buffer2,"%s.TMP",t);
if ((access(buffer2,0))==-1)
sprintf(fonds[++teller].ticker,"%s",t);
for (i=1;i<=teller;i++)
{
if (!strcmp(fonds[i].ticker,t))
{
fonds[i].vanaf=min(dag,fonds[i].vanaf);
i=teller;
}
}
if ((doel=fopen(buffer2,"a"))==NULL)
{
printf("Error: cannot open file %s\n",buffer2);
return 0;
}
fprintf(doel,"%s\n",s);
fclose(doel);
}
}
}
}
}
fclose(bron);
}
if (!teller)
return 0;
printf("Creating 2x %u graph specifications...\n",teller);
breedte=(schermbreedte-60)/3;
hoogte=((breedte/1.5)+0.5);
sprintf(csv,".");
if (teller>1)
{
i=1;
while (i<teller)
{
if (strcmp(fonds[i].ticker,fonds[i+1].ticker)>0)
{
sprintf(wissel,"%s",fonds[i].ticker);
hulp=fonds[i].vanaf;
sprintf(fonds[i].ticker,"%s",fonds[i+1].ticker);
fonds[i].vanaf=fonds[i+1].vanaf;
sprintf(fonds[i+1].ticker,"%s",wissel);
fonds[i+1].vanaf=hulp;
i=0;
}
i++;
}
}
for (i=1;i<=teller;i++)
{
verschil[i]=0;
sprintf(buffer,"%s.TMP",fonds[i].ticker);
if ((bron=fopen(buffer,"r"))==NULL)
{
printf("Error: cannot open file %s\n",buffer);
return 0;
}
posities=0;
teller2=0;
while (fgets(regel,32,bron)!=NULL)
{
sprintf(kopieregel,"%s",regel);
teller2++;
if (strtok(regel,csv)!=NULL)
{
if ((decimalen=strtok(NULL,csv))!=NULL)
{
if (strlen(decimalen)-1>posities)
posities=strlen(decimalen)-1;
if (teller2>1)
{
if (strcmp(kopieregel,vorige))
verschil[i]=1;
}
sprintf(vorige,"%s",kopieregel);
}
}
}
fclose(bron);
if (verschil[i]>0)
{
sprintf(buffer,"%s.FMT",fonds[i].ticker);
if ((doel=fopen(buffer,"w"))==NULL)
{
printf("Error: cannot create file %s\n",buffer);
return 0;
}
fprintf(doel,"form.Format=%%lf\n");
fprintf(doel,"form.DimX=%u\n",breedte);
fprintf(doel,"form.DimY=%u\n",hoogte);
fprintf(doel,"form.FileOut=%s.PNG\n",fonds[i].ticker);
fprintf(doel,"form.LegendUse=0\n");
fprintf(doel,
"form.Title=Year graph %s since %u\n",
fonds[i].ticker,
fonds[i].vanaf);
fprintf(doel,"form.BackColor=0xd9d9d9\n");
fprintf(doel,"form.FormatX=%%.0d\n");
fprintf(doel,"form.FormatY=%%.%df\n",posities);
fprintf(doel,"field0.use=1\n");
fprintf(doel,"field0.color=0x1c1c1c\n");
fclose(doel);
sprintf(buffer,"%slarge.FMT",fonds[i].ticker);
if ((doel=fopen(buffer,"w"))==NULL)
{
printf("Error: cannot create file %s\n",buffer);
return 0;
}
fprintf(doel,"form.Format=%%lf\n");
fprintf(doel,"form.DimX=%u\n",schermbreedte-24);
fprintf(doel,"form.DimY=%u\n",schermhoogte-184);
fprintf(doel,"form.FileOut=%slarge.PNG\n",fonds[i].ticker);
fprintf(doel,"form.LegendUse=0\n");
fprintf(doel,
"form.Title=Year graph %s since %u\n",
fonds[i].ticker,
fonds[i].vanaf);
fprintf(doel,"form.BackColor=0xd9d9d9\n");
fprintf(doel,"form.FormatX=%%.0d\n");
fprintf(doel,"form.FormatY=%%.%df\n",posities);
fprintf(doel,"field0.use=1\n");
fprintf(doel,"field0.color=0x1c1c1c\n");
fclose(doel);
}
}
printf("Creating 2x %u graphs...\n",teller);
for (i=1;i<=teller;i++)
{
if (verschil[i]>0)
{
printf("Busy with: %-10s\r",fonds[i].ticker);
fflush(stdout);
sprintf(buffer,
"@%sgDiagramm.EXE %s.TMP %s.FMT > NUL",
BIN,
fonds[i].ticker,
fonds[i].ticker);
system(buffer);
sprintf(buffer,
"@%sgDiagramm.EXE %s.TMP %slarge.FMT > NUL",
BIN,
fonds[i].ticker,
fonds[i].ticker);
system(buffer);
sprintf(buffer,"%s.FMT",fonds[i].ticker);
DosForceDelete(buffer);
sprintf(buffer,"%slarge.FMT",fonds[i].ticker);
DosForceDelete(buffer);
sprintf(buffer,"%s.TMP",fonds[i].ticker);
}
else
{
sprintf(buffer,"%s.TMP",fonds[i].ticker);
if (i<teller)
{
for (j=i;j<teller;j++)
{
sprintf(fonds[j].ticker,"%s",fonds[j+1].ticker);
verschil[j]=verschil[j+1];
}
i--;
}
teller--;
}
DosForceDelete(buffer);
}
printf("Sorting\n");
i=1;
while (i<teller)
{
j=i+1;
if (strcmp(fonds[i].ticker,fonds[j].ticker)>0)
{
sprintf(regel,"%s",fonds[j].ticker);
strcpy(fonds[j].ticker,fonds[i].ticker);
strcpy(fonds[i].ticker,regel);
i=0;
}
i++;
}
printf("\nCreating HTML...\n");
sprintf(buffer,"yeargraphs.html");
if (!access(buffer,0))
DosForceDelete(buffer);
if ((doel=fopen(buffer,"w"))==NULL)
{
printf("Error: cannot create file %s\n",buffer);
return 0;
}
fprintf(doel,"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Tr");
fprintf(doel,"ansitional//EN\" \"http://www.w3.org/TR/html4/lo");
fprintf(doel,"ose.dtd\">\n");
fprintf(doel,"<HTML><HEAD><TITLE>Year graphs</TITLE></HEAD>\n");
fprintf(doel,"<BODY bgcolor=\"#0070bf\" text=\"#ffffff\" link=");
fprintf(doel,"\"#ffff00\" vlink=\"#00ffff\" alink=\"#ffc0cb\">\n");
fprintf(doel,"<BR><CENTER><H2>Year graph closing prices</H2>");
fprintf(doel,"</CENTER>\n");
fprintf(doel,"<HR align=\"center\" width=\"80%%\"><BR>\n");
fprintf(doel,"<TABLE border=\"0\" align=\"center\" bgcolor=\"#");
fprintf(doel,"0090bf\">\n");
for (i=1;i<=teller;i+=3)
{
fprintf(doel,"<TR>");
for (j=i;j<=i+2;j++)
{
if (j<=teller)
{
fprintf(doel,"<TD><img src=\"%s.PNG\" ",fonds[j].ticker);
fprintf(doel,"alt=\"%s\" ",fonds[j].ticker);
fprintf(doel,"align=\"center\" border=\"0\" height=");
fprintf(doel,"\"%u\" width=\"%u\"></TD>",hoogte,breedte);
}
}
fprintf(doel,"</TR>\n<TR>");
for (j=i;j<=i+2;j++)
{
if (j<=teller)
{
fprintf(doel,"<TD align=\"center\"><A href=\"");
fprintf(doel,"%slarge.PNG\">",fonds[j].ticker);
fprintf(doel,"%s</A></TD>",fonds[j].ticker);
}
}
fprintf(doel,"</TR>\n");
}
fprintf(doel,"</TABLE>\n");
fprintf(doel,"<HR align=\"center\" width=\"80%%\"><BR clear=\"al");
fprintf(doel,"l\"></BODY></HTML>\n");
fclose(doel);
return 0;
}