How to Use secondsFromTime() and secondsTillTime() Functions

CHOZEN

New member
2019 Donor
I want to utilize SecondsFromTime and SecondsTillTime in thinkscript to write a code to place in my scanner that will only scan premarket from 4am - 9:30 am.

Found this example:

Code:
# The following statement will be true any time AFTER 9:30 am
def Aftr930 = secondsFromTime(930) > 0;
 
Solution
Search code here that uses SecondsFromTime and SecondsTillTime. You may need to adjust for your timezone.

I use a variable in all my scripts like

Code:
input timeOffsetFromEST = -300; #hint timeOffsetFromEST: 24-hour time offset from EST (-300 for PST)

and then

Code:
startTime = 0630 - timeOffsetFromEST;
endOfTradingTime = 1315 - timeOffsetFromEST;

and then maybe something like

Code:
def isActive = if SecondsTillTime(endTime) > 0 and SecondsFromTime(startTime) >= 0
                         then 1
                         else 0;

def atEndTime = if secondsTillTime(endTime) == 0
                then 1
                else 0;

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

Search code here that uses SecondsFromTime and SecondsTillTime. You may need to adjust for your timezone.

I use a variable in all my scripts like

Code:
input timeOffsetFromEST = -300; #hint timeOffsetFromEST: 24-hour time offset from EST (-300 for PST)

and then

Code:
startTime = 0630 - timeOffsetFromEST;
endOfTradingTime = 1315 - timeOffsetFromEST;

and then maybe something like

Code:
def isActive = if SecondsTillTime(endTime) > 0 and SecondsFromTime(startTime) >= 0
                         then 1
                         else 0;

def atEndTime = if secondsTillTime(endTime) == 0
                then 1
                else 0;
 
Solution
@korygill

Let me explain a bit better

The following code finds the % change in the value of a stock from open of the same day with aggregation period set to DAY in my scanner. I have some other filters in the scan like average_vol and sizzle index.

Code:
def x = round(100*((close/open)-1),2);
plot y = if x >= 4 then 1 else if x <= -4 then 1 else 0;

What I was trying to do is, based on time after market opens, the % which is >=4 or <= -4 should change.

From
9:30 to 10:30 it should be 2.5%
10:30 to 13:30 it should be 3.5%
13:30 to 16:00 it should be 4.5%

yTDCNvB.png
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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