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

Re: How to calculate from 1st bar of the day?



PureBytes Links

Trading Reference Links

Robert Roeske suggested:
>Plot1(OpenD(0),"Open of day");

This won't work if you have 24-hour data.  It works if your data is
day session only, and then only if you're in a western-hemisphere
time zone.  The OpenD function assumes the opening price is the
first bar after midnight, in whatever time zone you're in.

Doing it *correctly* is more complicated than TradeStation's OpenD
function.  Here's what I wrote a week or so ago, and now use:

----------------------------------------------------------------------
{Function: _OpenD - open of day
 by Alex Matulich, 12/2003

 This calculates the open of the day, fixing problems with
 TradeStation's builtin OpenD function, where (a) it assumes your
 timezone is such that the day session doesn't contain midnight, and
 (b) it assumes that the way you set GlobalServer's session times
 are the actual session times.  Here you must specify the start and
 end of the session.

 If data compression is daily or greater, then the DaysAgo parameter
 is the same as bars ago.}

inputs:
    DayOpenTime(NumericSimple),     {start of day session}
    DayCloseTime(NumericSimple),    {end of day session}
    DaysAgo(NumericSimple);

vars: FirstBarTime(0), OddTZ(false), j(0), session1(false);
array: dayopen[50](-1);

if datacompression >= 2 then
    _OpenD = Open[DaysAgo]
else begin
    if CurrentBar = 1 then begin
        FirstBarTime = CalcTime(DayOpenTime, BarInterval);
        if DayOpenTime > DayCloseTime then
            OddTZ = true; {odd time zone where session1 contains midnight}
    end;

    session1 =    {true when the day session is trading}
        (OddTZ=false and time >= FirstBarTime and time <= DayCloseTime)
        or (OddTZ=true
            and ((time>=FirstBarTime and time<=2400)
                 or (time>=0 and time<=DayCloseTime)));

    if session1 and (session1<>session1[1] or time=FirstBarTime) then begin
        for j = 50 downto 1 begin
            dayopen[j] = dayopen[j-1];
        end;
        dayopen[0] = Open;
    end;
end;
_OpenD = dayopen[DaysAgo];

----------------------------------------------------------------------

The above can be adapted to make corrected versions of the HighD,
LowD, and CloseD functions also.

-Alex