1

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!

1 Answer 1

0

You can use

session.ismarket 

Returns true if the current bar is a part of the regular trading hours (i.e. market hours), false otherwise See : https://www.tradingview.com/pine-script-reference/v5/#var_session{dot}ismarket

Sign up to request clarification or add additional context in comments.

1 Comment

Sorry, but this is not helpful at all. On daily, weekly and monthly timeframes, session.ismarket will always return true, so this variable is only useful for intraday timeframes (check this article). Plus, I believe it relates to the state of the market at the time of each past bar, not to the present status of the market.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.