Opening Range Breakout [Claude Ai] For ThinkOrSwim

Risktk1r

New member
VIP
I ask Claude Ai to write this script. If all conditions are met by 10:00am, the indicator will be above 0 (1) and trigger the alert. You would need to have a chart open with the script installed. Cannot say how well it works yet, just got it working today (4/1/26)

Code:
# Opening Range Breakout (ORB) Study
# Conditions:
#   1. Price breaks above 30-min Opening Range High (9:30–10:00 AM EST)
#   2. Breakout bar volume >= 1.5x avg volume of opening range
#   3. Price is above VWAP
#   4. Time is within first 2 hours of session (before 11:30 AM EST)
#   5. (Refinement) Breakout bar closes in TOP 50% of its range
#
# Compatible with 1-min, 5-min, and 15-min charts
# ============================================================



# ─────────────────────────────────────────────
# INPUTS
# ─────────────────────────────────────────────
input showORHLine      = yes;   # Toggle OR High horizontal line
input showLabels       = yes;   # Toggle info labels
input volumeMultiplier = 1.5;   # Volume threshold vs OR average

# ─────────────────────────────────────────────
# SESSION / TIME DEFINITIONS
# ─────────────────────────────────────────────
def marketOpen    = 0930;   # 9:30 AM EST
def orEnd         = 1000;   # 10:00 AM EST (end of opening range)
def sessionCutoff = 1600;   # 11:30 AM EST (2-hour mark, alerts stop)

def isORWindow    = SecondsFromTime(marketOpen) >= 0
                    and SecondsTillTime(orEnd) > 0;

def isAlertWindow = SecondsFromTime(marketOpen) >= 0
                    and SecondsTillTime(sessionCutoff) > 0;

# ─────────────────────────────────────────────
# OPENING RANGE HIGH & VOLUME
# ─────────────────────────────────────────────

# Track the high of the 9:30–10:00 AM range
def orHigh = HighestAll(if isORWindow then high else Double.NaN);

# Count how many bars are in the opening range window
def orBarCount = TotalSum(if isORWindow then 1 else 0);

# Sum volume during the OR window
def orVolSum   = TotalSum(if isORWindow then volume else 0);

# Average volume per bar during OR
def orAvgVol   = if orBarCount > 0 then orVolSum / orBarCount else 1;

# ─────────────────────────────────────────────
# VWAP
# ─────────────────────────────────────────────
def vwap = reference VWAP();

# ─────────────────────────────────────────────
# BREAKOUT CONDITIONS
# ─────────────────────────────────────────────

# 1. Price closes ABOVE the OR high (breakout confirmed on close)
def breakoutAboveOR = close > orHigh;

# 2. Current bar volume is >= 1.5x the OR average volume
def highVolume = volume >= volumeMultiplier * orAvgVol;

# 3. Price is above VWAP
def aboveVWAP = close > vwap;

# 4. Within the first 2 hours of the session (before 11:30 AM)
def withinWindow = isAlertWindow;

# 5. Refinement: Breakout bar closes in the TOP 50% of its range
#    (confirms strong buying pressure — not just a poke above)
def barRange      = high - low;
def midpoint      = low + barRange * 0.5;
def topHalfClose  = close >= midpoint;

# ─────────────────────────────────────────────
# ALL CONDITIONS MET
# ─────────────────────────────────────────────
def allConditions = breakoutAboveOR
                    and highVolume
                    and aboveVWAP
                    and withinWindow
                    and topHalfClose;

# Fire once per bar (not re-trigger mid-bar)
def alertTrigger = allConditions and !allConditions[1];

# ─────────────────────────────────────────────
# VISUALS — OR HIGH HORIZONTAL LINE
# ─────────────────────────────────────────────
plot ORHighLine = if showORHLine and orHigh > 0 then orHigh else Double.NaN;
ORHighLine.SetDefaultColor(Color.YELLOW);
ORHighLine.SetLineWeight(2);
ORHighLine.SetStyle(Curve.SHORT_DASH);
ORHighLine.HideBubble();
ORHighLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

# ─────────────────────────────────────────────
# VISUALS — BREAKOUT SIGNAL ARROW
# ─────────────────────────────────────────────
plot BreakoutSignal = if alertTrigger then low - TickSize() * 5 else Double.NaN;
plot AlertPlot = if alertTrigger then 1 else 0;
BreakoutSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BreakoutSignal.SetDefaultColor(Color.GREEN);
BreakoutSignal.SetLineWeight(3);
BreakoutSignal.HideBubble();

# ─────────────────────────────────────────────
# VISUALS — BACKGROUND HIGHLIGHT
# ─────────────────────────────────────────────
AssignBackgroundColor(if allConditions then Color.DARK_GREEN else Color.CURRENT);

# ─────────────────────────────────────────────
# LABELS
# ─────────────────────────────────────────────
AddLabel(showLabels and orHigh > 0,
    "OR High: " + AsPrice(orHigh),
    Color.YELLOW);

AddLabel(showLabels,
    "Vol vs OR Avg: " + Round(volume / orAvgVol, 2) + "x",
    if highVolume then Color.GREEN else Color.GRAY);

AddLabel(showLabels,
    "VWAP: " + AsPrice(vwap),
    if aboveVWAP then Color.GREEN else Color.RED);

AddLabel(showLabels,
    if withinWindow then "IN Window (<11:30)" else "OUT of Window",
    if withinWindow then Color.GREEN else Color.GRAY);

AddLabel(showLabels and allConditions,
    "[B]* ORB SETUP ACTIVE *[/B]",
    Color.GREEN);

# ─────────────────────────────────────────────
# ALERT
# ─────────────────────────────────────────────
# ─────────────────────────────────────────────
# ALERT
# ─────────────────────────────────────────────
Alert(alertTrigger,
    "ORB BREAKOUT - Check Symbol, Price, and Volume",
    Alert.BAR,
    Sound.Ding);
 
Last edited by a moderator:

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
1565 Online
Create Post

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