If a stock has zero volume during a trading day, how is its opening price and closing price determined? Will the opening and closing prices be the price of last trade, regardless of how long ago the last trade occurred?
The rules regarding the types of trade(s) that constitute the data points of Open, High, Low, Close and Volume are well defined.
For securities listed on NYSE, NYSE Arca, NYSE American or Cboe, they are defined by the Consolidated Tape Association in this document: https://www.ctaplan.com/publicdocs/ctaplan/CTS_Pillar_Output_Specification.pdf (see page 64 regarding sale condition)
For Nasdaq-listed securities they are defined by the UTP Plan in this document: https://utpplan.com/DOC/UtpBinaryOutputSpec.pdf (see page 43)
In the absence of any eligible trades for the day, there is no open price to report. However, there can be conditions where an ineligible trade contributes to volume but not to the last sale (e.g. an out-of-hours trade, an odd-lot trade, or a contingent trade) so you may see volume > 0 but no valid open/high/low/close price in the tape feed.
It's up to each data vendor/financial portal as to how this is actually displayed.
In our software we offer users the ability to perform optional "date padding" whereby a previous close is repeated into the OHLC fields if there are no last-sale eligible trades for the the day. This is selectable for market days, all weekdays and all calendar dates.
Best regards, Richard Dale
Disclosure: I am a co-owner of a data vendor, Norgate Data, that specializes in financial market data.