How can I check whether the market is open or closed before reaching the last bar?
This Stack Overflow thread suggests using the barstate.isrealtime built-in variable for that, but this will turn true only at the end of the script run (at the last bar of the chart). I need to know the status of the market before that.
Sure, I could write a function that will check the trading hours with the current hour. But I am looking for a solution that will work for all TradingView stock exchanges (with various schedules, time frames, holidays, etc), not just one or two exchanges.
Thank you!