Above/Below Pre-Market Levels Scanner for ThinkorSwim



New member
Hey guys, this is my first post here. The information you can find on this forum is so unbelievably valuable and I've learned so much already from exploring all the different strategies and testing out different indicator combinations myself (with a good amount of success). I can't thank everyone enough who posts here, it's an amazing resource.

One thing I couldn't find when I was digging around, however, was a simple custom scan to add to scan queries that looks for stocks Above their Pre-Market High level. I use this for day trading and swing trading to find stocks that tend to break above these levels and continue their trend throughout the morning or into the next day.

Using code from this post here:
I changed the bottom few lines so that it can be used for scans. Here is the code:

input alertPeriodStart = 930;
input alertPeriodEnd = 1130;
input alertOnBreak = no;
input alertOnPullBack = no;
input numberOfDays = 2;
input numberOfYears = 0;

def okToPlot = GetLastDay() - numberOfDays <= GetDay() and GetLastYear() - numberOfYears <= GetYear() ;

def startCounter =  SecondsFromTime(alertPeriodStart);
def endCounter = SecondsTillTime(alertPeriodEnd);

def alertPeriod = if startCounter >= 0 and endCounter >= 0 then 1 else 0;

def regularSessionHours = RegularTradingStart(GetYYYYMMDD()) <= GetTime();
def extendedSessionHours = RegularTradingStart(GetYYYYMMDD()) >= GetTime();

def extendedSessionStart = regularSessionHours[1] and extendedSessionHours;
def regularSessionStart = extendedSessionHours[1] and regularSessionHours;

def extendedSessionHigh = CompoundValue(1, if extendedSessionStart then high else if extendedSessionHours then Max(high, extendedSessionHigh[1]) else extendedSessionHigh[1], high);

def extendedSessionLow = CompoundValue(1, if extendedSessionStart then low else if extendedSessionHours then Min(low, extendedSessionLow[1]) else extendedSessionLow[1],low);

def regularSessionHigh = CompoundValue(1, if regularSessionStart then high else if regularSessionHours then Max(high, regularSessionHigh[1]) else regularSessionHigh[1], 0);

def regularSessionLow = CompoundValue(1, if regularSessionStart then low else if regularSessionHours then Min(low, regularSessionLow[1]) else regularSessionLow[1], 0);

plot overnightHigh = close > extendedSessionHigh;

#plot overnightLow = close < extendedSessionLow;

If you're looking for stocks that are Below the Pre Market Low level, just switch the hashtag on the last two lines.

To Mods:
If this is formatted wrong or has been posted somewhere else, feel free to edit this post however you like. Thought I'd put this info our there just for people who are having a hard time finding something like this like I was.
Last edited by a moderator:


Well-known member
If anyone is having a go at decoding the actual times that extended session hours entails, here is a quick way to determine that.
Run the following code on a 1 minute chart of /ES. You will see visually those timeframes.
This is the best way of making sure you're looking at the correct time bracket.

declare lower;
plot extendedSessionHours = RegularTradingStart(GetYYYYMMDD()) >= GetTime();

Similar threads