In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.
If I check with - for example - Tesla on the 12th of February 2021 using the daily chart, your script (adapted for plotting morningClose and afternoonOpen) returns 815.99 (morningClose) and 810.40 (afternoonOpen), whereas the 10:00 close and 14:30 close of Tesla on a 30 minute chart for the same day are 789.32 (10:00 close) and 803.50 (14:30 close), same for other stocks.
Is this an error or have I understood the meaning of the script incorrectly?