Trigger only during market hours

Stoynks

Member
Can't seem to make this work. I want my variable to only be triggered right after market opens and before it closes. so basically market open > x < market closes. I have this in the aggregation period of DAY. Without "rth" it works, but pre-market and after-hours still triggered my statement.


Code:
def rth = getTime() >= RegularTradingStart(getYYYYMMDD()) and getTime() <= RegularTradingEnd(getYYYYMMDD());

AddLabel (yes, " High: " + (high), (if

close crosses vwap and rth then color.white

else color.black));
 
Code:
input OpenTime = 0630;
input CloseTime = 1300;
def Begin = secondsfromTime(OpenTime);
def End = secondsTillTime(closetime);


AddLabel (yes, " High: " + (high), (if
Begin >= 0 and close crosses vwap and End >= 0 then color.white
else color.black));

Did a backtest and it is still triggering pre-market. Did I do the code right? unfortunately, I'm a beginner at coding.
 
Changed the time but it's still triggering at premarket. how would I format to account just for the current day? maybe that will help. Sorry about that.

4t4b9YY.png
 
Have you tried turning off extended hours trading and insuring that aggregation starts at market open in the Chart Settings > Equities panel...???
 
Yeah, I have extended hours trading unmarked and aggregation starts at market open checkmarked. Is it because I have it on Aggregation.Day chart? If that's the case, how would I still trigger my indicator from open market to closing with Day chart?
 
Last edited:

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
530 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.
Back
Top