Daily gaps when intraday data contains premarket / postmarket trading
Author: jduke
Creation Date: 1/28/2020 2:54 AM
profile picture

jduke

#1
Hi there,

I have been working with daily gaps using Fidelity intraday data, and it was pretty straightforward to code to find the first bar of the day (IntraDayBar==0) Open and subtract the previous bar's close to get the gap.

But now (happily) I have data with premarket/postmarket and I'm trying to figure out the most straightforward way to calculate the daily gap and put it in a dataseries.

I get the sense that using a SetScaleDaily and then doing some sort of calculation at the daily level would work, but it doesn't account for actual trading hours of 930 to 4pm. So then I figured I would need to calculate the time with eg
CODE:
Please log in to see this code.
and
CODE:
Please log in to see this code.
but this seems super inefficient to go through each bar and calculate these gaps then try to stuff them into a data series that is at the Daily level.

So any tips on the most straightforward approach to creating a dataseries of regular market gaps on a 1 minute dataset including pre/post market data?

Thanks!

Jon

profile picture

Eugene

#2
Hi Jon,

Isn't the idea of obtaining and/or trading on premarket/aftermarket data to be less affected by gaps? At any rate, if you keep using the Fidelity data to calculate the daily gap this seems like an easy workaround. For example, you could get the data with GetExternalSymbol.

P.S. Just a general observation, you should avoid hardcoding the open time as "931" as there will be times when a stock does not open at 9:31.
profile picture

Cone

#3
A few things to add:
1. Wealth-Lab Pro Fidelity Provider filters out pre/post market data for stocks.
2. Note that by convention Wealth-Lab intraday bar timestamps are end-of-bar, in contrast to ATPro's start-of-bar.
3. Here's the way to get the first bar of the day and the gap value in the bar loop:

CODE:
Please log in to see this code.


4. Make use of our Community.Components. Look for "Intraday Support Functions"

5. Finally, note that the last intraday trade close will often not match the Daily data's settled close. Consequently, if you want to get the gap w.r.t. the settled close, then you need to access the actual Daily data from the intraday chart. You can do that by using GetExternalSymbol and specifying the name of the Daily DataSet. Example:

CODE:
Please log in to see this code.
profile picture

jduke

#4
Thank you both so much! This is exactly what I needed!

Best,

Jon
profile picture

Eugene

#5
You're welcome!
profile picture

Cone

#6
I should have mentioned that the solution that accesses Daily data will not work for the Fidelity Provider in real time since that Provider does not update the Daily bar before the close of the session. Consequently, if you're planning on using that code in Real Time, you'll need to either get a Daily provider that will update to get "today's" opening price, or, use the intraday solution for the current day. If you need help with that, let me know.
profile picture

jduke

#7
Cone,

I see what you mean now regarding using this in real-time. Indeed, when using the external symbol approach, it could not calculate the gap on the open when running in strategy monitor.

That said, the intraday solution when running on a set including premarket data uses 4am as firstBarToday, so that doesn't solve my goal of getting the 4pm to 930am gap.

So, I think your suggestion of
QUOTE:
get a Daily provider that will update to get "today's" opening price
seems like the right one in this case. Do you know which Daily providers update to get "today's" opening price?

Thanks!

Jon
profile picture

Eugene

#8
QUOTE:
Do you know which Daily providers update to get "today's" opening price?

Currently it's Yahoo! provider with "Always return data with partial bar" option enabled (Data Manager > Yahoo tab).
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).