Thinkorswim Overnight Range Scan Alert 16

Intraday Alerts At Overnight Highs and Lows

A quick Google search on the term “Overnight Range Trading Setups” nets some very interesting Thumb TOS Overnight Rangeresults. So I spent some time writing code and looking at charts. I think there is some real evidence to support the inclusion of the overnight range in your trading setups. I’m not here to show you how to trade the overnight range. However I did build you the best tool I can dream up, given my current knowledge and experience. The rest is up to you.


In this video named Thinkorswim Overnight Range Scan Alert, we show you many examples of how this tool may be applied. In addition to some special levels, we also include the ability to build custom scans based on its signals. As if that wasn’t enough, we throw in a bonus by showing how you can generate real time alerts based on the scan results. I am really excited to be able to present this material. I think this may end up being a valuable tool for many. It was a real eye-opener for me.

The code for the scan is included at the very bottom of this post. So be sure when you are done watching the video to scroll down past the video to get to that code. In the video we show you how to use that code to build your own custom scans, with alerts!

*Thinkorswim is a chart analysis platform offered by TD

TD Ameritrade provides financial services including the trading of Stocks, Futures, Options and Forex.


Please be sure to share this page with your friends and colleagues. Leaving comments below is the best way to help make the content of this site even better.

Watch the video, Thinkorswim Overnight Range Scan Alert below:

input alertPeriodStart = 730;
input alertPeriodEnd = 930;
input minimumRange = 10;
input alertOnBreak = yes;
input alertOnPullBack = yes;
input numberOfDays = 0;
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], 0);
def extendedSessionLow = CompoundValue(1, if extendedSessionStart then low else if extendedSessionHours then Min(low, extendedSessionLow[1]) else extendedSessionLow[1], 0);
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);
def overnightHigh = if okToPlot and regularSessionHours then extendedSessionHigh else Double.NaN;
def overnightLow = if okToPlot and regularSessionHours then extendedSessionLow else Double.NaN;
def breakOfHigh = extendedSessionHigh[1] > regularSessionHigh[1] and regularSessionHigh > extendedSessionHigh;
def breakOfLow = extendedSessionLow[1] < regularSessionLow[1] and regularSessionLow < extendedSessionLow;
def pullbackToHigh = low[1] > extendedSessionHigh[1] and low < extendedSessionHigh;
def pullbackToLow = high[1] < extendedSessionLow[1] and high > extendedSessionLow;
def overnightRange = overnightHigh - overnightLow;
plot scan = if alertPeriod and overnightRange >= minimumRange * TickSize() then breakOfHigh or breakOfLow else no;
#plot scan = if alertPeriod and overnightRange >= minimumRange * TickSize() then pullbackToHigh or pullbackToLow else no;

__ Support our free content by making a purchase below. Thanks! __

Comments Drive Content of Future Posts:

16 thoughts on “Thinkorswim Overnight Range Scan Alert

      • D4S

        Ok. I modified this code to include prev days after-hours sessions price action as well. Below is the code if anyone would like to use it. Note that its a simpler version that just plots the AH/PM high/low (without any of the alerts) created to suit my needs.

        #set how many days to plot after-hours/pre-market (AH/PM) highs/lows
        def numberOfDays = 0;
        def numberOfYears = 0;
        def okToPlot = GetLastDay() – numberOfDays <= GetDay() and GetLastYear() – numberOfYears = RegularTradingStart(GetYYYYMMDD())) and (GetTime() = RegularTradingEnd(GetYYYYMMDD());
        def premarketSessionHours = GetTime() <= RegularTradingStart(GetYYYYMMDD());
        def extendedSessionHours = postcloseSessionHours or premarketSessionHours;

        #set flags for AH and regular session starts
        def postcloseSessionStart = regularSessionHours[1] and postcloseSessionHours;
        def regularSessionStart = regularSessionHours and premarketSessionHours[1];

        #update/retain extended hours (AH and PM) highs/lows
        def extendedSessionHigh = CompoundValue(1, if postcloseSessionStart then high else if extendedSessionHours then Max(high, extendedSessionHigh[1]) else extendedSessionHigh[1], 0);
        def extendedSessionLow = CompoundValue(1, if postcloseSessionStart then low else if extendedSessionHours then Min(low, extendedSessionLow[1]) else extendedSessionLow[1], 0);

        #Plot prev days AH and current days PM high/low during current days regular session hours
        plot overnightHigh = if (okToPlot and regularSessionHours) then extendedSessionHigh else Double.NaN;
        plot overnightLow = if (okToPlot and regularSessionHours) then extendedSessionLow else Double.NaN;

      • Pete Hahn Post author

        Um… the original code already covered both after market and before market hours. That’s called Extended Hours session. The code includes all of it. From your previous comment I thought you were asking to have to code only cover the after market hours.

      • D4S

        Earlier response ended up without a few lines of code. Perhaps its the auto format during posting at work here?

      • D4S

        Hmm.. it only showed the pre-market session high/low for me and did not include the prior days after hours high/low. May be I used a different version of the code.

      • Pete Hahn Post author

        There is limited space here as you can see. Not the best place to be trying to work out changes to some code. Please post a request in the Q&A forum if you still need assistance. Make to include a link to the video and a screenshot so we can setup our charts to match yours and figure out what’s up.

  • Frank

    I copied the code above and created the study in TOS. I set the time for 930 1030. It appears quite different that what the video describes. There are only a few settings available – no fibs etc. I can send a screenshot if you would care to check it out. Thank you
    It looks very interesting

    • Pete Hahn Post author

      First question I have is, what time zone do you have your charts set to? The start and end time you list would be compatible only with the Eastern Timezone. The other item to check is to make sure you are plotting extended session in addition to regular session.

      • Pete Hahn Post author

        Ok, this is a chart setting causing the issue. Go to chart settings. Select the Price Axis tab. Uncheck the box named: “Fit Studies”

      • Pete Hahn Post author

        The other problem is you are using the scan version of the code in a chart study. You need to use the Chart study version of the code.

      • fn

        Pete, That fixed the display issue. I would never have figured that out!
        I changed to a QQQ chart with extended hours displayed. the chart is good but no other data is on the chart. the settings in the study control box 920 1030 10 YES YEs 30 0.
        Plots: scan – Show Plot checked
        Again, charts are set for EDT

      • Pete Hahn Post author

        You seem to have missed my last reply in which I explained that you are using the scan version of this code as a chart study. That will never work. The scan code is meant for the scan. You need to get the Chart Study version. Link provided within the video.

    • Frank

      Pete, Thanks so much for your patience.
      I now have both the study and scan installed. I do a lot of scans so that is no issue.
      I will start Playing with the study and see how it goes.
      Will give feedback in a day or two next week.