Previous Day Close in Pre-Market Label

practicalopinion

New member
Plus
I am trying to get the Close Price of Previous Day during "Pre-Market" Session and add it as a label.

Code:
def PreviousClose = close(period = AggregationPeriod.DAY)[1] ;

The above line of code only works during regular trading session starts at 9:30 AM EST. I need it work in pre-market hours.

Any pointers / help is much appreciated.
 
Last edited by a moderator:
Solution
I am trying to get the Close Price of Previous Day during "Pre-Market" Session and add it as a label.

This finds the previousdpermarketclose by finding the time that day opened and saving the close of the bar before it. Plots were used to display the confirm the values in the following label code.

Screenshot 2024-03-02 070953.png
Code:
plot PreviousClose = close(period = AggregationPeriod.DAY)[1] ;
def premarketclose = if SecondsFromTime(0930) == 0 then close[1] else premarketclose[1];
plot previouspremarketclose = premarketclose[1];

AddLabel(1, PreviousClose + " " + previouspremarketclose);
A
I am trying to get the Close Price of Previous Day during "Pre-Market" Session and add it as a label.

This finds the previousdpermarketclose by finding the time that day opened and saving the close of the bar before it. Plots were used to display the confirm the values in the following label code.

Screenshot 2024-03-02 070953.png
Code:
plot PreviousClose = close(period = AggregationPeriod.DAY)[1] ;
def premarketclose = if SecondsFromTime(0930) == 0 then close[1] else premarketclose[1];
plot previouspremarketclose = premarketclose[1];

AddLabel(1, PreviousClose + " " + previouspremarketclose);
A
 
Last edited by a moderator:
Solution
Interestingly, I had my minute chart setting to "Today", when I changed the minute chart settings to 1 day, it displayed the correct values!!!
1709407152924.png
1709407435369.png


The only pending issue is that when I switch to the daily chart, it shows me the close value from 2 days back, which is 209.14
1709407585506.png
 

Attachments

  • 1709407103765.png
    1709407103765.png
    162.7 KB · Views: 36
  • 1709407143802.png
    1709407143802.png
    42.9 KB · Views: 31
Last edited by a moderator:
I think I will be able to resolve this, there is a function GetAggregationPeriod() which gives you the aggregation of the current chart setting, I will use it to adjust the close price accordingly. However, if you have a clever way of implementing it, pleas let me know.

Thanks for the solution @SleepyZ SleepyZ, appreciate it and have a good rest of the day!
 
Last edited by a moderator:

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
358 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