Hascons,
This is a rough idea. The first query breaks your data into partitions AND
gets the Opening/Closing date (for your next query).
Select Stock, Your Stock ID
BarDate, Just the Date part of BarDate
Partition(MinutesSinceMidnight, You calculate this value with...