start at 13:00 instead of 22:00? (I'm on the West Coast.)

compupix

New member
How would I get the previous day's close line to start at 13:00 instead of 22:00? (I'm on the West Coast.) Here's the code I'm currently using:

# PreviousDayClose

declare upper;

# The following time condition doesn't help
# Define time condition for 1pm (13:00)
def currentTime = GetTime();
def is1PMOrLater = currentTime >= 1300; # 1300 represents 1:00 PM in military time

def lastDayToday = if GetLastDay() == GetDay() and GetLastYear() == GetYear() then yes else no;

# Get previous day's close only once
def previousDayCloseValue = if lastDayToday then close(period = "DAY")[1] else Double.NaN;

# Plot only when time is 1pm or later
plot PrevDayClose = if is1PMOrLater and lastDayToday then
previousDayCloseValue
else
Double.NaN;

def CurrentClose = if lastDayToday then close else Double.NaN;

#===============================[ Look & Feel ]================================
PrevDayClose.SetDefaultColor(Color.ORANGE);
PrevDayClose.SetLineWeight(2);
PrevDayClose.SetStyle(Curve.MEDIUM_DASH);
 
Solution
How would I get the previous day's close line to start at 13:00 instead of 22:00? (I'm on the West Coast.) Here's the code I'm currently using:

# PreviousDayClose

declare upper;

# The following time condition doesn't help
# Define time condition for 1pm (13:00)
def currentTime = GetTime();
def is1PMOrLater = currentTime >= 1300; # 1300 represents 1:00 PM in military time

def lastDayToday = if GetLastDay() == GetDay() and GetLastYear() == GetYear() then yes else no;

# Get previous day's close only once
def previousDayCloseValue = if lastDayToday then close(period = "DAY")[1] else Double.NaN;

# Plot only when time is 1pm or later
plot PrevDayClose = if is1PMOrLater and lastDayToday then...
How would I get the previous day's close line to start at 13:00 instead of 22:00? (I'm on the West Coast.) Here's the code I'm currently using:

# PreviousDayClose

declare upper;

# The following time condition doesn't help
# Define time condition for 1pm (13:00)
def currentTime = GetTime();
def is1PMOrLater = currentTime >= 1300; # 1300 represents 1:00 PM in military time

def lastDayToday = if GetLastDay() == GetDay() and GetLastYear() == GetYear() then yes else no;

# Get previous day's close only once
def previousDayCloseValue = if lastDayToday then close(period = "DAY")[1] else Double.NaN;

# Plot only when time is 1pm or later
plot PrevDayClose = if is1PMOrLater and lastDayToday then
previousDayCloseValue
else
Double.NaN;

def CurrentClose = if lastDayToday then close else Double.NaN;

#===============================[ Look & Feel ]================================
PrevDayClose.SetDefaultColor(Color.ORANGE);
PrevDayClose.SetLineWeight(2);
PrevDayClose.SetStyle(Curve.MEDIUM_DASH);

not sure what significance 22:00 has, but ,
here is a study to plot a line from the desired time to end of day.
i added a 2nd line that goes from previous day end to desired time.

default is 1300 , 13:00 , or 1pm EST
if you want pacific time, then subtract 3 , 1000

Code:
#prev_day_close_attime

#https://usethinkscript.com/threads/start-at-13-00-instead-of-22-00-im-on-the-west-coast.20676/
#start at 13:00 instead of 22:00? (I'm on the West Coast.)
#compupix  3/6

#How would I get the previous day's close line to start at 13:00 instead of 22:00? (I'm on the West Coast.) Here's the code I'm currently using:

def na = double.nan;
def d = GetDay();
def newday = d != d[1];

#===================================
#https://usethinkscript.com/threads/finding-the-first-and-last-bar-of-the-day-in-thinkorswim.526/
def Offset = 0;
def nan = Double.NaN;
def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1];
def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD());
def afterEnd = GetTime() > RegularTradingEnd(GetYYYYMMDD());
def firstBarOfDay = if
    (beforeStart[1 + Offset] == 1 and beforeStart[Offset] == 0) or
    (isRollover[Offset] and beforeStart[Offset] == 0)
    then 1
    else 0;
def lastBarOfDay = if
    (afterEnd[-1 - Offset] == 1 and afterEnd[Offset] == 0) or
    (isRollover[-1 - Offset] and firstBarOfDay[-1 - Offset])
    then 1
    else 0;
#==================================

def daycls = if lastBarOfDay then close else daycls[1];

input line_start_EST = 1300;
def startbar = SecondsFromTime(line_start_EST)[1] < 0 and SecondsFromTime(line_start_est) >= 0;

# cyan line from time to day end
def lin = if newday then 0
 else if startbar then daycls
 else lin[1];
plot z = if lin > 0 then lin else na;
z.setdefaultcolor(color.cyan);

# gray line from last bar of prev day to time
def lin2 = if newday then daycls
 else if startbar then 0
 else lin2[1];
plot z2 = if lin2 > 0 then lin2 else na;
z2.setdefaultcolor(color.gray);
#
 

Attachments

  • img1.JPG
    img1.JPG
    64.4 KB · Views: 37
Solution

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