PureBytes Links
Trading Reference Links
|
Here's a program that will create a file with n-month bars (e.g. 3 month
= quarterly, 12 month = yearly bars) from daily data in TradeStation
(version 4 or later.) This will allow you to get quarterly and yearly
charts into TS (or any other program that reads ascii files.) Copy the code
to the power editor as a system and verify, be sure to set the MaxBars Back
as 1. Then load a chart with as much history as you want, and add this
study to it through "analysis techniques."
It will create bars of any number of months, but if the # of months
doesn't divide evenly into 12, the last bar in a year will contain data for
less than your chosen period. Also, the last bar will update to the current
date in the current n-month period.
You can change elements in the following line in the program to suit your
needs:
XFILE = "D:\PLData\"+ GETSYMBOLNAME +".DAT";
"D:\PLData\" refers to the directory where you want your data to go.
Change this in the program to go where you want it to go. GETSYMBOLNAME
+".DAT" automatically names the file after the symbol as loaded from TS,
with a .dat extension. You can change this also if you want.
I am grateful to Gary Funck for extensive help with this. In fact, he
basically wrote this. Thanks Gary. I hope someone else appreciates this
also. Tell Gary.
Please let me know if you find anything wrong with this or any improvements.
David Cicia
-------------------------
{System: BarCompress(monthly):
Creates an n-month bar from daily data.}
Input: nMonths(2);
{nMonths = number of months per bar to be created. Only works properly for
nMonths that divide evenly into 12, i.e. 2,3,4,6. Otherwise the last bar of
the year will be less than an nMonth period.}
var: Copen(0), Chigh(0), Clow(0), XFILE(" ");
XFILE = "D:\PLData\"+ GETSYMBOLNAME +".DAT";
if currentbar = 1 then begin
Filedelete(Xfile);
Copen = Open;
Chigh = high;
Clow = low;
end else begin
if (month(date) <> month(date[1])
and mod(month(date)-1, nMonths) = 0) then begin
{beginning of new month}
Fileappend(Xfile, NumToStr(Date[1],0)
+ " " + NumToStr(Copen,4)
+ " " + NumToStr(Chigh,4)
+ " " + NumToStr(Clow,4)
+ " " + NumToStr(Close[1],4)
+ Newline);
Copen = Open;
Chigh = high;
Clow = low;
end;
Chigh = Maxlist(Chigh, High);
Clow = MinList(Clow, Low);
if (Date = LastCalcDate and Time = LastCalcTime) then begin
Fileappend(Xfile, NumToStr(Date, 0)
+ " " + NumToStr(Copen,4)
+ " " + NumToStr(Chigh,4)
+ " " + NumToStr(Clow,4)
+ " " + NumToStr(Close,4)
+ Newline);
end;
end;
|