PureBytes Links
Trading Reference Links
|
At 12:21 AM 1/16/2005, Phil Bailey wrote:
>Would anyone know the code to bypass the first intraday bar of a new date?
>TS functions utilized in indicator calculate inconsistantly on first bar, so
>would just like to specify when 1st bar is active to bypass.
The simple answer is:
if Date = Date[1] then begin
...your code here...
end;
This will execute only when the date on the bar is the same as on the previous bar, which is true for every bar except the first bar of the day.
But the real answer is probably more complicated.
If the indicator uses "series functions" (instead of "simple functions") they will be executed on every bar, no matter what.
Or if the indicator uses several bars of data, and if there is a big overnight gap, then you need to wait until the effects of the gap have died out.
You can usually rewrite most functions to reinitialize on the start of a new day.
For example, many functions include special code for the first bar:
if CurrentBar = 1 then begin
... initialization code...
end else begin
... code for other bars...
end;
You can make the initialization code also run on the first bar of the day as follows:
if CurrentBar = 1 or Date <> Date[1] then begin
... initialization code...
end else begin
... code for other bars...
end;
And if the initialization code looks back X bars then you would have to delay the initialization X bars to make sure it is not using bars from the previous day.
Of course, if you are running with near 24 hour data, this will make the initialization happen after midnight, which is probably not what you want. That case is a bit more complicated.
Bob Fulks
|