Referencing past day data on an intraday column


Category:
0
0

hi Pete, I’ve been struggling with this one for some time now. Many times I’m gathering intraday information and want a cross-reference it against daily data in the past.

 

An example might be I currently have a chart that gives me the highest price by 8:30 today during market open

 

I want to compare that data to the closing price from yesterday so I can make a percent call them. I found a complex method to do it by trying to grab the price at the closing bell but sometimes if a stock didn’t trade at the closing bell it won’t return that data

I was then able to modify it by getting the most recent closing price within a certain time frame before the closing bell but it all seems very sloppy

 

Anytime I try to reference in aggression period of a day passed on an intraday column it gives me an error. Love any insight you may have

Marked as spam
Posted by (Questions: 7, Answers: 9)
Asked on February 12, 2019 9:46 am
138 views
0

Show me the code you have built to try to solve this and I might be able to fix it.

( at February 15, 2019 2:05 pm)
0

Here’s the portion I’m currently using to grab the closing price. The problem is this bandaid solution is this only records stocks who have a tick 1m before the closing bell, or as in my modified solution below, a few hours before closing.

declare lower;
declare zerobase;

input close_to_closing_time = 1300;
input closing_time = 1559;
input open_time = 0930;

def time_until_close = SecondsTillTime(closing_time);
def time_until_close2close = secondstilltime (close_to_closing_time);
def closing_bell = time_until_close == 0;
def after_close_to_closing_time = time_until_close2close =0;

rec closing_price = compoundvalue(1,if closing_bell then close else if before_closing_bell and after_close_to_closing_time then close else closing_price[1],0);

My desire would be to use something like this code, on a 1m column or scan study:

def yesterday_close = close(period = AggregationPeriod.DAY)[1];

( at February 15, 2019 10:29 pm)
0

Are you using extended hours trade data for this? If so, I don’t see an easy solution. If you are using only regular session trade data, we can check for “new day” and grab the close of the previous 1 min bar.

( at February 16, 2019 10:49 am)
0
Private answer

Yes, using extended hours for this. Stayed up till 5 last night scripting and finally landed on something that appears to be working, no matter the time.day of the last day. The idea here was once after hours start, I add “1” to a compound value. Then I just have it gather data prior that value. A bit sloppy, but here’s what I came up with that looks to be working so far!

def JustEnded = if SecondsFromTime(930) > 0 and SecondsFromTime(1600) >= 0 then 1 else 0;
def Today ;
rec closing_price ;
Today = if GetDay() != GetDay()[1] then 1 else 0;
rec GetFirstTickAfterHours = if JustEnded then 1 + GetFirstTickAfterHours[1] else GetFirstTickAfterHours[1];
def tickbeforeclose = if GetFirstTickAfterHours – 1 == GetFirstTickAfterHours[2] then 1 else 0;
def noafterhourticks = if Today and GetFirstTickAfterHours == GetFirstTickAfterHours[2] then 1 else 0;
closing_price = if JustEnded then (if tickbeforeclose then close[1] else closing_price[1]) else if noafterhourticks then close[1] else closing_price[1];

Marked as spam
Posted by (Questions: 7, Answers: 9)
Answered on February 16, 2019 11:39 am