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

Re: Day of Week Code



PureBytes Links

Trading Reference Links

> If DayofWeek(Date)=5 and DayofWeek(Date of next bar)=1 then buy next bar
> at open;

I'd use "if DayOfWeek(Date) > DayOfWeek(Date of next bar)" -- 
that way it works even if Friday or Monday or whatever is a 
holiday.

> It appears an error message like this: "Cannot mix next bar prices
> with data streams other than data1" 
> 
> Is there any way around this?

'Fraid not, with this approach anyway.  I don't remember exactly 
why TS has this limitation, but next-bar access is not allowed 
with multiple data streams.

Possible workarounds:

* Use shorter bars instead of EOD bars.  With 5min bars you could 
enter at the end of the first 5min bar of the day.

* For backtesting you could construct an artificial data series 
that is, for example, tomorrow's Date of the main data series.  
E.g. display your data series in data1, then run an indicator 
that writes "Date,DayOfWeek(Date of next bar)" to a file.  Then 
display the artificial series as data2, and your test becomes "if 
DayOfWeek(Date) > Close of data2 then..."  (Close of data2 being 
DayOfWeek of the next bar.)  Obviously you can't do this in 
realtime, but in realtime you'll just be issuing your orders, not 
worrying about TS's limitations.  (Unless you want TS to issue 
the orders for you, in which case it gets messy.)

* Use a global-var facility like PushPop to pass the information 
from another chart.  E.g. push DayOfWeek(Date of next bar) from 
another chart, and access it from your active chart.  Realize, 
though, that any indicator/system that uses "next bar" CAN'T 
EXECUTE on the last (current realtime) bar, because there IS no 
"next bar" at that point.  So if today is Friday, your PushPop 
indicator can't push the next bar's Monday DayOfWeek because 
there's no bar there.  So you still can't use it to issue orders 
in realtime.  As with the one above, this is a solution for 
backtesting but for realtime you'll have to do it yourself.

Gary