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;

korygill

Active member
VIP
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
D

Deleted2090

Guest
@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

Top