Query editor
select time + offset as time, min_price_usd, max_price_usd, open_price_usd, close_price_usd, case when close_price_usd >= open_price_usd and part in (2, 3, 5, 6) then open_price_usd end as grow_open_usd, case when close_price_usd < open_price_usd and part in (2, 3, 5, 6) then close_price_usd end as drop_close_usd, case when close_price_usd >= open_price_usd and part in (2, 3, 5, 6) then close_price_usd - open_price_usd + 0.000001 end as grow_boby_usd, case when close_price_usd < open_price_usd and part in (2, 3, 5, 6) then open_price_usd - close_price_usd end as drop_boby_usd, case when part = 4 then min_price_usd end as wick_min_usd, case when close_price_usd >= open_price_usd and part = 4 then max_price_usd - min_price_usd end as grow_wick_usd, case when close_price_usd < open_price_usd and part = 4 then max_price_usd - min_price_usd end as drop_wick_usd, min_price_eth, max_price_eth, open_price_usd / open_price_eth as open_price_eth, close_price_usd / close_price_eth as close_price_eth, case when close_price_usd / close_price_eth >= open_price_usd / open_price_eth and part in (2, 3, 5, 6) then open_price_usd / open_price_eth end as grow_open_eth, case when close_price_usd / close_price_eth < open_price_usd / open_price_eth and part in (2, 3, 5, 6) then close_price_usd / close_price_eth end as drop_close_eth, case when close_price_usd / close_price_eth >= open_price_usd / open_price_eth and part in (2, 3, 5, 6) then close_price_usd / close_price_eth - open_price_usd / open_price_eth + 0.000000000000000001 end as grow_boby_eth, case when close_price_usd / close_price_eth < open_price_usd / open_price_eth and part in (2, 3, 5, 6) then open_price_usd / open_price_eth - close_price_usd / close_price_eth end as drop_boby_eth, case when part = 4 then min_price_eth end as wick_min_eth, case when close_price_usd / close_price_eth >= open_price_usd / open_price_eth and part = 4 then max_price_eth - min_price_eth end as grow_wick_eth, case when close_price_usd / close_price_eth < open_price_usd / open_price_eth and part = 4 then max_price_eth - min_price_eth end as drop_wick_ethfrom (select date_trunc('week', pi.minute) as time, min_by(pi.price, pi.minute) as open_price_usd, max_by(pi.price, pi.minute) as close_price_usd, min(pi.price) as min_price_usd, avg(pi.price) as avg_price_usd, max(pi.price) as max_price_usd, min_by(pe.price, pe.minute) as open_price_eth, max_by(pe.price, pe.minute) as close_price_eth, min(pi.price / pe.price) as min_price_eth, avg(pi.price / pe.price) as avg_price_eth, max(pi.price / pe.price) as max_price_ethfrom prices.usd as pileft join prices.usd as pe on pe.blockchain = 'ethereum'and pe.minute = pi.minuteand pe.contract_address = 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2where pi.blockchain = 'ethereum'and pi.contract_address = 0x111111111117dc0aa78b770fa6a738034120c302group by 1) tleft join (values(interval '0' second, 1),(interval '1' second, 2),(interval '2' second, 3),(interval '3' second, 4),(interval '4' second, 5),(interval '5' second, 6),(interval '6' second, 7)) as offsets (offset, part) on trueorder by 1 desc