PureBytes Links
Trading Reference Links
|
Max wrote:
>I had better results using time <time[1] to detect a day rollover
That will only work if you have single session data only, or if the
new trading day actually begins at midnight. If you use 24-hour
data, or live in a time zone where the trading session contains
midnight (such as trading the Bund from Hawaii), you need to do
something else.
Here's a function to tell when a new session begins. The function
returns the bar number of the day session (1=first bar, 2=second bar,
etc). If it returns 0 then you have 24 hour data and it's not the day
session. So when it returns 1, that's the start of the new day.
WARNING: I put this code in this message based on a much larger bit
of code, so I can't guarantee it verifies (I don't have TS here with
me right now).
-------------------------------------------------------------------------
{Function: _sess1bar
by Alex Matulich
return the current bar number of the day session}
vars: onesession(false), session1(false), OddTZ(false), bnum(0);
if CurrentBar = 1 then begin
onesession = (Sess2StartTime=Sess2EndTime);
if Sess1FirstBarTime > Sess1EndTime then OddTZ = true;
end;
session1 = {true when the day session is trading}
(OddTZ=false and time >= Sess1FirstBarTime and time <= Sess1EndTime)
or (OddTZ=true and
((time>=Sess1FirstBarTime and time<=2400) or (time>=0 and time<=Sess1EndTime)));
if session1 then begin
if session1<>session1[1] or time=Sess1FirstBarTime then bnum = 0;
bnum = bnum+1;
end;
if session1 = false or (onesession=true and time=Sess1FirstBarTime) then
bnum = 0;
_sess1bar = bnum;
-------------------------------------------------------------------------
--
,|___ Alex Matulich -- alex@xxxxxxxxxxxxxx
// +__> Director of Research and Development
// \
// __) Unicorn Research Corporation -- http://unicorn.us.com
|