Defining Start & End Times In ThinkOrSwim

SleepyZ

Moderator - Expert
VIP
Lifetime
The following defines start and end to use with your code.

Ruby:
#input Start = 0930;#define the start of tradingsession, suggest no change
#input end = 1600;#define the end of tradingsession, suggest no change


input space = 6.25;
input startprice = 300;
def start = regularTradingStart(getyyyYMMDD());
def end   = regularTradingEnd(getyyYYMMDD());
def condition1 = gettime() > Start;
def condition2 = Gettime() < end;
def hh = if Gettime() crosses above Start then startprice
 else if condition1 and condition2 then hh[1] else if Gettime() > end then Double.NaN
else hh[1];

# the logic is plotting price lines only between 0930 and 1600
plot line0 = if Gettime() < Start then Double.NaN else hh;
line0.SetPaintingStrategy(12);

plot line1 = line0 + space;
plot line2 = line1 + space;
plot line3 = line2 + space;

If you wanted to use your inputs for starrt and end as is, then you would use the secondsfromtime() and/or secondstilltime() functions in conjunction with them.

Ruby:
input Start = 0930;#define the start of tradingsession, suggest no change
input end = 1600;#define the end of tradingsession, suggest no change
input space = 6.25;
input startprice = 190;

def condition1 = secondsFromTime(Start) > 0;
def condition2 = secondsFromTime(end)<0;
def hh = if secondsFromTime(Start)==0 then startprice else if condition1 and condition2 then hh[1] else if secondsfromTime(end)>0 then Double.NaN
else hh[1];
# the logic is plotting price lines only between 0930 and 1600
plot line0 = if secondsfromTime(start)<0 then Double.NaN else hh;
line0.SetPaintingStrategy(12);

plot line1 = line0 + space;
plot line2 = line1 + space;
plot line3 = line2 + space;
 
Last edited by a moderator:

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

Thread starter Similar threads Forum Replies Date
T Defining Candle Patterns Tutorials 0

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
553 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