hhmm from RegularTradingStart()?

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

This may work...
declare upper;

def time = round(RegularTradingStart(getYYYYMMDD()) / 1000, 0);

input tz = -8;

def hh = floor((time / 3600) % 24) + tz;
def mm = floor((time  / 60) % 60);

addLabel(yes, "Regular Trading Hours Start: " + hh +":" + mm + " ", color.gray);
Things get ugly when you try to take into consideration converting from GMT if you have to adjust for things being > 23 or < 0. It can be done, but it gets ugly.

If this works for you, cool. If not, let me know what it is or isn't doing


PS Don't forget to adjust the timezone for wherever you want the local time. I'm on the west coast, so I'm at GMT-8 and that's the value in the input. Change to suit your location.
  • Hot
Reactions: bmn
Thanks @mashume This is a pretty neat code.

Just have a few follow-up questions.

for \CL, it shows single digit after the colon (e.g. 6:0, instead of 6:00). Is it possible to show 2 digits (append with 0 if single digit)?
This maybe a stretch but would you be able to show how to grab start of pre-market hours dynamically using this logic (I've seen "isRollover" logic used in some studies, though I don't quite understand how that really works other than it marks the time when the day changes).
Can tz be dynamically grabbed from any sys functions (TS docs don't show anything so most probably not)?
I couldn't find a way to get tz info.

the single digit zero is not something I could figure a way around. ToS is dynamically typed so you can have strings, but I can't change variable types so that it would be a number sometimes and a string other times.

not sure about isRollOver things...

  • Like
Reactions: bmn
Thread starter Similar threads Forum Replies Date
K RegularTradingStart(getYYYYMMDD()) Questions 4

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
419 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.