Opening Range Breakout Indicator for ThinkorSwim

There were just pieces of missing code. The bubbles were already fixed in your code.
It's weird.

I have one additional request for this script which is having the choice of showing the bubbles for today only or show all.

Ruby:
# Opening_Range_Breakout Strategy with Risk and Target Lines
# Mobius
# This is V03.02.2017(B) Other versions start with V01.01.2001 Ported to TOS 06.2011
#hint: Opening Range Breakout is one of the original Floor Trader Strategies.\n Why it works: Overnight orders accumulate. Those orders being placed during the first 15 minutes of Regular Trading Hours combined with the typical high volume in the first 30 minutes of trading make this the most volatile trading period of the day. Regularly released reports during the first 30 minutes of trading add to the volatility and effect the days direction.\n Features of this study: The yellow dashed line is the Day Filter Line and is used to determin the trend direction for the day. The dominant time spent above or below this line during the Opening Range Period typically determines the days trend. Green points indicate a close at EOD above the yellow line. Red Points a close below the yellow line. Yellow points a neutral or balanced day, close Between the Opening Range Extremes and often very near the Day Filter Line. The Opening Range is plotted with a green and red dashed line. Trades can be taken when there is an open outside these range lines. Up to 10 Targets are generated using Average True Range to plot target lines. When price crosses the first target line part of the trade should be taken as Risk Off profit and a stop should be placed at the entry point ensuring a profitable trade. If price crosses further targets stops should be moved to the preceeding target until stopped or your profit target is met. Initial Risk Stops are an open below the bar's low prior to entry or the Risk Lines plotted below the Opening range Lines. When price tests the opening range lines from below for the upper line or above for the lower lines trades can be taken with a first target to the yellow line from either direction and a Risk Stop line outside the opening range at the First Target lines or a close outside the Opening Range Lines. \n FYI the color of Probable close direction points are statistically accurate between 60% and 70% of the time. Trading against the direction of the ORB's Day Filtered Direction should be considered counter trend trades.\n As of 01.03.2017 You have just under a 52% probability that a DAILY bar will close green. So a 60% to 70% probability is a nice edge.
# (B)Deletions / Additions: Deleted - Globex High / Low, Globex Volume and Averages.
# Additions: Added 5 more target lines for a total of 10 on each side of the Opening Range.
#20230601 Sleepyz - Added ONExpansion option
declare hide_on_daily;
declare once_per_bar;

input onexpansion_ORB = no;
input ORHL_Begin = 0930;
input ORHL_Start = 0935;
input EndOfFirstBar = 0935.0; #hint OrMeanE: End Mean period. Usually End of first bar.
input ORB_HL_Begin = 0930.0; #hint OrBegin: Beginning for Period of Opening Range Breakout.
input ORB_HL_Start = 1030.0; #hint OrEnd: End of Period of Opening Range Breakout.
input CloudOn_ORB = yes; #hint CloudOn: Clouds Opening Range.
input AlertOn = yes; #hint AlertOn: Alerts on cross of Opening Range.
input nAtr = 4; #hint nATR: Lenght for the ATR Risk and Target Lines.
input AtrTargetMult = 2.0; #hint ATRmult: Multiplier for the ATR calculations.
input bubble_ORB = yes;
input bubblemover_ORB = 0;
input ShowTodayOnly_ORB = { default "No","Yes"};
input MARKETOpen_ORB = 0930.0; #hint OrMeanS: Begin Mean Period. Usually Market Open EST.


###########

def rthrs = SecondsFromTime(0930) >= 0 and SecondsFromTime(1630) < 0;

###########

def h = high;
def l = low;
def c = close;
def s_orb = ShowTodayOnly_orb;
def today_ORB = if s_ORB == 0 or GetDay() == GetLastDay() and SecondsFromTime(MARKETOpen_ORB) >= 0 then 1 else 0;
def today = if s_orb == 0 or GetDay() == GetLastDay() and SecondsFromTime(ORHL_Begin) >= 0 then 1 else 0;
def na = double.nan;
def na_ORB = Double.NaN;
def ORActive = if SecondsTillTime(EndOfFirstBar) > 0 and SecondsFromTime(MARKETOpen_ORB) >= 0 then 1 else 0;
def ORActiveHL = if SecondsTillTime(ORHL_Start) > 0 and
SecondsFromTime(ORHL_Begin) >= 0 then 1 else 0;
def ORHigh = if ORHigh[1] == 0 or ORActiveHL[1] == 0 and ORActiveHL == 1 then h else if ORActiveHL and h > ORHigh[1] then h else ORHigh[1];
def ORLow = if ORLow[1] == 0 or ORActiveHL[1] == 0 and ORActiveHL == 1 then l else if ORActiveHL and l < ORLow[1] then l else ORLow[1];
def ORWidth = ORHigh - ORLow;
def ORHA = if ORActiveHL or today_ORB < 1 then na_ORB else ORHigh;
def ORLA = if ORActiveHL or today_ORB < 1 then na_ORB else ORLow;
def O = ORHA - Round(((ORHA - ORLA) / 2) / TickSize(), 0) * TickSize();
def ORActive2 = if SecondsTillTime(ORB_HL_Start) > 0 and SecondsFromTime(ORB_HL_Begin) >= 0 then 1 else 0;
def ORHigh2 = if ORHigh2[1] == 0 or ORActive2[1] == 0 and ORActive2 == 1 then h else if ORActive2 and h > ORHigh2[1] then h else ORHigh2[1];
def ORLow2 = if ORLow2[1] == 0 or ORActive2[1] == 0 and ORActive2 == 1 then l else if ORActive2 and l < ORLow2[1] then l else ORLow2[1];
def ORWidth2 = ORHigh2 - ORLow2;
def TimeLine = if SecondsTillTime(ORB_HL_Start) == 0 then 1 else 0;
def ORmeanBar = if !ORActive and ORActive[1] then BarNumber() else ORmeanBar[1];
def ORendBar = if !ORActive2 and ORActive2[1]
then BarNumber() else ORendBar[1];
def ORL = If (O == 0 , na, O);
def ORH2 = if ORActive2 or today < 1 then na else ORHigh2;

plot ORB_BAL = if rthrs and !ORActive2 and onexpansion_ORB and !ORActive[2] and !IsNaN(close) then Double.NaN else if onexpansion_ORB and BarNumber() >= HighestAll(ORmeanBar) then HighestAll(if IsNaN(c[-1]) then ORL[1] else Double.NaN) else if !onexpansion_ORB and rthrs then ORL else Double.NaN;

ORB_BAL.SetDefaultColor(Color.MAGENTA);
ORB_BAL.SetPaintingStrategy(PaintingStrategy.DASHES);
ORB_BAL.SetLineWeight(1);
ORB_BAL.HideTitle();

plot ORB_H = if rthrs and !ORActive2 and onexpansion_ORB and !ORActive[2] and !IsNaN(close) then Double.NaN else if !ShowTodayOnly_orb and !oractive2 and rthrs then ORH2[1] else if onexpansion_ORB and BarNumber() >= HighestAll(ORendBar) then HighestAll(if IsNaN(c[-1]) then ORH2[1] else Double.NaN) else if !onexpansion_ORB and rthrs then ORH2 else Double.NaN;

ORB_H.SetDefaultColor(Color.GREEN);
ORB_H.SetPaintingStrategy(PaintingStrategy.DASHES);
ORB_H.SetLineWeight(2);
ORB_H.HideTitle();

def ORL2 = if ORActive2 or today_ORB < 1 then na_ORB else ORLow2;

plot ORB_L = if rthrs and !ORActive2 and onexpansion_ORB and !ORActive[2] and !IsNaN(close) then Double.NaN else if !ShowTodayOnly_orb and !oractive2 and rthrs then ORL2[1] else if onexpansion_ORB and BarNumber() >= HighestAll(ORendBar) then HighestAll(if IsNaN(c[-1]) then ORL2[1] else Double.NaN) else if !onexpansion_ORB and rthrs then ORL2 else Double.NaN;

ORB_L.SetDefaultColor(Color.RED);
ORB_L.SetPaintingStrategy(PaintingStrategy.DASHES);
ORB_L.SetLineWeight(2);
ORB_L.HideTitle();

def RelDay = (ORL - ORL2) / (ORH2 - ORL2);
def dColor = if RelDay > .5 then 5 else if RelDay < .5 then 6 else 4;
def pos = (ORH2 - ORL2) / 10;
def mover_ORB = bubble_ORB and onexpansion_ORB and IsNaN(close[bubblemover_ORB]) and !IsNaN(close[bubblemover_ORB + 1]);

AddCloud(if CloudOn_ORB and !ORActive2 and !onexpansion_ORB and !ORActive[2] and rthrs == yes then ORL else Double.NaN, ORL2, Color.LIGHT_RED, Color.LIGHT_RED);
AddCloud(if CloudOn_ORB and !ORActive2 and !onexpansion_ORB and !ORActive[2] and rthrs == yes then ORL else Double.NaN, ORH2, Color.GREEN, Color.GREEN);

AddChartBubble(bubble_ORB and !ORActive2 and !onexpansion_ORB and !ORActive[2] and IsNaN(ORB_H[bubblemover_ORB - 1]) and !IsNaN(ORB_H[bubblemover_ORB]), ORB_H[bubblemover_ORB], "IB_H", ORB_H.TakeValueColor());
AddChartBubble(bubble_ORB and !ORActive2 and !onexpansion_ORB and !ORActive[2] and IsNaN(ORB_L[bubblemover_ORB - 1]) and !IsNaN(ORB_L[bubblemover_ORB]), ORB_L[bubblemover_ORB], "IB_L", ORB_L.TakeValueColor());
AddChartBubble(bubble_ORB and !ORActive2 and !onexpansion_ORB and !ORActive[2] and IsNaN(ORB_BAL[bubblemover_ORB - 1]) and !IsNaN(ORB_BAL[bubblemover_ORB]), ORB_BAL[bubblemover_ORB], "BAL", ORB_BAL.TakeValueColor());

#
 

Attachments

  • Screenshot 2024-03-03 at 8.18.52 AM.png
    Screenshot 2024-03-03 at 8.18.52 AM.png
    230.1 KB · Views: 90
Last edited by a moderator:

Ben's Swing Trading Strategy + Indicator

I wouldn't call this a course. My goal is zero fluff. I will jump right into my current watchlist, tell you the ThinkorSwim indicator that I'm using, and past trade setups to help you understand my swing trading strategy.

I'm Interested

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

It's weird.

I have one additional request for this script which is having the choice of showing the bubbles for today only or show all.

The new input showTodayBubblesOnly = yes; will allow you to choose.

Screenshot 2024-03-05 075525.png
Code:
# Opening_Range_Breakout Strategy with Risk and Target Lines
# Mobius
# This is V03.02.2017(B) Other versions start with V01.01.2001 Ported to TOS 06.2011
#hint: Opening Range Breakout is one of the original Floor Trader Strategies.\n Why it works: Overnight orders accumulate. Those orders being placed during the first 15 minutes of Regular Trading Hours combined with the typical high volume in the first 30 minutes of trading make this the most volatile trading period of the day. Regularly released reports during the first 30 minutes of trading add to the volatility and effect the days direction.\n Features of this study: The yellow dashed line is the Day Filter Line and is used to determin the trend direction for the day. The dominant time spent above or below this line during the Opening Range Period typically determines the days trend. Green points indicate a close at EOD above the yellow line. Red Points a close below the yellow line. Yellow points a neutral or balanced day, close Between the Opening Range Extremes and often very near the Day Filter Line. The Opening Range is plotted with a green and red dashed line. Trades can be taken when there is an open outside these range lines. Up to 10 Targets are generated using Average True Range to plot target lines. When price crosses the first target line part of the trade should be taken as Risk Off profit and a stop should be placed at the entry point ensuring a profitable trade. If price crosses further targets stops should be moved to the preceeding target until stopped or your profit target is met. Initial Risk Stops are an open below the bar's low prior to entry or the Risk Lines plotted below the Opening range Lines. When price tests the opening range lines from below for the upper line or above for the lower lines trades can be taken with a first target to the yellow line from either direction and a Risk Stop line outside the opening range at the First Target lines or a close outside the Opening Range Lines. \n FYI the color of Probable close direction points are statistically accurate between 60% and 70% of the time. Trading against the direction of the ORB's Day Filtered Direction should be considered counter trend trades.\n As of 01.03.2017 You have just under a 52% probability that a DAILY bar will close green. So a 60% to 70% probability is a nice edge.
# (B)Deletions / Additions: Deleted - Globex High / Low, Globex Volume and Averages.
# Additions: Added 5 more target lines for a total of 10 on each side of the Opening Range.
#20230601 Sleepyz - Added ONExpansion option
declare hide_on_daily;
declare once_per_bar;

input onexpansion_ORB = no;
input ORHL_Begin = 0930;
input ORHL_Start = 0935;
input EndOfFirstBar = 0935.0; #hint OrMeanE: End Mean period. Usually End of first bar.
input ORB_HL_Begin = 0930.0; #hint OrBegin: Beginning for Period of Opening Range Breakout.
input ORB_HL_Start = 1030.0; #hint OrEnd: End of Period of Opening Range Breakout.
input CloudOn_ORB = yes; #hint CloudOn: Clouds Opening Range.
input AlertOn = yes; #hint AlertOn: Alerts on cross of Opening Range.
input nAtr = 4; #hint nATR: Lenght for the ATR Risk and Target Lines.
input AtrTargetMult = 2.0; #hint ATRmult: Multiplier for the ATR calculations.
input bubble_ORB = yes;
input bubblemover_ORB = 0;
input showTodayBubblesOnly = yes;
input ShowTodayOnly_ORB = { default "No","Yes"};
input MARKETOpen_ORB = 0930.0; #hint OrMeanS: Begin Mean Period. Usually Market Open EST.


###########

def rthrs = SecondsFromTime(0930) >= 0 and SecondsFromTime(1630) < 0;

###########

def h = high;
def l = low;
def c = close;
def s_orb = ShowTodayOnly_orb;
def today_ORB = if s_ORB == 0 or GetDay() == GetLastDay() and SecondsFromTime(MARKETOpen_ORB) >= 0 then 1 else 0;
def today = if s_orb == 0 or GetDay() == GetLastDay() and SecondsFromTime(ORHL_Begin) >= 0 then 1 else 0;
def na = double.nan;
def na_ORB = Double.NaN;
def ORActive = if SecondsTillTime(EndOfFirstBar) > 0 and SecondsFromTime(MARKETOpen_ORB) >= 0 then 1 else 0;
def ORActiveHL = if SecondsTillTime(ORHL_Start) > 0 and
SecondsFromTime(ORHL_Begin) >= 0 then 1 else 0;
def ORHigh = if ORHigh[1] == 0 or ORActiveHL[1] == 0 and ORActiveHL == 1 then h else if ORActiveHL and h > ORHigh[1] then h else ORHigh[1];
def ORLow = if ORLow[1] == 0 or ORActiveHL[1] == 0 and ORActiveHL == 1 then l else if ORActiveHL and l < ORLow[1] then l else ORLow[1];
def ORWidth = ORHigh - ORLow;
def ORHA = if ORActiveHL or today_ORB < 1 then na_ORB else ORHigh;
def ORLA = if ORActiveHL or today_ORB < 1 then na_ORB else ORLow;
def O = ORHA - Round(((ORHA - ORLA) / 2) / TickSize(), 0) * TickSize();
def ORActive2 = if SecondsTillTime(ORB_HL_Start) > 0 and SecondsFromTime(ORB_HL_Begin) >= 0 then 1 else 0;
def ORHigh2 = if ORHigh2[1] == 0 or ORActive2[1] == 0 and ORActive2 == 1 then h else if ORActive2 and h > ORHigh2[1] then h else ORHigh2[1];
def ORLow2 = if ORLow2[1] == 0 or ORActive2[1] == 0 and ORActive2 == 1 then l else if ORActive2 and l < ORLow2[1] then l else ORLow2[1];
def ORWidth2 = ORHigh2 - ORLow2;
def TimeLine = if SecondsTillTime(ORB_HL_Start) == 0 then 1 else 0;
def ORmeanBar = if !ORActive and ORActive[1] then BarNumber() else ORmeanBar[1];
def ORendBar = if !ORActive2 and ORActive2[1]
then BarNumber() else ORendBar[1];
def ORL = If (O == 0 , na, O);
def ORH2 = if ORActive2 or today < 1 then na else ORHigh2;

plot ORB_BAL = if rthrs and !ORActive2 and onexpansion_ORB and !ORActive[2] and !IsNaN(close) then Double.NaN else if onexpansion_ORB and BarNumber() >= HighestAll(ORmeanBar) then HighestAll(if IsNaN(c[-1]) then ORL[1] else Double.NaN) else if !onexpansion_ORB and rthrs then ORL else Double.NaN;

ORB_BAL.SetDefaultColor(Color.MAGENTA);
ORB_BAL.SetPaintingStrategy(PaintingStrategy.DASHES);
ORB_BAL.SetLineWeight(1);
ORB_BAL.HideTitle();

plot ORB_H = if rthrs and !ORActive2 and onexpansion_ORB and !ORActive[2] and !IsNaN(close) then Double.NaN else if !ShowTodayOnly_orb and !oractive2 and rthrs then ORH2[1] else if onexpansion_ORB and BarNumber() >= HighestAll(ORendBar) then HighestAll(if IsNaN(c[-1]) then ORH2[1] else Double.NaN) else if !onexpansion_ORB and rthrs then ORH2 else Double.NaN;

ORB_H.SetDefaultColor(Color.GREEN);
ORB_H.SetPaintingStrategy(PaintingStrategy.DASHES);
ORB_H.SetLineWeight(2);
ORB_H.HideTitle();

def ORL2 = if ORActive2 or today_ORB < 1 then na_ORB else ORLow2;

plot ORB_L = if rthrs and !ORActive2 and onexpansion_ORB and !ORActive[2] and !IsNaN(close) then Double.NaN else if !ShowTodayOnly_orb and !oractive2 and rthrs then ORL2[1] else if onexpansion_ORB and BarNumber() >= HighestAll(ORendBar) then HighestAll(if IsNaN(c[-1]) then ORL2[1] else Double.NaN) else if !onexpansion_ORB and rthrs then ORL2 else Double.NaN;

ORB_L.SetDefaultColor(Color.RED);
ORB_L.SetPaintingStrategy(PaintingStrategy.DASHES);
ORB_L.SetLineWeight(2);
ORB_L.HideTitle();

def RelDay = (ORL - ORL2) / (ORH2 - ORL2);
def dColor = if RelDay > .5 then 5 else if RelDay < .5 then 6 else 4;
def pos = (ORH2 - ORL2) / 10;
def mover_ORB = bubble_ORB and onexpansion_ORB and IsNaN(close[bubblemover_ORB]) and !IsNaN(close[bubblemover_ORB + 1]);

AddCloud(if CloudOn_ORB and !ORActive2 and !onexpansion_ORB and !ORActive[2] and rthrs == yes then ORL else Double.NaN, ORL2, Color.LIGHT_RED, Color.LIGHT_RED);
AddCloud(if CloudOn_ORB and !ORActive2 and !onexpansion_ORB and !ORActive[2] and rthrs == yes then ORL else Double.NaN, ORH2, Color.GREEN, Color.GREEN);



AddChartBubble(if showtodayBubblesonly and getday()!=getlastday() then double.nan else bubble_ORB and !ORActive2 and !onexpansion_ORB and !ORActive[2] and IsNaN(ORB_H[bubblemover_ORB - 1]) and !IsNaN(ORB_H[bubblemover_ORB]), ORB_H[bubblemover_ORB], "IB_H", ORB_H.TakeValueColor());
AddChartBubble(if showtodayBubblesonly and getday()!=getlastday() then double.nan else bubble_ORB and !ORActive2 and !onexpansion_ORB and !ORActive[2] and IsNaN(ORB_L[bubblemover_ORB - 1]) and !IsNaN(ORB_L[bubblemover_ORB]), ORB_L[bubblemover_ORB], "IB_L", ORB_L.TakeValueColor());
AddChartBubble(if showtodayBubblesonly and getday()!=getlastday() then double.nan else bubble_ORB and !ORActive2 and !onexpansion_ORB and !ORActive[2] and IsNaN(ORB_BAL[bubblemover_ORB - 1]) and !IsNaN(ORB_BAL[bubblemover_ORB]), ORB_BAL[bubblemover_ORB], "BAL", ORB_BAL.TakeValueColor());

#
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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