pine script – Create candlesticks with lower timeframe data

In TradingView, I’d like to create a candlestick in the 1 hour chart with the opening price being the VWAP of the first 30 minutes and the closing price being the VMAP of the latter 30 min. If I use it in the 4h chart, then it would do the same but with the opening price being the VWAP of the first 2 hours and the closing price of the 2nd 2 hours. Same with any other timeframe -> get the VWAP of the first half for the opening price and the VWAP of the second half for the closing price. Anybody can help with this calculation?