Time limit code

CHOZEN

New member
2019 Donor
Looking for some help. Anyone know how to write a code to place in my scanner that will only scan premarket from 4am - 9:30am
 

BenTen

Administrative
Staff
VIP
By only scanning during pre-market. You can also use the “within X bars” as a lookback period.
 

markos

Well-known member
VIP
@chosen Type the word Universe in the search box above. I know that there are more than one of those scanners in there, but you will have to hunt.
 

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
input timeOffsetFromEST = -300; #hint timeOffsetFromEST: 24-hour time offset from EST (-300 for PST)

and then
startTime = 0630 - timeOffsetFromEST;
endOfTradingTime = 1315 - timeOffsetFromEST;

and then maybe something like
def isActive = if SecondsTillTime(endTime) > 0 and SecondsFromTime(startTime) >= 0
then 1
else 0;

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

JML

New member
This study plots the opening 9:30 EST price but keeps plotting till the next day at 9:30. I would like to stop plotting at 4:15EST. Can anyone help with this? thanks


input showOnlyToday = YES;
input Market_Open_Time = 0931;
input Market_Close_Time = 1615;
input Market_Close_Time2 = 1600;



def OpeningBell = if SecondsTillTime(Market_Open_Time)[1] > 0 and SecondsTillTime(Market_Open_Time) <= 0 or (SecondsTillTime(Market_Open_Time)[1] < SecondsTillTime(Market_Open_Time) and SecondsTillTime(Market_Open_Time)[1] > 0) then 1 else 0;




def day = GetDay();
def lastDay = GetLastDay();
def isToday = If(day == lastDay, 1, 0);
def shouldPlot = If(showOnlyToday and isToday, 1, If(!showOnlyToday, 1, 0));

def pastOpen = If((SecondsTillTime(Market_Open_Time) > 0), 0, 1);
def pastClose = If((SecondsTillTime(Market_Close_Time) > 0), 0, 1);
def pastClose2 = If((SecondsTillTime(Market_Close_Time2) > 0), 0, 1);
def marketOpen = If(pastOpen and !pastClose, 1, 0);
def firstBar = If (day[1] != day, 1, 0);

def closingBell = if SecondsTillTime(Market_Close_Time)[1] > 0 and SecondsTillTime(Market_Close_Time) <= 0 or (SecondsTillTime(Market_Close_Time)[1] < SecondsTillTime(Market_Close_Time) and SecondsTillTime(Market_Close_Time)[1] > 0) then 1 else 0;

def closingBell2 = if SecondsTillTime(Market_Close_Time2)[1] > 0 and SecondsTillTime(Market_Close_Time2) <= 0 or (SecondsTillTime(Market_Close_Time2)[1] < SecondsTillTime(Market_Close_Time2) and SecondsTillTime(Market_Close_Time2)[1] > 0) then 1 else 0;

rec regHoursHigh = If(high > regHoursHigh[1] and marketOpen, high, If(marketOpen and !firstBar, regHoursHigh[1], high));
rec regHoursLow = If(low < regHoursLow[1] and marketOpen, low, If(marketOpen and regHoursLow[1] > 0 and !firstBar, regHoursLow[1], low));

rec runningClose = CompoundValue(1, if closingBell then close[1] else runningClose[1], close);
rec prevClose = CompoundValue(1, if closingBell then runningClose else prevClose[1], close);

#rec runningClose2 = compoundValue(1, if closingBell2 then close[1] else runningClose2[1], close);
#rec prevClose2 = compoundValue(1, if closingBell2 then #runningClose2 else prevClose2[1], close);

rec prevHigh = CompoundValue(1, if closingBell then regHoursHigh[1] else prevHigh[1], high);
rec prevLow = CompoundValue(1, if closingBell then regHoursLow[1] else prevLow[1], low);

plot pc = if shouldPlot then prevClose else Double.NaN;
pc.SetStyle(Curve.SHORT_DASH);
pc.SetDefaultColor(Color.WHITE);

#plot pc2 = if shouldPlot then prevClose2 else double.nan;
#pc2.SetStyle(curve.SHORT_DASH);
#pc2.setDefaultColor(color.pink);

plot pl = if shouldPlot then prevLow else Double.NaN;
pl.SetDefaultColor(Color.DARK_RED);
pl.SetStyle(Curve.SHORT_DASH);

plot ph = if shouldPlot then prevHigh else Double.NaN;
ph.SetStyle(Curve.SHORT_DASH);
ph.SetDefaultColor(Color.DARK_GREEN);

rec runningOpen = CompoundValue(1, if OpeningBell then open[1] else runningOpen[1], open);
rec prevOpen = CompoundValue(1, if OpeningBell then runningOpen else prevOpen[1], open);
plot Open = if shouldPlot then prevOpen else Double.NaN;

Open.SetStyle(Curve.SHORT_DASH);
Open.SetDefaultColor(Color.YELLOW);
 
Last edited:

cay7man

Member
VIP
After the market close, I want to load a study that paints arrow on specific bars (5 min)? doable?

Thx!
 

easyman

New member
Good day all,

I want to setup scan to run ONLY after the market closes (are say at 3 PM PST).

Is it possible (all the gettime and other functions are not allowing it)

Thanks in advance
MN
 

easyman

New member
@BenTen ,
Thanks unfortunately ... it's not working..

I want to add a code so my scanner can run ONLY after after market ... and only once ... so i don't get multiple alerts :)

Here is the code i took.. all of them comes as ZERO only weird... ii changed the time to earlier to run... hmmm. nothing.

----
def startofRunTime = 1611;
def endOfTradingTime = 1645 ;

def isActive = if SecondsTillTime(endOfTradingTime) > 0 and SecondsFromTime(startofRunTime) >= 0
then 1
else 0;
----------


Thanks again.
 

BlueRaven

New member
I'm looking to figure the RTH hours ATR but on a extended hours chart for futures...

I know you can have thinkscript look at only certain times, but I'm not sure how to or if it's possible to only have it look at RTH timeframe over a series of days.

I'll work on this some and see if I can figure it out, but I figured I would ask here as if anyone knows it would be someone on here.

Thanks.
 

Similar threads

Top