Opening Range Breakout Indicator for ThinkorSwim

Can someone provide AddChartBubble code so that when Price cross above and below the Opening High and Low. The Bubble text would display "B" for when price cross above the ORHigh and "S" when price cross below the ORLow. See Code below.

Code:
input opentime = 0930;
input ORend = 0934;

AddChartBubble(SecondsTillTime(0930) == 0, high, "NY", Color.WHITE, yes);
AddVerticalLine(SecondsTillTime(0930) == 0, "NEW YORK ", Color.CYAN, Curve.FIRM);

def na = Double.NaN;
def ORActive = if GetLastDay() == GetDay() and SecondsFromTime(opentime) >= 0 and SecondsFromTime(ORend) < 0 then 1 else 0;
def ORHigh = if ORActive then high else na;
def ORLow = if ORActive then low else na;
def ORLow2 = if ORActive then low else na;

plot OHIGH = if GetLastDay() != GetDay() or !ORActive then na else HighestAll(ORHigh);
plot OLOW = if GetLastDay() != GetDay() or !ORActive then na else LowestAll(ORLow);
plot OLOW2 = if GetLastDay() != GetDay() or !ORActive then na else LowestAll(ORLow);
plot HIGH = if GetLastDay() != GetDay() or SecondsFromTime(ORend) < 0 then na else HighestAll(ORHigh);
plot LOW = if GetLastDay() != GetDay() or SecondsFromTime(ORend) < 0 then na else LowestAll(ORLow);

OHIGH.SetStyle(Curve.SHORT_DASH);
OLOW.SetStyle(Curve.SHORT_DASH);
OLOW2.SetStyle(Curve.SHORT_DASH);
OHIGH.SetDefaultColor(Color.GREEN);
OLOW.SetDefaultColor(Color.RED);
OLOW2.SetDefaultColor(Color.RED);
HIGH.SetStyle(Curve.SHORT_DASH);
LOW.SetStyle(Curve.SHORT_DASH);
HIGH.SetDefaultColor(Color.GREEN);
LOW.SetDefaultColor(Color.RED);

AddCloud(OLOW, OHIGH, COLOR.white, COLOR.white, YES);
 
@Branch For some reason, the code you provided doesn't play well with the AddChartBubble function that I included in it. As a result, I had to try a different code.

This one is similar to what you have, but the settings are different. You may have to modify some of the features to match your old settings.

Code:
# Clayburgs Directional Day Filter
# Written by KumoBob Dec 31 2009

# Thanks to ThinkScriptor and aPPLE_PI for helping me with the secondsfromtime() function by showing me the code writen by Prospectus in his Opening Range study.


# Directional Day Filter Line - After the first five minutes calculate the average range for this 5-minute bar. Draw a horizontal line at this level.
# Time Line - Draw a vertical line at 60-minute bar (Low to High of the day so far).
# (slower value for faster moving charts like currency and S&P – Faster value for slower moving charts) (45 minutes to 90 minutes)
# Determine the amount of activity above and below the Directional Day Filter Line prior to the Time Line.
# (A rectangle can be drawn with Blue shading above and Red below the Directional Day Filter Line)
# If the majority of the activity is above the Directional Day Filter Line the trend bias for the day will be higher.
# If the majority of the activity is below the Directional Day Filter Line the trend bias for the day will be lower.
# If it's even the day will most likely be flat.
# If the closing bar on the Time Line is within 1/3 the distance from the Directional Day Filter Line then added bias can be anticipated.

#hint: Best used in a 1 to 5 minute chart period


def na = double.nan;
############### Directional Day Filter Line ##############


input ORBegin = 0930;
input OREnd = 0935;
# Show Today only? (Default Yes)
input ShowTodayOnly = { default "No", "Yes"};
def s = ShowTodayOnly;
# Create logic for OR definition: 1 if between fist 5 minutes
Def ORActive = if secondsTillTime(OREnd) > 0 AND secondsFromTime(ORBegin) >= 0 then 1 else 0;
# Create logic to paint only current day post-open:
def today = if s == 0 OR getDay() == getLastDay() AND secondsFromTime(ORBegin) >= 0 then 1 else 0;
# Track OR High:
Rec ORHigh = if ORHigh[1] == 0 or ORActive[1] == 0 AND ORActive == 1 then high else if ORActive AND high > ORHigh[1] then high else ORHigh[1];
# Track OR Low:
Rec ORLow = if ORLow[1] == 0 or ORActive[1] == 0 AND ORActive == 1 then low else if ORActive AND low < ORLow[1] then low else ORLow[1];
# Calculate OR width:
Def ORWidth = ORHigh - ORLow;
# Define all the plots:
Def ORHA = if ORActive OR today < 1 then na else ORHigh;
Def ORLA = if ORActive OR today < 1 then na else ORLow;
Def O = ORHA - (ORHA - ORLA) / 2;
Plot ORL = if (o == 0 , na, o);
ORL.SetDefaultColor(color.Yellow);
ORL.SetStyle(curve.Long_DASH);
ORL.SetLineWeight(3);

################## Time Line #####################

input ORBegin2 = 0930;
# Define time that OR is finished (in hhmm format,
# 10:00 is the default):
input OREnd2 = 1030;
# Show Today only? (Default Yes)
####input ShowTodayOnly={"No", default "Yes"};
####def s=ShowTodayOnly;
# Create logic for OR definition:
Def ORActive2 = if secondsTillTime(OREnd2) > 0 AND secondsFromTime(ORBegin2) >= 0 then 1 else 0;
# Create logic to paint only current day post-open:
#####def today=if s==0 OR getday()==getlastday() AND secondsfromtime(ORBegin2)>=0 then 1 else 0;
# Track OR High:
Rec ORHigh2 = if ORHigh2[1] == 0 or ORActive2[1] == 0 AND ORActive2 == 1 then high else if ORActive2 AND high > ORHigh2[1] then high else ORHigh2[1];
# Track OR Low:
Rec ORLow2 = if ORLow2[1] == 0 or ORActive2[1] == 0 AND ORActive2 == 1 then low else if ORActive2 AND low < ORLow2[1] then low else ORLow2[1];
# Calculate OR width:
Def ORWidth2 = ORHigh2 - ORLow2;
# Define all the plots:
Plot ORH2 = if ORActive2 OR today < 1 then na else ORHigh2;
Plot ORL2 = if ORActive2 OR today < 1 then na else ORLow2;
# Formatting:
ORH2.SetDefaultColor(color.green);
ORH2.SetStyle(curve.Long_DASH);
ORH2.SetLineWeight(3);
ORL2.SetDefaultColor(color.red);
ORL2.SetStyle(curve.Long_DASH);
ORL2.SetLineWeight(3);

################################
Def TimeLine = if secondsTillTime(OREnd2) == 0 then 1 else 0;

Def pos = (ORH2 - ORL2) / 10;

plot d1 = if (TimeLine , ORH2, na);
plot d2 = if (TimeLine , ORH2 - ( pos * 2), na);
plot d3 = if (TimeLine , ORH2 - ( pos * 3), na);
plot d4 = if (TimeLine , ORH2 - ( pos * 4), na);
plot d5 = if (TimeLine , ORH2 - ( pos * 5), na);
plot d6 = if (TimeLine , ORH2 - ( pos * 6), na);
plot d7 = if (TimeLine , ORH2 - ( pos * 7), na);
plot d8 = if (TimeLine , ORH2 - ( pos * 8), na);
plot d9 = if (TimeLine , ORH2 - ( pos * 9), na);
plot d10 = if (TimeLine , (ORL2), na);

d1.SetPaintingStrategy(PaintingStrategy.arrow_down);
d2.SetPaintingStrategy(PaintingStrategy.POINTS);
d3.SetPaintingStrategy(PaintingStrategy.POINTS);
d4.SetPaintingStrategy(PaintingStrategy.POINTS);
d5.SetPaintingStrategy(PaintingStrategy.POINTS);
d6.SetPaintingStrategy(PaintingStrategy.POINTS);
d7.SetPaintingStrategy(PaintingStrategy.POINTS);
d8.SetPaintingStrategy(PaintingStrategy.POINTS);
d9.SetPaintingStrategy(PaintingStrategy.POINTS);
d10.SetPaintingStrategy(PaintingStrategy.ARROW_UP);


d2.HideBubble();
d3.HideBubble();
d4.HideBubble();
d5.HideBubble();
d6.HideBubble();
d7.HideBubble();
d8.HideBubble();
d9.HideBubble();



DEF Span = (O - ORL2) / (ORH2 - ORL2);
rec colorState = if Span > 0.66 then -1
else if Span < 0.33 then 1 else 0;


d1.AssignValueColor(
if colorState < 0 then Color.RED else
if colorState > 0 then Color.GREEN else
Color.Yellow
);

d2.AssignValueColor(
if colorState < 0 then Color.RED else
if colorState > 0 then Color.GREEN else
Color.Yellow
);

d3.AssignValueColor(
if colorState < 0 then Color.RED else
if colorState > 0 then Color.GREEN else
Color.Yellow
);

d4.AssignValueColor(
if colorState < 0 then Color.RED else
if colorState > 0 then Color.GREEN else
Color.Yellow
);

d5.AssignValueColor(
if colorState < 0 then Color.RED else
if colorState > 0 then Color.GREEN else
Color.Yellow
);

d6.AssignValueColor(
if colorState < 0 then Color.RED else
if colorState > 0 then Color.GREEN else
Color.Yellow
);

d7.AssignValueColor(
if colorState < 0 then Color.RED else
if colorState > 0 then Color.GREEN else
Color.Yellow
);

d8.AssignValueColor(
if colorState < 0 then Color.RED else
if colorState > 0 then Color.GREEN else
Color.Yellow
);

d9.AssignValueColor(
if colorState < 0 then Color.RED else
if colorState > 0 then Color.GREEN else
Color.Yellow
);

d10.AssignValueColor(
if colorState < 0 then Color.RED else
if colorState > 0 then Color.red else
Color.Yellow
);
d1.SetLineWeight(5);
d2.SetLineWeight(5);
d3.SetLineWeight(5);
d4.SetLineWeight(5);
d5.SetLineWeight(5);
d6.SetLineWeight(5);
d7.SetLineWeight(5);
d8.SetLineWeight(5);
d9.SetLineWeight(5);
d10.SetLineWeight(5);

#######################################################################


Def TimeLineb = if secondsTillTime(OREND) == 0 then 1 else 0;

Def posbd = (ORHA - ORLA) / 10;

plot bd1 = if (TimeLineb , ORHA, na);
plot bd2 = if (TimeLineb , ORHA - ( posbd * 2), na);
plot bd3 = if (TimeLineb , ORHA - ( posbd * 3), na);
plot bd4 = if (TimeLineb , ORHA - ( posbd * 4), na);
plot bd5 = if (TimeLineb , ORHA - ( posbd * 5), na);
plot bd6 = if (TimeLineb , ORHA - ( posbd * 6), na);
plot bd7 = if (TimeLineb , ORHA - ( posbd * 7), na);
plot bd8 = if (TimeLineb , ORHA - ( posbd * 8), na);
plot bd9 = if (TimeLineb , ORHA - ( posbd * 9), na);
plot bd10 = if (TimeLineb , (ORL2), na);

bd1.SetPaintingStrategy(PaintingStrategy.POINTS);
bd2.SetPaintingStrategy(PaintingStrategy.POINTS);
bd3.SetPaintingStrategy(PaintingStrategy.POINTS);
bd4.SetPaintingStrategy(PaintingStrategy.POINTS);
bd5.SetPaintingStrategy(PaintingStrategy.POINTS);
bd6.SetPaintingStrategy(PaintingStrategy.POINTS);
bd7.SetPaintingStrategy(PaintingStrategy.POINTS);
bd8.SetPaintingStrategy(PaintingStrategy.POINTS);
bd9.SetPaintingStrategy(PaintingStrategy.POINTS);
bd10.SetPaintingStrategy(PaintingStrategy.POINTS);

bd1.SetDefaultColor(Color.YELLOW);
bd2.SetDefaultColor(Color.YELLOW);
bd3.SetDefaultColor(Color.YELLOW);
bd4.SetDefaultColor(Color.YELLOW);
bd5.SetDefaultColor(Color.YELLOW);
bd6.SetDefaultColor(Color.YELLOW);
bd7.SetDefaultColor(Color.YELLOW);
bd8.SetDefaultColor(Color.YELLOW);
bd9.SetDefaultColor(Color.YELLOW);
bd10.SetDefaultColor(Color.YELLOW);

bd1.HideBubble();
bd2.HideBubble();
bd3.HideBubble();
bd4.HideBubble();
bd5.HideBubble();
bd6.HideBubble();
bd7.HideBubble();
bd8.HideBubble();
bd9.HideBubble();
bd10.HideBubble();

AddCloud(ORL2, ORH2, color.green, color.green);
#def aggregation = if getAggregationPeriod() == (AggregationPeriod.MIN * 5) or (AggregationPeriod.MIN * 10) or (AggregationPeriod.MIN * 15) then 1 else 0 ;
def aggregation = 1;

def breakout = close crosses above ORH2;
def breakdown = close crosses below ORL2;

AddChartBubble(breakout, low, "B", Color.light_green, no);
AddChartBubble(breakdown, high, "S", Color.light_red, no);
 
So Mobius posted an ORB study that draws lines for the High and Low of the first candle, but it changes based on the Chart Time Frame. I like to use the 15 minute chart for my ORB lines and then trade on the 5 min chart.

Is there a way to make the code below, do that? That is, draw the high and low of the 15 minute chart on any of the time frames I pull up or will it always be based off the first candle of the current time frame?

Code:
# ORB for TOS Mobile App
# Mobius
# V01.08.2018

def o = open;
def h = high;
def l = low;
def c = close;
def OpeningBell = getTime()[1] < RegularTradingStart(getYYYYMMDD()) and
                  getTime() > RegularTradingStart(getYYYYMMDD());
def RTH = getTime() >= RegularTradingStart(getYYYYMMDD()) and
          getTime() <= RegularTradingEnd(getYYYYMMDD());
def ORActive = getTime() >= OpeningBell and
               getTime() <= RegularTradingStart(getYYYYMMDD()) + 1800000;
def ORH = if OpeningBell
          then h
          else if ORActive and
                  h > ORH[1]
               then h
               else ORH[1];
def ORL = if OpeningBell
          then l
          else if ORActive and
                  l < ORL[1]
               then l
               else ORL[1];
plot ORhigh = if !ORActive and RTH
              then ORH
              else Double.NaN;
ORhigh.SetStyle(Curve.LONG_DASH);
ORhigh.SetLineWeight(3);
ORhigh.SetDefaultColor(Color.GREEN);
plot ORlow = if !ORActive and RTH
             then ORL
             else Double.NaN;
ORlow.SetStyle(Curve.LONG_DASH);
ORlow.SetLineWeight(3);
ORlow.SetDefaultColor(Color.RED);
def ORmeanActive = getTime() >= OpeningBell and
                   getTime() <= RegularTradingStart(getYYYYMMDD()) + 300000;
def ORmeanH = if OpeningBell
              then h
              else if ORmeanActive and h > ORmeanH[1]
                   then h
                   else ORmeanH[1];
def ORmeanL = if OpeningBell
              then l
              else if ORmeanActive and l < ORmeanL[1]
                   then l
                   else ORmeanL[1];
plot ORmean = if !ORmeanActive and RTH
              then Round(((ORmeanH + ORmeanL) / 2) / TickSize(), 0) * TickSize()
              else Double.NaN;
ORmean.SetStyle(Curve.LONG_DASH);
ORmean.SetLineWeight(3);
ORmean.SetDefaultColor(Color.YELLOW);
# End Code ORB for Mobile App
 
@CaptainNORDO

Change the first few lines of the code. But be-aware you need 15m to close to form the ORB and you can be in the lower timeframe not on the higher timeframe. Any frame higher then 15m will not show the ORB lines.

Code:
input aP = AggregationPeriod.FIFTEEN_MIN;
def o = open(period = aP);
def h = high(period = aP);
def l = low(period = aP);
def c = close(period = aP);
 
Good morning,
I would like to change the start on the ORBI from 9:30 to opening bell. Is that possible? If so can someone please guide me on how to change it.
Please and thank you
 
Good morning,
I would like to change the start on the ORBI from 9:30 to opening bell. Is that possible? If so can someone please guide me on how to change it.
Please and thank you
I like that idea too. I have been doing opening bell trades without success as it's a rollercoaster. After months of unsuccessful trades, I have decided not to trade for the first 30 minutes.
 
that is the whole idea. @s1111 you need to wait for a specific time to give you price range for a specific day. How about start from the beginning of what it is supposed to do? I would suggest read up this and may be few other Openrange threads on this form to see how openrange indicators are supposed to work before you deploy them in your strategy .

-S
 
Nice! this looks to be very useful. Can you please explain what the white line & RO mean? (Risk ON/OFF?) Also could you explain what Risk On ORL with red line and Risk On ORH with green line mean? Hope these questions make sense, thank you!

I’m also pondering the idea if somehow this could be turned into a watchlist column. Green bar for bull zone red bar for bear zone. 🤔
 
Can someone please explain what "RO" means?

I've seen other people ask and no-one answers.

What is the point of the RO line? PC line? Etc?

A glossary would be great.
 

New Indicator: Buy the Dip

Check out our Buy the Dip indicator and see how it can help you find profitable swing trading ideas. Scanner, watchlist columns, and add-ons are included.

Download the indicator

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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