B
Bill Cunningham
I have a program written with the intention to create a true range
between stocks. I had a program like this before and lost it so I am having
to re-write it. CL means current low, CH current high, PC previous close. My
system tells me abs is in stdlib.h and not just math.h. I don't know if
that's true or not. Anyway abs takes ints and my variables are all doubles.
I will post the code and anyone interested can comment. I hope it explains
itself with my brief explaination. The program takes CH CL and PC in that
order. I inputted 3.86 3.08 3.86 and there was no response. The answer is
..70.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
double ch, cl, pc, chr, clr, pcr;
if (argc !=4) {
fprintf(stderr, "TR usage error ch cl pc\n");
exit(EXIT_FAILURE);
}
ch = strtod(argv[1], NULL);
cl = strtod(argv[2], NULL);
pc = strtod(argv[3], NULL);
chr = ch - cl;
clr = cl - pc;
pcr = ch - pc;
if (chr > clr && pcr)
printf("%.2f\n", chr);
if (clr > chr && pcr)
printf("%.2f\n", clr);
if (pcr > chr && clr)
printf("%.2f\n", pcr);
return 0;
}
between stocks. I had a program like this before and lost it so I am having
to re-write it. CL means current low, CH current high, PC previous close. My
system tells me abs is in stdlib.h and not just math.h. I don't know if
that's true or not. Anyway abs takes ints and my variables are all doubles.
I will post the code and anyone interested can comment. I hope it explains
itself with my brief explaination. The program takes CH CL and PC in that
order. I inputted 3.86 3.08 3.86 and there was no response. The answer is
..70.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
double ch, cl, pc, chr, clr, pcr;
if (argc !=4) {
fprintf(stderr, "TR usage error ch cl pc\n");
exit(EXIT_FAILURE);
}
ch = strtod(argv[1], NULL);
cl = strtod(argv[2], NULL);
pc = strtod(argv[3], NULL);
chr = ch - cl;
clr = cl - pc;
pcr = ch - pc;
if (chr > clr && pcr)
printf("%.2f\n", chr);
if (clr > chr && pcr)
printf("%.2f\n", clr);
if (pcr > chr && clr)
printf("%.2f\n", pcr);
return 0;
}