Opening Range Breakout (ORB) Scanner for ThinkorSwim

@netarchitech
What I find great is, that your scanner shows all symbols, which crosses the opening range within the trading day.
Ben's scanner has a limitation, because it includes "within 2 bars" so only the last 10 minutes are shown. After 10 minutes the symbols on the watchlist will disappear. For a long time I'm searching for the option to see historically which symbols met the scanner criteria over the day. For example trade-ideas shows all symbols an alert was triggered for.
@Antares66 the "within x bars" is what is available to us on the ToS app
 

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

I am facing below error while trying to create a scanner. I followed the steps but still same. Can you please help?
"com.devexperts.tos.thinkscript.runtime.TooComplexException: The complexity of the expression suggests that it may not be reliable with real-time data."
 
Last edited by a moderator:
I'm running an ORB Scanner I found online and modified it to show instances of clean breaks above the 15-minute opening range (OR). I want to take it a step further and ONLY display green bars that also have a low that crosses into the ORB. See below for an example of what I'm looking for:

The fourth bar in $AAPL has a low that crosses below the 15-minute opening range, an open above the opening range, and a close above the open.

NyK22Nu.png


I tried to modify the code below by changing the plot conditions and had some success as I'm seeing bars where the low crosses into the OR but I'm having difficulty making it scan for only green bars. I'm still seeing a mix of red bars where technically the open and close are both above the OR. I tried using "open < close" and "isAscending(close, 1)" but both are filtering out $AAPL which I'm using to validate the scanners effectiveness. The formation is pretty clear in $AAPL on the 15 minute timeframe so I'm not sure why this is happening. See below for the code I'm using.

Code:
def orStartTime = 0930;
def orEndTime = 0945;

# opening range time logic
def isOr = secondstilltime(orEndTime) > 0
    and secondsfromtime(orStartTime) >= 0;
def afterOR = secondsFromTime(orEndTime) >= 0;
def hi = high;
def lo = low;

# opening range levels logic
rec orhi =
    if orhi[1] == 0
        or !isOr[1]
        and isOr
    then hi
    else if isOr
        and hi > orhi[1]
    then hi
    else orhi[1];

rec orlo =
    if orlo[1] == 0
        or !isOr[1]
        and isOr
    then lo
    else if isOr
        and lo < orlo[1]
    then lo
    else orlo[1];

plot orb = afterOR and low < ORHI and open > ORHI and close > ORHI;
 
I'm running an ORB Scanner I found online and modified it to show instances of clean breaks above the 15-minute opening range (OR). I want to take it a step further and ONLY display green bars that also have a low that crosses into the ORB. See below for an example of what I'm looking for:

The fourth bar in $AAPL has a low that crosses below the 15-minute opening range, an open above the opening range, and a close above the open.

NyK22Nu.png


I tried to modify the code below by changing the plot conditions and had some success as I'm seeing bars where the low crosses into the OR but I'm having difficulty making it scan for only green bars. I'm still seeing a mix of red bars where technically the open and close are both above the OR. I tried using "open < close" and "isAscending(close, 1)" but both are filtering out $AAPL which I'm using to validate the scanners effectiveness. The formation is pretty clear in $AAPL on the 15 minute timeframe so I'm not sure why this is happening. See below for the code I'm using.

Code:
def orStartTime = 0930;
def orEndTime = 0945;

# opening range time logic
def isOr = secondstilltime(orEndTime) > 0
    and secondsfromtime(orStartTime) >= 0;
def afterOR = secondsFromTime(orEndTime) >= 0;
def hi = high;
def lo = low;

# opening range levels logic
rec orhi =
    if orhi[1] == 0
        or !isOr[1]
        and isOr
    then hi
    else if isOr
        and hi > orhi[1]
    then hi
    else orhi[1];

rec orlo =
    if orlo[1] == 0
        or !isOr[1]
        and isOr
    then lo
    else if isOr
        and lo < orlo[1]
    then lo
    else orlo[1];

plot orb = afterOR and low < ORHI and open > ORHI and close > ORHI;

This seems to work. Paste this inot the scanner editor set to 15min and extended hours turned off. Just added close > open to orb and had it be a 1/0 plot statement. That made the scan line within 26 bars clearer to define for true statements during RTHours, since we are running the scan after market close. You can take the within 26 bars to how many you want when scanning during market hours.

AAPL shows up in the scan results only for bar 4 you identified in the orb.

Ruby:
def orStartTime = 0930;
def orEndTime = 0945;

# opening range time logic
def isOr = SecondsTillTime(orEndTime) > 0
    and SecondsFromTime(orStartTime) >= 0;
def afterOR = SecondsFromTime(orEndTime) >= 0;
def hi = high;
def lo = low;

# opening range levels logic
rec orhi =
    if orhi[1] == 0
        or !isOr[1]
        and isOr
    then hi
    else if isOr
        and hi > orhi[1]
    then hi
    else orhi[1];

rec orlo =
    if orlo[1] == 0
        or !isOr[1]
        and isOr
    then lo
    else if isOr
        and lo < orlo[1]
    then lo
    else orlo[1];

def orb = if afterOR and low < orhi and open > orhi and close > orhi and close > open then 1 else 0;
plot scan = orb within 26 bars ;
 
I'm running an ORB Scanner I found online and modified it to show instances of clean breaks above the 15-minute opening range (OR). I want to take it a step further and ONLY display green bars that also have a low that crosses into the ORB. See below for an example of what I'm looking for:

The fourth bar in $AAPL has a low that crosses below the 15-minute opening range, an open above the opening range, and a close above the open.

NyK22Nu.png


I tried to modify the code below by changing the plot conditions and had some success as I'm seeing bars where the low crosses into the OR but I'm having difficulty making it scan for only green bars. I'm still seeing a mix of red bars where technically the open and close are both above the OR. I tried using "open < close" and "isAscending(close, 1)" but both are filtering out $AAPL which I'm using to validate the scanners effectiveness. The formation is pretty clear in $AAPL on the 15 minute timeframe so I'm not sure why this is happening. See below for the code I'm using.

Code:
def orStartTime = 0930;
def orEndTime = 0945;

# opening range time logic
def isOr = secondstilltime(orEndTime) > 0
    and secondsfromtime(orStartTime) >= 0;
def afterOR = secondsFromTime(orEndTime) >= 0;
def hi = high;
def lo = low;

# opening range levels logic
rec orhi =
    if orhi[1] == 0
        or !isOr[1]
        and isOr
    then hi
    else if isOr
        and hi > orhi[1]
    then hi
    else orhi[1];

rec orlo =
    if orlo[1] == 0
        or !isOr[1]
        and isOr
    then lo
    else if isOr
        and lo < orlo[1]
    then lo
    else orlo[1];

plot orb = afterOR and low < ORHI and open > ORHI and close > ORHI;

it is hard to debug a column or scan study.
i run them on a chart and add bubbles to display values and draw verical lines to see when something happens.

to find only green bars, change the last line, to compare close to open, not orhi.
. and close > open );


test code
Code:
# orb_crosshiline_00

def orStartTime = 0930;
def orEndTime = 0945;

# opening range time logic
def isOr = secondstilltime(orEndTime) > 0
    and secondsfromtime(orStartTime) >= 0;
def afterOR = secondsFromTime(orEndTime) >= 0;
def hi = high;
def lo = low;

# opening range levels logic
rec orhi =
    if orhi[1] == 0
        or !isOr[1]
        and isOr
    then hi
    else if isOr
        and hi > orhi[1]
    then hi
    else orhi[1];

rec orlo =
    if orlo[1] == 0
        or !isOr[1]
        and isOr
    then lo
    else if isOr
        and lo < orlo[1]
    then lo
    else orlo[1];

plot z1 = orhi;
plot z2 = orlo;

#plot orb = ( afterOR and low < ORHI and open > ORHI and close > orhi );
def orb = ( afterOR and low < ORHI and open > ORHI and close > open );

addverticalline(orb, "x", color.cyan);
#

vertical lines are drawn just before the bar that triggers them
this example shows when orb was true 2 times that day
zeqGFsw.jpg
 
This seems to work. Paste this inot the scanner editor set to 15min and extended hours turned off. Just added close > open to orb and had it be a 1/0 plot statement. That made the scan line within 26 bars clearer to define for true statements during RTHours, since we are running the scan after market close. You can take the within 26 bars to how many you want when scanning during market hours.

AAPL shows up in the scan results only for bar 4 you identified in the orb.

Thank you for this, it's functioning as intended now.

Final question, is there a way to check the condition against only the first five 15-minute bars of the day? It seems that "within" goes from the end of the day to the beginning of the day when I was experimenting with it but is there a way to do that in reverse?
 
As MerrDay posted above, you MUST USE this link to get the create the scan setup to work as indicated

Load Shared Study Link: http://tos.mx/oxkzZsr Save the study under the name: BetterOrb. (if you skip this part the scanner in part two will not

This link http://tos.mx/NzMhcR will load a preset scan but has a "Too complex exception " indication.
 
@BenTen I've retooled Robert Payne's scan above to further refine results. Just plug in the desired percentage amount in the "Limiter" input and scan. Also, make sure to specify whether you're looking for Breakouts or Breakdowns by positioning the Hashtag (#) in front of the plot statement you want to exclude...

Rich (BB code):
# Filename: 30_min_Opening_Range_SCAN

# source: 30 min opening range
# original author: Robert Payne

def OpenRangeMinutes = 30;
def MarketOpenTime = 0930;
input ShowTodayOnly = yes;
input Limiter = 0.05;

def Today = if GetDay() == GetLastDay()
            then 1
            else 0;
               
def FirstMinute = if SecondsFromTime(MarketOpenTime) < 60
                  then 1
                  else 0;
                     
def OpenRangeTime = if SecondsFromTime(MarketOpenTime) < 60 * OpenRangeMinutes
                    then 1
                    else 0;

def ORHigh =  if FirstMinute
              then high
              else if OpenRangeTime and high > ORHigh[1]
                   then high
                   else ORHigh[1];
                        
def ORLow = if FirstMinute
            then low
            else if OpenRangeTime and low < ORLow[1]
                 then low
                 else ORLow[1];

def OpenRangeHigh = if ShowTodayOnly and !Today
                    then Double.NaN
                    else if !OpenRangeTime
                         then ORHigh
                         else Double.NaN;
                              
def OpenRangeLow = if ShowTodayOnly and !Today
                   then Double.NaN
                   else if !OpenRangeTime
                        then ORLow
                        else Double.NaN;

def PreviousRange = high[1] - low[1];
def range = Average(PreviousRange, 10);

def entryLine1 = OpenRangeHigh + (range * 0.06);
def entryLine2 = OpenRangeLow - (range * 0.06);

# Scan currently set to find Breakouts
# Move Hashtag to Breakout plot to scan for Breakdowns
# Limiter set by user (currently 5 percent)

plot breakout = close > (entryline1 + (entryline1 * Limiter));
#plot breakdown = close < (entryline2 - (entryline2 * Limiter));
When I ran this without the "Limiter" I got 233 results...After plugging in the Limiter, the scan returned 3 results...

Hope this helps...

Good Luck and Good Trading :)
@netarchitech when you plugged in the limiter what did you change it to? Did you change it within the script?
 
Hi, all. So far I cannot find an ORB scanner that works with futures. Is there a way to get @tomsk's code here to work on futures? It will give one result via an error code.


It would have been nice to know that PL was breaking out via a watchlist or scan window results. Is there a way to accomplish that? Thank you in advance if anyone can enlighten me :)
 
Hi, all. So far I cannot find an ORB scanner that works with futures. Is there a way to get @tomsk's code here to work on futures? It will give one result via an error code.


It would have been nice to know that PL was breaking out via a watchlist or scan window results. Is there a way to accomplish that? Thank you in advance if anyone can enlighten me :)
You need to use a valid symbol
 
@BenTen hey i was able to use the script at the top and i unplotted everything but the low and high lines but its shaded in and i cant figure out how to remove the shading
 
@BenTen hey i was able to use the script at the top and i unplotted everything but the low and high lines but its shaded in and i cant figure out how to remove the shading
Welcome to the Forum.
"shading" is created by AddCloud statements.
You can delete those lines
or
You can put # hastags in front of those statements which comments them out of the active code.
 
I have a basic question about the scan. Does the scanner show valid entries throughout the day or is it only used at the beginning of the day? Nevermind I figured it out
 
Last edited:
@full_of_options Give this a try: https://tos.mx/NzMhcR

I named my indicator "BetterORB" so make sure you change yours to that or change the source code to match with however you named your indicator.
Hi Ben,

I understand this is an old post but very interesting. I have 2 questions and wondering if you could help me.

1- Since this is from 2018, have you released a new version of the (ORB)?
2- I tried using the scanner but had no luck setting it up. I wonder because your version is different than mine?

Many thanks!
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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