Last bar open and close price of day

adTS

New member
Hi,
I am having trouble getting for the last bar open and close price at the closing session (4pm est) , specially on Mondays
I am using
def day = GetDay();
def lastDay = GetLastDay();
def isToday = If(day == lastDay, 1, 0);
but not always work for SPX, ES, SPY with and without extended hours on

Today at 3pm I would like to get yesterday's values
Today at 5pm I would like to get today's values
Tomorrow at 8am I would like to get yesterday's values

Any help is appreciated
 
Solution
@adTS
You can reduce your above code to:
Ruby:
def isToday = GetDay() == GetLastDay();
and get the same results, but I don't think you even need it at all.
A script to record open and close of a certain bar from every day would overwrite itself with the data of the current day at the time defined.
This code records the open and close of the bar at 4:00 p.m.
Ruby:
input Reset_Time = 1600; # Time of bar to record open and close.

def Start =
(SecondsTillTime(Reset_Time)[1] > 0 and SecondsTillTime(Reset_Time) <= 0);
    
def SessionOpen;
def SessionClose;
if Start {
SessionOpen = open;
SessionClose = close;
} else {
SessionOpen = SessionOpen[1];
SessionClose = SessionClose[1];
}
@adTS
You can reduce your above code to:
Ruby:
def isToday = GetDay() == GetLastDay();
and get the same results, but I don't think you even need it at all.
A script to record open and close of a certain bar from every day would overwrite itself with the data of the current day at the time defined.
This code records the open and close of the bar at 4:00 p.m.
Ruby:
input Reset_Time = 1600; # Time of bar to record open and close.

def Start =
(SecondsTillTime(Reset_Time)[1] > 0 and SecondsTillTime(Reset_Time) <= 0);
    
def SessionOpen;
def SessionClose;
if Start {
SessionOpen = open;
SessionClose = close;
} else {
SessionOpen = SessionOpen[1];
SessionClose = SessionClose[1];
}
 
Last edited:
Solution

@Svanoy

Thank you reply, very appreciated.
I tried you code, but the open and close price is for the first bar of the day (9:30am), not the last bar of the day.
I tried SPY and SPX at 11:00pm EST
 
Last edited:
@adTS
I had forgot to change the start time def, it is fixed now.
The code I posted has an input field for time of day. Change that to the time of the bar you want.
 
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
519 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