PureBytes Links
Trading Reference Links
|
> Speaking of multiple time frames. I would like to write a
> TradeStation strategy where one data series is 1-min bars and the
> other is daily bars. Is this possible? Specifically I am trying to
> build a day-trading strategy for stock indices that halts trading
> when the average daily ranges fall below a certain threshold.
You don't really have to use two data series for this. You can get
yesterday's range using HighD(1) - LowD(1). It would be a pain to
calculate the simple average of that -- you'd have to store it in an
array and compute it from that -- but you can roll your own xaverage
pretty easily. Something like this:
input: DaysLen(20);
vars: RngFactor(0), RngXavg(0), HiD(0), LoD(0);
vars: InitXavg(.7); { Some reasonable value to jump-start the xavg }
{ Initialize xaverage for daily H-L range }
if DaysLen + 1 <> 0 and CurrentBar <= 1 then begin
RngFactor = 2 / (DaysLen + 1);
RngXavg = InitXavg;
end;
HiD = HighD(1);
LoD = LowD(1);
if Date<>Date[1] then
RngXavg = RngFactor * (HiD-LoD) + (1 - RngFactor) * RngXavg[1];
NOTE: On TS4 at least, you MUST call HighD/LowD OUTSIDE of any
conditional statements -- that's why I assigned them into HiD/LoD.
If you don't call HighD/LowD on EVERY BAR, it won't work right. It's
a bug in TS4 and I'm not sure if they fixed it in TS2k/TSPro.
Gary
|