[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Create n-day/n-month bars in TS



PureBytes Links

Trading Reference Links

  I recently got alot of help, behind the scenes of the current turmoil,
from Gary Funck from this list in creating the following code (so much help
that I must say that he did most of it.) I want to thank him again and
share the results with the list, for anyone who may be interested. This
list really is a very valuable resource.
  The first program (I set it as a "system" in the Power Editor) exports an
ascii file of n-day bars, from TS daily bars. In other words, you can have
2-day bars, 3-day bars, 10-day bars, or whatever. Just apply the system to
any daily chart you have displayed and it will create this file and
automatically name the file after the symbol.
  The second program is similar to this one. It will export an ascii file
of n-month bars, so long as the number of months divides evenly into 12.
This is especially useful if you want a chart of quarterly bars, but you
can also get 2-month, 4-month, 6-month or yearly bars. (This will not work
the same way if you display a monthly chart in TS and use the first
program. You won't get quarterly bars, for instance, you'll get 3-month
bars that don't start at the right place.)
  Both programs have a line that goes:
XFILE = "C:\DATA\"+ GETSYMBOLNAME +".DAT";
This sends the ascii file to your C drive in a directory called "data" and
with file extension ".dat". You can go into the program, if you want to,
and change these to whatever path and extension you want. (The
"getsymbolname" is a command to automatically name the file after the
symbol's name.)

David Cicia
  --------------
-------------------

System: Bar Comp(n-day):
---------------------
inputs: Length(3); {number of days to compress into one bar}
vars: Copen(0), Cclose(0), Chigh(0), Clow(0),
XFILE(" ");

XFILE = "C:\DATA\"+ GETSYMBOLNAME +".DAT";

if mod(currentbar, Length) = 0 then begin
   Copen = Open[Length - 1];
   Chigh = highest(high, length);
   Clow  = lowest(Low, length);
   Cclose = Close;
  
FILEAPPEND(XFILE,NUMTOSTR(Date,0) + " " + NUMTOSTR(COPEN,4) + "  " 
+  NUMTOSTR(CHIGH,4) + "  "  + NUMTOSTR(CLOW,4) + "  " + NUMTOSTR(CCLOSE,4)
+ NEWLINE);
end;	
If currentbar = 1 then FILEDELETE(XFILE);
---------------------
---------------------

System: Bar Comp(monthly):
-----------------
Input: nMonths(3); {nMonths = # of months, 3 = quarterly, 12 = yearly.
Only works for nMonths that divide evenly into 12, i.e. 2,3,4,6 and 12}

vars: Copen(0),  Chigh(0), Clow(0),
XFILE(" ");

XFILE = "C:\DATA\"+ GETSYMBOLNAME +".DAT";

if currentbar = 1 
   or (month(date) <> month(date[1])
       and mod(month(date)-1, nMonths) = 0) then begin
    {beginning of new month}
    if currentbar > 1 then begin
FILEAPPEND(XFILE,NUMTOSTR(Date[1],0) + " " + NUMTOSTR(COPEN,4) + "  " 
+  NUMTOSTR(CHIGH,4) + "  "  + NUMTOSTR(CLOW,4) + "  " + NUMTOSTR(CLOSE[1],4)
+ NEWLINE);
end;	
    Copen = Open;
    Chigh = high;
    Clow = low;
end;
If currentbar = 1 then FILEDELETE(XFILE);

Chigh = Maxlist(Chigh, high);
Clow = MinList(Clow, low);
------------------