Puede agregar números fijos de filas usando row_number()
y aritmética:
select min(date),
(array_agg(bid order by seqnum asc))[1] as open,
(array_agg(bid order by seqnum desc))[1] as close,
min(bid) as min_bid, max(bid) as max_bid
from (select t.*, row_number() over (order by date) as seqnum
from ticks t
) t
group by floor((seqnum - 1) / 500);
Esto usa "hackear" para obtener el open
y close
-- mediante el uso de matrices.