AGAIG ORB Indicator For ThinkOrSwim

csricksdds

Trader Educator
VIP
AGAIG As Good As It Gets Opening Range Breakout Indicator

As pointed out there are many adaptations to the ORB. I slightly revamped the one from halcyonguy where I've labeled the ORB HI and ORB LO on the chart using yellow lines (no clouds) also with the label above which states whether price is Above/Within/Below ORB. It's also included on my regular chart setup (AGAIG-BestTradingChartSetup). I use broken lines for the first 15 min while the range is being established and then solid lines for rest of the day. Some traders like the first 30 min instead and that change can be made on the code (change aggregation period to thirty_min). I've included a picture of Fridays QQQ where ORB established an opening range low point and never reached that point again. Here is the code and a picture of the indicator by itself. You can see where the day before the QQQs traded below the ORB for most of the day. On my BestTradingChart setup are other complimentary indicators which I use along with the ORB. In day trading once a level is established my assumption is that level will not be achieved again and so I close a position and wait for another established re-entry.

Picture:
Code:
Ruby:
#orb_colors_03
#Mobius original
#csricksdds 2/20
#I like your ORB indicator with the labels that show when above/below...so that the labels don't show only when above/below can you add one showing Yellow "Trading within ORB" when it's trading within?
#Thanks to halcyonguy I have made a few changes to suit myself.
#https://usethinkscript.com/threads/shaded-opening-range-no-breakout.17922/
#Shaded Opening Range (No Breakout)
# 2020-01
# halcyonguy
#Revamped by C. Ricks 2/12/24
def na = Double.NaN;

# pick an agg time
input orb_time = AggregationPeriod.fifteen_min;
def orb_min = orb_time/60000;
def per = orb_min;

input show_ORB_label = yes;
input show_arrows = yes;

# open/close times (ET)
input start = 0930;
input end = 1600;
def daytime = if secondsfromTime(start) >= 0 and secondstillTime(end) > 0 then 1 else 0;

def getgg = getaggregationPeriod();
def getaggmin = round(getgg/60,0);

addlabel(0,getaggmin);

# test if agg time is > than chart time
def aggok = if getaggmin <= orb_min then 1 else 0;


def durationsec = per * 60;
def secondspassed = secondsfromTime(start);
# simulated firstbar , based on orb time
def firstbar = if secondspassed >= 0 and secondspassed < durationsec then 1 else 0;
#addchartbubble(yes,low,per + "" + firstbar + "" + agg);
def afterfirst = if ( daytime and !firstbar ) then 1 else 0;

# is this the first bar after open ?
def openbar = if secondspassed >= 0 and secondspassed <= getgg then 1 else 0;

def ehi = high(period = orb_time);
def elo = low(period = orb_time);

# looks at firstbar , which is orbtime , NOT bar[1]
def perhigh = if !daytime then na else if firstbar then ehi else perhigh[1];
def perlow = if !daytime then na else if firstbar then elo else perlow[1];

# .....................................................


addlabel(1, " ", color.Yellow);
addlabel((close > perhigh),"Price Above ORB", color.green);
addlabel((close < perlow),"Price Below ORB", color.red);
addlabel((close <= perhigh and close >= perlow),"Price Inside ORB", color.yellow);
addlabel(1, " ", color.Yellow);

# .....................................................

# plot dots for first bar timeframe
plot hidots = if firstbar then perhigh else na;
plot lodots = if firstbar then perlow else na;
hidots.setpaintingStrategy(paintingStrategy.Dashes);
lodots.setpaintingStrategy(paintingStrategy.Dashes);
hidots.setDefaultColor(color.yellow);
lodots.setDefaultColor(color.yellow);


# plot line after first bar
plot hiline = if !firstbar then perhigh else na;
plot loline = if !firstbar then perlow else na;
hiline.setpaintingStrategy(paintingStrategy.LINE);
loline.setpaintingStrategy(paintingStrategy.LINE);
hiline.setDefaultColor(color.yellow);
loline.setDefaultColor(color.yellow);

#DefineGlobalColor("orb",color.magenta);
#DefineGlobalColor("orb_after",color.gray);
DefineGlobalColor("orb",color.red);
DefineGlobalColor("orb_after",color.green);

plot static = hiline;
static.AssignValueColor(Color.Yellow);

def limit = !IsNaN(close) and IsNaN(close [-1] ) && LowestAll(BarNumber());

AddChartBubble(limit, static, "ORB HI", Color.Yellow);


plot static2 = loline;
static2.AssignValueColor(Color.Yellow);

def limit2 = !IsNaN(close) and IsNaN(close [-1] ) && LowestAll(BarNumber());

AddChartBubble(limit2, static2, "ORB LO", Color.YELLOW);

##End Code
 
Last edited by a moderator:

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

I tried to move the bubbles on the ORB code which is pasted below but then the code does not work. can anyone post how to incorporate the bubble shift
https://usethinkscript.com/threads/bubblemover-code-snippet-for-thinkorswim.9392/
a few spaces to the right for the following code. if the price is near the ORB hi or lo the bubble overlaps on to of the candle and if you are doing multi time frame with 1, 5 and 15 orb, (three indicators) the labels do not overlap but are stacked and takes up a lot of real estate on the chart. if it can be shifted 2 bars to the right, it would be very helpful. thanks.
Code:
#orb_colors_03
#Mobius original
#csricksdds  2/20
#I like your ORB indicator with the labels that show when above/below...so that the labels don't show only when above/below can you add one showing Yellow "Trading within ORB" when it's trading within?
#Thanks to halcyonguy I have made a few changes to suit myself.
#https://usethinkscript.com/threads/shaded-opening-range-no-breakout.17922/
#Shaded Opening Range (No Breakout)
# 2020-01
# halcyonguy
#Revamped by C. Ricks 2/12/24
def na = Double.NaN;

# pick an agg time
input orb_time = AggregationPeriod.fifteen_min;
def orb_min = orb_time/60000;
def per = orb_min;

input show_ORB_label = yes;
input show_arrows = yes;

# open/close times  (ET)
input start = 0930;
input end = 1600;
def daytime = if secondsfromTime(start) >= 0 and secondstillTime(end) > 0 then 1 else 0;

def getgg = getaggregationPeriod();
def getaggmin = round(getgg/60,0);

addlabel(0,getaggmin);

# test if agg time is > than chart time
def aggok = if getaggmin <= orb_min then 1 else 0;


def durationsec = per * 60;
def secondspassed = secondsfromTime(start);
#  simulated firstbar , based on orb time
def firstbar = if secondspassed >= 0 and secondspassed < durationsec then 1 else 0;
#addchartbubble(yes,low,per + "__" + firstbar + "__" + agg);
def afterfirst = if ( daytime and !firstbar ) then 1 else 0;

# is this the first bar after open ?
def openbar = if secondspassed >= 0 and secondspassed <= getgg then 1 else 0;

def ehi = high(period = orb_time);
def elo = low(period = orb_time);

#  looks at firstbar ,  which is orbtime ,  NOT bar[1]
def perhigh = if !daytime then na else if firstbar then ehi else perhigh[1];
def perlow = if !daytime then na else if firstbar then elo else perlow[1];

# .....................................................


addlabel(1, " ", color.Yellow);
addlabel((close > perhigh),"Price Above ORB", color.green);
addlabel((close < perlow),"Price Below ORB", color.red);
addlabel((close <= perhigh and close >= perlow),"Price Inside ORB", color.yellow);
addlabel(1, " ", color.Yellow);

# .....................................................

# plot dots for first bar timeframe
plot hidots = if firstbar then perhigh else na;
plot lodots = if firstbar then perlow else na;
hidots.setpaintingStrategy(paintingStrategy.Dashes);
lodots.setpaintingStrategy(paintingStrategy.Dashes);
hidots.setDefaultColor(color.yellow);
lodots.setDefaultColor(color.yellow);


# plot line after first bar 
plot hiline = if !firstbar then perhigh else na;
plot loline = if !firstbar then perlow else na;
hiline.setpaintingStrategy(paintingStrategy.LINE);
loline.setpaintingStrategy(paintingStrategy.LINE);
hiline.setDefaultColor(color.yellow);
loline.setDefaultColor(color.yellow);

#DefineGlobalColor("orb",color.magenta);
#DefineGlobalColor("orb_after",color.gray);
DefineGlobalColor("orb",color.red);
DefineGlobalColor("orb_after",color.green);

plot static = hiline;
static.AssignValueColor(Color.Yellow);

def limit = !IsNaN(close) and IsNaN(close [-1] ) && LowestAll(BarNumber());

AddChartBubble(limit, static, "ORB 15Hi", Color.dark_green);


plot static2 = loline;
static2.AssignValueColor(Color.Yellow);

def limit2 = !IsNaN(close) and IsNaN(close [-1] ) && LowestAll(BarNumber());

AddChartBubble(limit2, static2, "ORB 15Lo", Color.light_red);
 
Last edited by a moderator:
I tried to move the bubbles on the ORB code which is pasted below but then the code does not work. can anyone post how to incorporate the bubble shift
https://usethinkscript.com/threads/bubblemover-code-snippet-for-thinkorswim.9392/
a few spaces to the right for the following code. if the price is near the ORB hi or lo the bubble overlaps on to of the candle and if you are doing multi time frame with 1, 5 and 15 orb, (three indicators) the labels do not overlap but are stacked and takes up a lot of real estate on the chart. if it can be shifted 2 bars to the right, it would be very helpful. thanks.
Code:
#orb_colors_03
#Mobius original
#csricksdds  2/20
#I like your ORB indicator with the labels that show when above/below...so that the labels don't show only when above/below can you add one showing Yellow "Trading within ORB" when it's trading within?
#Thanks to halcyonguy I have made a few changes to suit myself.
#https://usethinkscript.com/threads/shaded-opening-range-no-breakout.17922/
#Shaded Opening Range (No Breakout)
# 2020-01
# halcyonguy
#Revamped by C. Ricks 2/12/24
def na = Double.NaN;

# pick an agg time
input orb_time = AggregationPeriod.fifteen_min;
def orb_min = orb_time/60000;
def per = orb_min;

input show_ORB_label = yes;
input show_arrows = yes;

# open/close times  (ET)
input start = 0930;
input end = 1600;
def daytime = if secondsfromTime(start) >= 0 and secondstillTime(end) > 0 then 1 else 0;

def getgg = getaggregationPeriod();
def getaggmin = round(getgg/60,0);

addlabel(0,getaggmin);

# test if agg time is > than chart time
def aggok = if getaggmin <= orb_min then 1 else 0;


def durationsec = per * 60;
def secondspassed = secondsfromTime(start);
#  simulated firstbar , based on orb time
def firstbar = if secondspassed >= 0 and secondspassed < durationsec then 1 else 0;
#addchartbubble(yes,low,per + "__" + firstbar + "__" + agg);
def afterfirst = if ( daytime and !firstbar ) then 1 else 0;

# is this the first bar after open ?
def openbar = if secondspassed >= 0 and secondspassed <= getgg then 1 else 0;

def ehi = high(period = orb_time);
def elo = low(period = orb_time);

#  looks at firstbar ,  which is orbtime ,  NOT bar[1]
def perhigh = if !daytime then na else if firstbar then ehi else perhigh[1];
def perlow = if !daytime then na else if firstbar then elo else perlow[1];

# .....................................................


addlabel(1, " ", color.Yellow);
addlabel((close > perhigh),"Price Above ORB", color.green);
addlabel((close < perlow),"Price Below ORB", color.red);
addlabel((close <= perhigh and close >= perlow),"Price Inside ORB", color.yellow);
addlabel(1, " ", color.Yellow);

# .....................................................

# plot dots for first bar timeframe
plot hidots = if firstbar then perhigh else na;
plot lodots = if firstbar then perlow else na;
hidots.setpaintingStrategy(paintingStrategy.Dashes);
lodots.setpaintingStrategy(paintingStrategy.Dashes);
hidots.setDefaultColor(color.yellow);
lodots.setDefaultColor(color.yellow);


# plot line after first bar
plot hiline = if !firstbar then perhigh else na;
plot loline = if !firstbar then perlow else na;
hiline.setpaintingStrategy(paintingStrategy.LINE);
loline.setpaintingStrategy(paintingStrategy.LINE);
hiline.setDefaultColor(color.yellow);
loline.setDefaultColor(color.yellow);

#DefineGlobalColor("orb",color.magenta);
#DefineGlobalColor("orb_after",color.gray);
DefineGlobalColor("orb",color.red);
DefineGlobalColor("orb_after",color.green);

plot static = hiline;
static.AssignValueColor(Color.Yellow);

def limit = !IsNaN(close) and IsNaN(close [-1] ) && LowestAll(BarNumber());

AddChartBubble(limit, static, "ORB 15Hi", Color.dark_green);


plot static2 = loline;
static2.AssignValueColor(Color.Yellow);

def limit2 = !IsNaN(close) and IsNaN(close [-1] ) && LowestAll(BarNumber());

AddChartBubble(limit2, static2, "ORB 15Lo", Color.light_red);

This is the above code with a bubblemover input set at 2 that can be adjusted at the input screen.
The bubbles and labels are modified to automatically display the input orb_time chosen.

Screenshot 2024-08-23 123903.png
Code:
#orb_colors_03
#Mobius original
#csricksdds  2/20
#I like your ORB indicator with the labels that show when above/below...so that the labels don't show only when above/below can you add one showing Yellow "Trading within ORB" when it's trading within?
#Thanks to halcyonguy I have made a few changes to suit myself.
#https://usethinkscript.com/threads/shaded-opening-range-no-breakout.17922/
#Shaded Opening Range (No Breakout)
# 2020-01
# halcyonguy
#Revamped by C. Ricks 2/12/24
def na = Double.NaN;

# pick an agg time
input orb_time = AggregationPeriod.FIFTEEN_MIN;
def orb_min = orb_time / 60000;
def per = orb_min;

input show_ORB_label = yes;
input show_arrows = yes;

# open/close times  (ET)
input start = 0930;
input end = 1600;
def daytime = if SecondsFromTime(start) >= 0 and SecondsTillTime(end) > 0 then 1 else 0;

def getgg = GetAggregationPeriod();
def getaggmin = Round(getgg / 60, 0);

AddLabel(0, getaggmin);

# test if agg time is > than chart time
def aggok = if getaggmin <= orb_min then 1 else 0;


def durationsec = per * 60;
def secondspassed = SecondsFromTime(start);
#  simulated firstbar , based on orb time
def firstbar = if secondspassed >= 0 and secondspassed < durationsec then 1 else 0;
#addchartbubble(yes,low,per + "__" + firstbar + "__" + agg);
def afterfirst = if ( daytime and !firstbar ) then 1 else 0;

# is this the first bar after open ?
def openbar = if secondspassed >= 0 and secondspassed <= getgg then 1 else 0;

def ehi = high(period = orb_time);
def elo = low(period = orb_time);

#  looks at firstbar ,  which is orbtime ,  NOT bar[1]
def perhigh = if !daytime then na else if firstbar then ehi else perhigh[1];
def perlow = if !daytime then na else if firstbar then elo else perlow[1];

# .....................................................


AddLabel(1, " ", Color.YELLOW);
AddLabel((close > perhigh), "Price Above " + (orb_time/getaggregationPeriod()) + " ORB", Color.GREEN);
AddLabel((close < perlow), "Price Below " + (orb_time/getaggregationPeriod()) + " ORB", Color.RED);
AddLabel((close <= perhigh and close >= perlow), "Price Inside " + (orb_time/getaggregationPeriod()) + " ORB", Color.YELLOW);
AddLabel(1, " ", Color.YELLOW);

# .....................................................

# plot dots for first bar timeframe
plot hidots = if firstbar then perhigh else na;
plot lodots = if firstbar then perlow else na;
hidots.SetPaintingStrategy(PaintingStrategy.DASHES);
lodots.SetPaintingStrategy(PaintingStrategy.DASHES);
hidots.SetDefaultColor(Color.YELLOW);
lodots.SetDefaultColor(Color.YELLOW);


# plot line after first bar
plot hiline = if !firstbar then perhigh else na;
plot loline = if !firstbar then perlow else na;
hiline.SetPaintingStrategy(PaintingStrategy.LINE);
loline.SetPaintingStrategy(PaintingStrategy.LINE);
hiline.SetDefaultColor(Color.YELLOW);
loline.SetDefaultColor(Color.YELLOW);

#DefineGlobalColor("orb",color.magenta);
#DefineGlobalColor("orb_after",color.gray);
DefineGlobalColor("orb", Color.RED);
DefineGlobalColor("orb_after", Color.GREEN);

plot static = hiline;
static.AssignValueColor(Color.YELLOW);

input bubblemover = 2;
def b = bubblemover;
def b1 = b + 1;
def limit = !IsNaN(close[b1]) and IsNaN(close [b] ) ;#&& LowestAll(BarNumber());

AddChartBubble(limit, static[b], "ORB" + (orb_time/getaggregationPeriod()) + "Hi", Color.DARK_GREEN);


plot static2 = loline;
static2.AssignValueColor(Color.YELLOW);

def limit2 = !IsNaN(close[b1]) and IsNaN(close [b] ); # && LowestAll(BarNumber());

AddChartBubble(limit2, static2[b], "ORB " + (orb_time/getaggregationPeriod()) + "Lo", Color.light_red);

#
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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