Opening Range Breakout Indicator for ThinkorSwim

I'm wondering if someone might be able to help me add two lines to the above ORB study (Shareable Link: https://tos.mx/qu3Cu0).

I've been trying to figure it out, but not quite getting it.

Line 1: a line exactly like ORH2ext, but instead of the highest high of the opening range...
- Have it find the highest open or highest close (use whichever value is higher)

Line 2: a line exactly like ORL2ext, but instead of the lowest low of the opening range...
- Have it find the lowest open or lowest close (use whichever value is lower)

I feel like it might just be a couple additional lines of code, but cannot quite get it right.

Thanks to anyone who can assist here!

The White Dashed line is Highest OR c/o and Magenta is Lowest OR c/o.

Screenshot-2022-12-09-162302.png

# 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 = yes;
input OrMeanS = 0930.0; #hint OrMeanS: Begin Mean Period. Usually Market Open EST.
input OrMeanE = 0935.0; #hint OrMeanE: End Mean period. Usually End of first bar.
input OrBegin = 0930.0; #hint OrBegin: Beginning for Period of Opening Range Breakout.
input OrEnd = 1000.0; #hint OrEnd: End of Period of Opening Range Breakout.
input CloudOn = no; #hint CloudOn: Clouds Opening Range.
input AlertOn = yes; #hint AlertOn: Alerts on cross of Opening Range.
input ShowTodayOnly = {"No", default "Yes"};
input nAtr = 4; #hint nATR: Lenght for the ATR Risk and Target Lines.
input AtrTargetMult = 2.0; #hint ATRmult: Multiplier for the ATR calculations.

def h = high;
def l = low;
def c = close;

def bar = BarNumber();
def s = ShowTodayOnly;
def ORActive = if SecondsTillTime(OrMeanE) > 0 and
SecondsFromTime(OrMeanS) >= 0
then 1
else 0;
def today = if s == 0
or GetDay() == GetLastDay() and
SecondsFromTime(OrMeanS) >= 0
then 1
else 0;
def ORHigh = if ORHigh[1] == 0
or ORActive[1] == 0 and
ORActive == 1
then h
else if ORActive and
h > ORHigh[1]
then h
else ORHigh[1];
def ORLow = if ORLow[1] == 0
or ORActive[1] == 0 and
ORActive == 1
then l
else if ORActive and
l < ORLow[1]
then l
else ORLow[1];
def ORWidth = ORHigh - ORLow;
def na = Double.NaN;
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 - Round(((ORHA - ORLA) / 2) / TickSize(), 0) * TickSize();
def ORActive2 = if SecondsTillTime(OrEnd) > 0 and
SecondsFromTime(OrBegin) >= 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(OrEnd) == 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);
plot ORLext = if onexpansion and !isnan(close) then double.nan
else if BarNumber() >= HighestAll(ORmeanBar)
then HighestAll(if IsNaN(c[-1])
then ORL[1]
else Double.NaN)
else Double.NaN;
ORLext.SetDefaultColor(Color.YELLOW);
ORLext.SetStyle(Curve.LONG_DASH);
ORLext.SetLineWeight(3);
ORLext.HideTitle();
def ORH2 = if ORActive2
or today < 1
then na
else ORHigh2;

plot ORH2ext = if onexpansion and !isnan(close) then double.nan
else if !ShowTodayOnly
then
ORH2[1]
else if BarNumber() >= HighestAll(ORendBar)
then HighestAll(if IsNaN(c[-1])
then ORH2[1]
else Double.NaN)
else Double.NaN;
ORH2ext.SetDefaultColor(Color.GREEN);
ORH2ext.SetStyle(Curve.LONG_DASH);
ORH2ext.SetLineWeight(3);
ORH2ext.HideTitle();
def ORL2 = if ORActive2
or today < 1
then na
else ORLow2;
plot ORL2ext = if onexpansion and !isnan(close) then double.nan
else if !ShowTodayOnly
then
ORL2[1]
else if BarNumber() >= HighestAll(ORendBar)
then HighestAll(if IsNaN(c[-1])
then ORL2[1]
else Double.NaN)
else Double.NaN;
ORL2ext.SetDefaultColor(Color.RED);
ORL2ext.SetStyle(Curve.LONG_DASH);
ORL2ext.SetLineWeight(3);
ORL2ext.HideTitle();

def ORcHi = if ORcHi[1] == 0
or ORActive2[1] == 0 and
ORActive2 == 1
then c
else if ORActive2 and
c > ORcHi[1]
then c
else ORcHi[1];
def ORcLo = if ORcLo[1] == 0
or ORActive2[1] == 0 and
ORActive2 == 1
then c
else if ORActive2 and
c < ORcLo[1]
then c
else ORcLo[1];

def ORoHi = if ORoHi[1] == 0
or ORActive2[1] == 0 and
ORActive2 == 1
then open
else if ORActive2 and
open > ORoHi[1]
then open
else ORoHi[1];
def ORoLo = if ORoLo[1] == 0
or ORActive2[1] == 0 and
ORActive2 == 1
then open
else if ORActive2 and
open < ORoLo[1]
then open
else ORoLo[1];

def ORHoc2 = if ORActive2
or today < 1
then na
else Max(ORcHi[1], ORoHi[1]) ;

plot ORHoc = if onexpansion and !isnan(close) then double.nan
else if !ShowTodayOnly
then ORHoc2
else if BarNumber() >= HighestAll(ORendBar)
then HighestAll(if IsNaN(c[-1])
then ORHoc2
else Double.NaN)
else Double.NaN;
ORHoc.SetDefaultColor(Color.WHITE);
ORHoc.SetStyle(Curve.LONG_DASH);
ORHoc.SetLineWeight(3);
ORHoc.HideTitle();

def ORLoc2 = if ORActive2
or today < 1
then na
else Min(ORcLo[1], ORoLo[1]) ;

plot ORLoc = if onexpansion and !isnan(close) then double.nan
else if !ShowTodayOnly
then ORLoc2
else if BarNumber() >= HighestAll(ORendBar)
then HighestAll(if IsNaN(c[-1])
then Min(ORcLo, ORoLo)
else Double.NaN)
else Double.NaN;
ORLoc.SetDefaultColor(Color.MAGENTA);
ORLoc.SetStyle(Curve.LONG_DASH);
ORLoc.SetLineWeight(3);
ORLoc.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;
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.POINTS);
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.POINTS);
d1.AssignValueColor(GetColor(dColor));
d2.AssignValueColor(GetColor(dColor));
d3.AssignValueColor(GetColor(dColor));
d4.AssignValueColor(GetColor(dColor));
d5.AssignValueColor(GetColor(dColor));
d6.AssignValueColor(GetColor(dColor));
d7.AssignValueColor(GetColor(dColor));
d8.AssignValueColor(GetColor(dColor));
d9.AssignValueColor(GetColor(dColor));
d10.AssignValueColor(GetColor(dColor));
d1.HideBubble();
d2.HideBubble();
d3.HideBubble();
d4.HideBubble();
d5.HideBubble();
d6.HideBubble();
d7.HideBubble();
d8.HideBubble();
d9.HideBubble();
d10.HideBubble();
d1.HideTitle();
d2.HideTitle();
d3.HideTitle();
d4.HideTitle();
d5.HideTitle();
d6.HideTitle();
d7.HideTitle();
d8.HideTitle();
d9.HideTitle();
d10.HideTitle();
AddCloud(if CloudOn == yes
then ORL
else Double.NaN
, ORL2, CreateColor(244, 83, 66), CreateColor(244, 83, 66));
AddCloud(if CloudOn == yes
then ORL
else Double.NaN
, ORH2, CreateColor(66, 244, 131), CreateColor(66, 244, 131));
# Begin Risk Algorithm
# First Breakout or Breakdown bars
def Bubbleloc1 = IsNaN(close) and !isnan(close[1]);
def Bubbleloc2 = IsNaN(close[-1]) and !isnan(close);
def BreakoutBar = if ORActive
then Double.NaN
else if !ORActive and c crosses above ORH2
then bar
else if !IsNaN(BreakoutBar[1]) and c crosses ORH2
then BreakoutBar[1]
else BreakoutBar[1];

def ATR = if ORActive2
then Round((Average(TrueRange(h, c, l), nAtr)) / TickSize(), 0) * TickSize()
else ATR[1];
def cond1 = if h > ORH2 and
h[1] <= ORH2
then Round((ORH2 + (ATR * AtrTargetMult)) / TickSize(), 0) * TickSize()
else cond1[1];
plot ORLriskUP = if onexpansion and !isnan(close) then double.nan
else if bar >= ORendBar and !ORActive and today
then HighestAll(ORH2ext - 2)
else Double.NaN;
ORLriskUP.SetStyle(Curve.LONG_DASH);
ORLriskUP.SetDefaultColor(Color.GREEN);
ORLriskUP.HideTitle();
def crossUpBar = if close crosses above ORH2
then bar
else Double.NaN;
AddChartBubble(bar == HighestAll(crossUpBar), ORLriskUP, "Risk\nON ORH", Color.GREEN, no);
plot ORLriskDN = if onexpansion and !isnan(close) then double.nan
else if bar >= ORendBar and !ORActive and close < ORL
then HighestAll(ORL2ext + 2)
else Double.NaN;
ORLriskDN.SetStyle(Curve.LONG_DASH);
ORLriskDN.SetDefaultColor(Color.RED);
ORLriskDN.HideTitle();
def crossDnBar = if close crosses below ORL2ext
then bar
else Double.NaN;
AddChartBubble(bar == HighestAll(crossDnBar), HighestAll(ORLriskDN), "Risk\nON ORL", Color.RED, yes);

# High Targets
plot Htarget = if onexpansion and !isnan(c) then double.nan
else if bar >= highestall(breakoutbar)
then HighestAll(if isNaN(c[-1])
then cond1
else Double.NaN)
else Double.NaN;
Htarget.SetPaintingStrategy(PaintingStrategy.SQUARES);
Htarget.SetLineWeight(1);
Htarget.SetDefaultColor(Color.WHITE);
Htarget.HideTitle();
AddChartBubble(Bubbleloc1, Htarget, "RO", Color.WHITE, if c > Htarget then no else yes);

def condHtarget2 = if c crosses above cond1
then Round((cond1 + (ATR * AtrTargetMult)) / TickSize(), 0) * TickSize()
else condHtarget2[1];
plot Htarget2 = if onexpansion and !isnan(c) then double.nan
else if bar >= highestall(orendBar)
then HighestAll(if isNaN(c[-1])
then condHtarget2
else Double.NaN)
else Double.NaN;
Htarget2.SetPaintingStrategy(PaintingStrategy.SQUARES);
Htarget2.SetLineWeight(1);
Htarget2.SetDefaultColor(Color.PLUM);
Htarget2.HideTitle();
AddChartBubble(Bubbleloc1, Htarget2, "2nd T", Color.PLUM, if c > Htarget2
then no
else yes);
def condHtarget3 = if c crosses above condHtarget2
then Round((condHtarget2 + (ATR * AtrTargetMult)) / TickSize(), 0) * TickSize()
else condHtarget3[1];
plot Htarget3 = if onexpansion and !isnan(c) then double.nan
else if bar >= highestall(orendBar)
then HighestAll(if isNaN(c[-1])
then condHtarget3
else Double.NaN)
else Double.NaN;
Htarget3.SetPaintingStrategy(PaintingStrategy.SQUARES);
Htarget3.SetLineWeight(1);
Htarget3.SetDefaultColor(Color.PLUM);
Htarget3.HideTitle();
AddChartBubble(Bubbleloc1, Htarget3, "3rd T", Color.PLUM, if c > Htarget3 then no else yes);
def condHtarget4 = if c crosses above condHtarget3
then Round((condHtarget3 + (ATR * AtrTargetMult)) / TickSize(), 0) * TickSize()
else condHtarget4[1];
plot Htarget4 = if onexpansion and !isnan(c) then double.nan
else if bar >= highestall(orendBar)
then HighestAll(if isNaN(c[-1])
then condHtarget4
else Double.NaN)
else Double.NaN;
Htarget4.SetPaintingStrategy(PaintingStrategy.SQUARES);
Htarget4.SetLineWeight(1);
Htarget4.SetDefaultColor(Color.PLUM);
Htarget4.HideTitle();
AddChartBubble(Bubbleloc1, Htarget4, "4th T", Color.PLUM, if c > Htarget4 then no else yes);
def condHtarget5 = if c crosses above condHtarget4
then Round((condHtarget4 + (ATR * AtrTargetMult)) / TickSize(), 0) * TickSize()
else condHtarget5[1];
plot Htarget5 = if onexpansion and !isnan(c) then double.nan
else if bar >= highestall(orendBar)
then HighestAll(if isNaN(c[-1])
then condHtarget5
else Double.NaN)
else Double.NaN;
Htarget5.SetPaintingStrategy(PaintingStrategy.SQUARES);
Htarget5.SetLineWeight(1);
Htarget5.SetDefaultColor(Color.PLUM);
Htarget5.HideTitle();
AddChartBubble(Bubbleloc1, Htarget5, "5th T", Color.PLUM, if c > Htarget5 then no else yes);
# Low Targets
def cond2 = if l < ORL2 and
l[1] >= ORL2
then Round((ORL2 - (AtrTargetMult * ATR)) / TickSize(), 0) * TickSize()
else cond2[1];
plot Ltarget = if onexpansion and !isnan(close) then double.nan
else if bar >= HighestAll(ORendBar)
then HighestAll(if IsNaN(c[-1])
then cond2
else Double.NaN)
else Double.NaN;
Ltarget.SetPaintingStrategy(PaintingStrategy.SQUARES);
Ltarget.SetLineWeight(1);
Ltarget.SetDefaultColor(Color.WHITE);
Ltarget.HideTitle();
AddChartBubble(Bubbleloc2, cond2, "RO", Color.WHITE, if c < Ltarget
then yes
else no);
def condLtarget2 = if c crosses below cond2
then Round((cond2 - (AtrTargetMult * ATR)) / TickSize(), 0) * TickSize()
else condLtarget2[1];
plot Ltarget2 = if onexpansion and !isnan(close) then double.nan
else if bar >= HighestAll(ORendBar)
then HighestAll(if IsNaN(c[-1])
then condLtarget2
else Double.NaN)
else Double.NaN;
Ltarget2.SetPaintingStrategy(PaintingStrategy.SQUARES);
Ltarget2.SetLineWeight(1);
Ltarget2.SetDefaultColor(Color.PLUM);
Ltarget2.HideTitle();
AddChartBubble(Bubbleloc2, condLtarget2, "2nd T", Color.PLUM, if c < condLtarget2
then yes
else no);
def condLtarget3 = if c crosses below condLtarget2
then Round((condLtarget2 - (AtrTargetMult * ATR)) / TickSize(), 0) * TickSize()
else condLtarget3[1];
plot Ltarget3 = if onexpansion and !isnan(close) then double.nan
else if bar >= HighestAll(ORendBar)
then HighestAll(if IsNaN(c[-1])
then condLtarget3
else Double.NaN)
else Double.NaN;
Ltarget3.SetPaintingStrategy(PaintingStrategy.SQUARES);
Ltarget3.SetLineWeight(1);
Ltarget3.SetDefaultColor(Color.PLUM);
Ltarget3.HideTitle();
AddChartBubble(Bubbleloc2, condLtarget3, "3rd T", Color.PLUM, if c < Ltarget3
then yes
else no);
def condLtarget4 = if c crosses condLtarget3
then Round((condLtarget3 - (AtrTargetMult * ATR)) / TickSize(), 0) * TickSize()
else condLtarget4[1];
plot Ltarget4 = if onexpansion and !isnan(close) then double.nan
else if bar >= HighestAll(ORendBar)
then HighestAll(if IsNaN(c[-1])
then condLtarget4
else Double.NaN)
else Double.NaN;
Ltarget4.SetPaintingStrategy(PaintingStrategy.SQUARES);
Ltarget4.SetLineWeight(1);
Ltarget4.SetDefaultColor(Color.PLUM);
Ltarget4.HideTitle();
AddChartBubble(Bubbleloc2, condLtarget4, "4th T", Color.PLUM, if c < Ltarget4
then yes
else no);
def condLtarget5 = if c crosses condLtarget4
then Round((condLtarget4 - (AtrTargetMult * ATR)) / TickSize(), 0) * TickSize()
else condLtarget5[1];
plot Ltarget5 = if onexpansion and !isnan(close) then double.nan
else if bar >= HighestAll(ORendBar)
then HighestAll(if IsNaN(c[-1])
then condLtarget5
else Double.NaN)
else Double.NaN;
Ltarget5.SetPaintingStrategy(PaintingStrategy.SQUARES);
Ltarget5.SetLineWeight(1);
Ltarget5.SetDefaultColor(Color.PLUM);
Ltarget5.HideTitle();
AddChartBubble(Bubbleloc2, condLtarget5, "5th T", Color.PLUM, if c < Ltarget5
then yes
else no);
def last = if SecondsTillTime(1600) == 0 and
SecondsFromTime(1600) == 0
then c[1]
else last[1];
plot LastClose = if onexpansion and !isnan(close) then double.nan
else if today and last != 0
then last
else Double.NaN;
LastClose.SetPaintingStrategy(PaintingStrategy.DASHES);
LastClose.SetDefaultColor(Color.WHITE);
LastClose.HideBubble();
LastClose.HideTitle();
AddChartBubble(SecondsTillTime(0930) == 0, LastClose, "PC", Color.GRAY, yes);
Alert(c crosses above ORH2, "", Alert.BAR, Sound.Bell);
Alert(c crosses below ORL2, "", Alert.BAR, Sound.Ring);
# End Code ORB with Risk and targets
 
Last edited:

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

The White Dashed line is Highest OR c/o and Magenta is Lowest OR c/o.
YES!!!!!!!!
Thank you so very much. That's exactly what I was trying to do.

Some very smart people in here. :)


My only other question would be - is there a way to make those lines show on previous days?

I switched 'Show Today Only' in the settings to NO, but it still just shows for only the current day's session.

Not sure if I just did something wrong in the settings.
 
Last edited:
YES!!!!!!!!
Thank you so very much. That's exactly what I was trying to do.

Some very smart people in here. :)


My only other question would be - is there a way to make those lines show on previous days?

I switched 'Show Today Only' in the settings to NO, but it still just shows for only the current day's session.

Not sure if I just did something wrong in the settings.

The code that you referenced and which was modified to add your request did not work for any of the OR plots for the showtodayonly option. I have modified the code to now do that and it is replaced in https://usethinkscript.com/threads/opening-range-breakout-indicator-for-thinkorswim.16/post-113995

 
Whenever I use this study, I wish that it would only extend the lines from the beginning of the day til the end of the day midnight to midnight would be perfect. As of now, the lines go for eternity, and it is very bothersome. I would appreciate it if someone could take a look at this! Thanks in the advance, team.

Code:
#Opening Range

#Define Market time and variables for ORHigh and ORLow
input opentime = 930;
input endtime = 1100;
def na = Double.NaN;

#check if the Opening Range time is now 
def ORActive = if GetLastDay() == GetDay() and
SecondsFromTime(opentime) >= 0 and
SecondsFromTime(endtime) < 0  
then 1 else 0; 

# Track the Opening Range high and low if Opening Range is active 
def OpenHigh = if ORActive then high else na;
def OpenLow = if ORActive then low else na; 

# Def the Opening Range high and low 
def OpenH = if GetLastDay() != GetDay() or !ORActive then na else HighestAll(OpenHigh);
def OpenL = if GetLastDay() != GetDay() or !ORActive then na else LowestAll(OpenLow); 

#Defines
def Today = GetDay() == GetLastDay();
def agg = AggregationPeriod.DAY;
def x_b = Today[0];

plot OpenHi = HighestAll(OpenHigh);
OpenHi.SetDefaultColor(Color.BLUE);

plot OpenLo = LowestAll(OpenLow);
OpenLo.SetDefaultColor(Color.BLUE);
 
I tried making a strategy where you enter trade when price closes over breakout and exit on first RO, with stoploss at opposite breakout level but past days don't show RO levels, so it's not a good backtester. I'll keep trying..
 
Last edited:
Could someone create a backtest for this? Or strategy that can be used to see profit/loss? Like enter trade when price closes over breakout and exit on first RO, with stoploss at opposite breakout level?

There is one but with filters https://usethinkscript.com/threads/...y-with-market-volatility-for-thinkorswim.164/

I imagine the backtesting script is relatively easy to set up unless you want to narrow down and add additional stoploss levels and entry criteria.
 
Last edited by a moderator:
Last edited by a moderator:
https://usethinkscript.com/threads/opening-range-breakout-indicator-for-thinkorswim.16/
Mobius' ORB Bubble Location is written like this: def Bubbleloc1 = isNaN(close[-1]);
The alert is: alert(c crosses above ORH2,

Is there a way to add a second bubble that will appear AT the candle where it occurred and remain there?
This kinda works: def Bubbleloc2 = (c crosses above ORH2);
... except it appears on every candle.

Thanks!

This will place a bubble at each cross and remain there

Code:
addchartBubble(c crosses below ORL2, ORL2, "Cross below", color.red, yes);
addchartBubble(c crosses above ORH2, ORH2, "Cross above", color.green, no);
 
Recently came across this cool indicator called Opening Range Breakout by Mobius. This is more than just an indicator. There is also a strategy with risk and target lines included.



thinkScript Code

After adding the indicator, I couldn't quite understand it much. From looking at it, seems more like a support and resistance indicator to me. I watched a few YouTube videos about the Opening Range Breakout and was able to make some changes to the current code. As a result, I was able to have a clear picture of what this indicator does.

Here is my own version of it:

Rich (BB code):
declare Hide_On_Daily;
declare Once_per_bar;

input OrMeanS  = 0930.0; #hint OrMeanS: Begin Mean Period. Usually Market Open EST.
input OrMeanE  = 0935.0; #hint OrMeanE: End Mean period. Usually End of first bar.
input OrBegin  = 0930.0; #hint OrBegin: Beginning for Period of Opening Range Breakout.
input OrEnd    = 1000.0; #hint OrEnd: End of Period of Opening Range Breakout.
input CloudOn  = no;     #hint CloudOn: Clouds Opening Range.
input AlertOn  = yes;    #hint AlertOn: Alerts on cross of Opening Range.
input ShowTodayOnly = {"No", default "Yes"}; 
input nAtr = 4;          #hint nATR: Lenght for the ATR Risk and Target Lines.
input AtrTargetMult = 2.0; #hint ATRmult: Multiplier for the ATR calculations.

  def h = high;
  def l = low;
  def c = close;
  def bar = barNumber();
  def s = ShowTodayOnly;
  def ORActive = if secondsTillTime(OrMeanE) > 0 and
                    secondsFromTime(OrMeanS) >= 0
                 then 1
                 else 0;
  def today = if s == 0
              or getDay() == getLastDay() and
                 secondsFromTime(OrMeanS) >= 0
              then 1
              else 0;
  def ORHigh = if ORHigh[1] == 0
               or ORActive[1] == 0 and
                  ORActive == 1
               then h
               else if ORActive and
                       h > ORHigh[1]
               then h
               else ORHigh[1];
  def ORLow = if ORLow[1] == 0
              or ORActive[1] == 0 and
                 ORActive == 1
              then l
              else if ORActive and
                      l < ORLow[1]
              then l
              else ORLow[1];
  def ORWidth = ORHigh - ORLow;
  def na = double.nan;
  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 - Round(((ORHA - ORLA) / 2) / TickSize(), 0) * TickSize();
  def ORActive2 = if secondsTillTime(OREnd) > 0 and
                     secondsFromTime(ORBegin) >= 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(OREnd) == 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);
plot ORLext = if barNumber() >= highestAll(ORmeanBar)
              then HighestAll(if isNaN(c[-1])
                              then ORL[1]
                              else double.nan)
              else double.nan;
     ORLext.SetDefaultColor(color.Yellow);
     ORLext.SetStyle(curve.Long_DASH);
     ORLext.SetLineWeight(3);
     ORLext.HideTitle();
  def ORH2 = if ORActive2
             or today < 1
             then na
             else ORHigh2;
plot ORH2ext = if barNumber() >= highestAll(ORendBar)
               then HighestAll(if isNaN(c[-1])
                               then ORH2[1]
                               else double.nan)
               else double.nan;
     ORH2ext.SetDefaultColor(color.Green);
     ORH2ext.SetStyle(curve.Long_DASH);
     ORH2ext.SetLineWeight(3);
     ORH2ext.HideTitle();
  def ORL2 = if ORActive2
               or today < 1
             then na
             else ORLow2;
plot ORL2ext = if barNumber() >= highestAll(ORendBar)
               then HighestAll(if isNaN(c[-1])
                               then ORL2[1]
                               else double.nan)
               else double.nan;
     ORL2ext.SetDefaultColor(color.Red);
     ORL2ext.SetStyle(curve.Long_DASH);
     ORL2ext.SetLineWeight(3);
     ORL2ext.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;
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.POINTS);
     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.POINTS);
     d1.AssignValueColor(GetColor(Dcolor));
     d2.AssignValueColor(GetColor(Dcolor));
     d3.AssignValueColor(GetColor(Dcolor));
     d4.AssignValueColor(GetColor(Dcolor));
     d5.AssignValueColor(GetColor(Dcolor));
     d6.AssignValueColor(GetColor(Dcolor));
     d7.AssignValueColor(GetColor(Dcolor));
     d8.AssignValueColor(GetColor(Dcolor));
     d9.AssignValueColor(GetColor(Dcolor));
    d10.AssignValueColor(GetColor(Dcolor));
     d1.HideBubble();
     d2.HideBubble();
     d3.HideBubble();
     d4.HideBubble();
     d5.HideBubble();
     d6.HideBubble();
     d7.HideBubble();
     d8.HideBubble();
     d9.HideBubble();
    d10.HideBubble();
     d1.HideTitle();
     d2.HideTitle();
     d3.HideTitle();
     d4.HideTitle();
     d5.HideTitle();
     d6.HideTitle();
     d7.HideTitle();
     d8.HideTitle();
     d9.HideTitle();
    d10.HideTitle();
addCloud(if CloudOn == yes
         then orl
         else double.nan
       , orl2,createColor(244,83,66), createColor(244,83,66));
addCloud(if CloudOn == yes
         then orl
         else double.nan
       , orh2,createColor(66,244,131), createColor(66,244,131));
# Begin Risk Algorithm
# First Breakout or Breakdown bars
  def Bubbleloc1 = isNaN(close[-1]);
  def BreakoutBar = if ORActive
                    then double.nan
                    else if !ORActive and c crosses above ORH2
                         then bar
                         else if !isNaN(BreakoutBar[1]) and c crosses ORH2
                              then BreakoutBar[1]
                    else BreakoutBar[1];
  def ATR = if ORActive2
  then Round((Average(TrueRange(h, c, l), nATR)) / TickSize(), 0) * TickSize()
  else ATR[1];
  def cond1 =  if h > ORH2 and
                  h[1] <= ORH2
               then Round((ORH2  + (ATR * AtrTargetMult)) / TickSize(), 0) * TickSize()
               else cond1[1];
plot ORLriskUP = if bar >= OREndBar and !ORActive and today
                 then HighestAll(ORH2ext - 2)
                 else double.nan;
     ORLriskUP.SetStyle(Curve.Long_Dash);
     ORLriskUP.SetDefaultColor(Color.Green);
     ORLriskUP.HideTitle();
  def crossUpBar = if close crosses above ORH2
                   then bar
                   else double.nan;
AddChartBubble(bar == HighestAll(crossUpBar), ORLriskUP, "RiskON ORH", color.green, no);
plot ORLriskDN = if bar >= OREndBar and !ORActive and close < ORL
                 then HighestAll(ORL2ext + 2)
                 else double.nan;
     ORLriskDN.SetStyle(Curve.Long_Dash);
     ORLriskDN.SetDefaultColor(Color.Red);
     ORLriskDN.HideTitle();
  def crossDnBar = if close crosses below ORL2ext
                   then bar
                   else double.nan;
AddChartBubble(bar == HighestAll(crossDnBar), HighestAll(ORLriskDN), "Risk ON ORL", color.red, yes);
# High Targets
plot Htarget = if bar >= BreakoutBar
               then cond1
               else double.nan;
     Htarget.SetPaintingStrategy(paintingStrategy.Squares);
     Htarget.SetLineWeight(1);
     Htarget.SetDefaultColor(Color.White);
     Htarget.HideTitle();
AddChartBubble(BubbleLoc1, Htarget, "RO", color.white, if c > Htarget then no else yes);
  def condHtarget2 = if c crosses above cond1
  then Round((cond1 + (ATR * AtrTargetMult)) / TickSize(), 0) * TickSize()
  else condHtarget2[1];
plot Htarget2 = if bar >= BreakoutBar
                then  condHtarget2
                else double.nan;
     Htarget2.SetPaintingStrategy(PaintingStrategy.Squares);
     Htarget2.SetLineWeight(1);
     Htarget2.SetDefaultColor(Color.Plum);
     Htarget2.HideTitle();
AddChartBubble(BubbleLoc1, Htarget2, "2nd T", color.plum, if c > Htarget2
                                                          then no
                                                          else yes);
  def condHtarget3 = if c crosses above condHtarget2
  then Round((condHtarget2 + (ATR * AtrTargetMult)) / TickSize(), 0) * TickSize()
  else condHtarget3[1];
plot Htarget3 = if bar >= BreakoutBar
                then condHtarget3
                else double.nan;
     Htarget3.SetPaintingStrategy(PaintingStrategy.Squares);
     Htarget3.SetLineWeight(1);
     Htarget3.SetDefaultColor(Color.Plum);
     Htarget3.HideTitle();
AddChartBubble(isNaN(C[-1]), Htarget3, "3rd T", color.plum, if c > Htarget3 then no else yes);
  def condHtarget4 = if c crosses above condHtarget3
  then Round((condHtarget3 + (ATR * AtrTargetMult)) / TickSize(), 0) * TickSize()
  else condHtarget4[1];
plot Htarget4 = if bar >= HighestAll(BreakoutBar)
                then condHtarget4
                else double.nan;
     Htarget4.SetPaintingStrategy(PaintingStrategy.Squares);
     Htarget4.SetLineWeight(1);
     Htarget4.SetDefaultColor(Color.Plum);
     Htarget4.HideTitle();
AddChartBubble(BubbleLoc1, Htarget4, "4th T", color.plum, if c > Htarget4 then no else yes);
  def condHtarget5 = if c crosses above condHtarget4
  then Round((condHtarget4 + (ATR * AtrTargetMult)) / TickSize(), 0) * TickSize()
  else condHtarget5[1];
plot Htarget5 = if bar >= BreakoutBar
                then condHtarget5
                else double.nan;
     Htarget5.SetPaintingStrategy(PaintingStrategy.Squares);
     Htarget5.SetLineWeight(1);
     Htarget5.SetDefaultColor(Color.Plum);
     Htarget5.HideTitle();
AddChartBubble(BubbleLoc1, Htarget5, "5th T", color.plum, if c > Htarget5 then no else yes);
# Low Targets
  def cond2 = if L < ORL2 and
                 L[1] >= ORL2
              then Round((ORL2  - (AtrTargetMult * ATR)) / TickSize(), 0) * TickSize()
              else cond2[1];
plot Ltarget =  if bar >= HighestAll(OREndBar)
                then highestAll(if isNaN(c[-1])
                                then cond2
                                else double.nan)
                else double.nan;
     Ltarget.SetPaintingStrategy(PaintingStrategy.Squares);
     Ltarget.SetLineWeight(1);
     Ltarget.SetDefaultColor(Color.White);
     Ltarget.HideTitle();
AddChartBubble(BubbleLoc1, cond2, "RO", color.white, if c < Ltarget
                                                     then yes
                                                     else no);
  def condLtarget2 = if c crosses below cond2
  then Round((cond2 - (AtrTargetMult * ATR)) / TickSize(), 0) * TickSize()
  else condLtarget2[1];
plot Ltarget2 =  if bar >= HighestAll(OREndBar)
                 then highestAll(if isNaN(c[-1])
                                 then condLtarget2
                                 else double.nan)
                 else double.nan;
     Ltarget2.SetPaintingStrategy(PaintingStrategy.Squares);
     Ltarget2.SetLineWeight(1);
     Ltarget2.SetDefaultColor(Color.Plum);
     Ltarget2.HideTitle();
AddChartBubble(BubbleLoc1, condLtarget2, "2nd T", color.plum, if c < condLtarget2
                                                              then yes
                                                              else no);
  def condLtarget3 = if c crosses below condLtarget2
  then Round((condLtarget2 - (AtrTargetMult * ATR)) / TickSize(), 0) * TickSize()
  else condLtarget3[1];
plot Ltarget3 = if bar >= HighestAll(OREndBar)
                then highestAll(if isNaN(c[-1])
                                then condLtarget3
                                else double.nan)
                else double.nan;
     Ltarget3.SetPaintingStrategy(PaintingStrategy.Squares);
     Ltarget3.SetLineWeight(1);
     Ltarget3.SetDefaultColor(Color.Plum);
     Ltarget3.HideTitle();
AddChartBubble(BubbleLoc1, condLtarget3, "3rd T", color.plum, if c < Ltarget3
                                                              then yes
                                                              else no);
  def condLtarget4 = if c crosses condLtarget3
  then Round((condLtarget3 - (AtrTargetMult * ATR)) / TickSize(), 0) * TickSize()
  else condLtarget4[1];
plot Ltarget4 = if bar >= HighestAll(OREndBar)
                then highestAll(if isNaN(c[-1])
                                then condLtarget4
                                else double.nan)
                else double.nan;
     Ltarget4.SetPaintingStrategy(PaintingStrategy.Squares);
     Ltarget4.SetLineWeight(1);
     Ltarget4.SetDefaultColor(Color.Plum);
     Ltarget4.HideTitle();
AddChartBubble(BubbleLoc1, condLtarget4, "4th T", color.plum, if c < Ltarget4
                                                              then yes
                                                              else no);
  def condLtarget5 = if c crosses condLtarget4
  then Round((condLtarget4 - (AtrTargetMult * ATR)) / TickSize(), 0) * TickSize()
  else condLtarget5[1];
plot Ltarget5 = if bar >= HighestAll(OREndBar)
                then highestAll(if isNaN(c[-1])
                                then condLtarget5
                                else double.nan)
                else double.nan;
     Ltarget5.SetPaintingStrategy(PaintingStrategy.Squares);
     Ltarget5.SetLineWeight(1);
     Ltarget5.SetDefaultColor(Color.Plum);
     Ltarget5.HideTitle();
AddChartBubble(BubbleLoc1, condLtarget5, "5th T", color.plum, if c < Ltarget5
                                                              then yes
                                                              else no);
def last = if secondsTillTime(1600) == 0 and
              secondsFromTime(1600) == 0
           then c[1]
           else last[1];
plot LastClose = if Today and last != 0
                 then last
                 else Double.NaN;
     LastClose.SetPaintingStrategy(PaintingStrategy.Dashes);
     LastClose.SetDefaultColor(Color.White);
     LastClose.HideBubble();
     LastClose.HideTitle();
AddChartBubble(SecondsTillTime(0930) == 0, LastClose, "PC", color.gray, yes);
alert(c crosses above ORH2, "", Alert.Bar, Sound.Bell);
alert(c crosses below ORL2, "", Alert.Bar, Sound.Ring);
# End Code ORB with Risk and targets

Shareable Link: https://tos.mx/qu3Cu0

Now that you have the indicator added, let's get some terminology out of the way.
  • The green shadow is called the Bull Zone
  • The red shadow is called Bear Zone
  • Anywhere above the Bull Zone is called the Breakout Zone
  • Anywhere below the Bear Zone is called the Breakdown Zone

Hopefully you were able to understand those terms from this picture.

6TYzeF5.png


The Setup

  • 5 or 15 minutes timeframe
  • Heikin-Ashi candlestick
  • Disable pre-market and after-hour market
  • TEMA (30)
  • EMA (20)
  • Supertrend Indicator

Usage #1: Taking Advantage of Breakout Zone

Once the stock reaches above the breakout zone, we buy calls.

Usage #2: Taking Advantage of Breakdown Zone

Do the same as above. If the stock start to go from Bear Zone to breakdown zone, we start shorting it.

Usage #3: Avoid Misleading Signals given by Supertrend

A lot of people brought up a really good point about Supertrend. That is sometimes it would give false signals. And I also seen it first hand too. The Opening Range Breakout Indicator will allows us to resolve that.

Example #1: Don't short when the candles are still in the Bull Zone.

ITKLEOm.png


The only time that it is reasonable to short while the candles are still in Bull Zone is: IF the candle are by the border of Bull Zone and Bear Zone. Even better if it's already crossing the border into Bear Zone.

Example #2: Don't Buy Calls in Breakdown Zone

If you think the Bear Zone is worst, wait until you buy calls in the Breakdown Zone. That's a hard pass.

35EW7Rf.png


Again, sometimes it may be reasonable to buy calls if the candles are crossing the border going back to Bear Zone, then you may have a chance to pull thru and get above it. But anywhere between the Bear Zone and Breakdown Zone, be cautious, especially if you're already deep down in the Breakdown Zone.

Here is another example of "don't buy calls in the Breakdown zone"

EUamb16.png


The following screenshot will tell us a few things.

telbFSl.png


  1. When the Supertrend is giving us a buy signal, and that candle is crossing from Bear Zone into Bull Zone, then it's potentially setting up for a call play. (circle #1)
  2. Unlike the rule of not buying calls when you're in Breakdown Zone, shorting when in Breakout Zone could potentially be profitable too. But only if it's reasonable. Look at circle #2. It rejected the white dotted line, which is an additional border to enter another Breakout Zone. Since it rejected the second breakout area, we could take advantage of the Supertrend signal to go short.
  3. Circle #3 and #4, don't short in Breakout Zone without reasonable evidence (I like to use Support and Resistance during the Breakout and Breakdown Zone).

When the Supertrend is showing a buy signal while the candle is in Bull Zone then it's fairly safe to take it. When Supertrend is showing a short signal while the candle s in Bear Zone, then it's fairly safe to short at that point. Treat these zones as the home of Bears and Bulls.

I think the concept is pretty simple and straightforward here. Give it a spin and let me know how it goes for you guys.

Feel free to post questions, ideas, or any additional finding from this indicator.

P.S: I'll let Steve talk more about the usage of TEMA and EMA when he's on.

Update: A different version with Fibonacci Levels.

Here is the scanner for anyone interested.
HI @BenTen


I'm trying to calculate data on the IB range from yesterday, but I can't find a way. Can you help me with some instructions. As much as I try to put "(orhigh [1])" it does not return correct data. I don't know if I have to add some parameter to include the time period. Thanks
 
@chewie76 Nice. It's so hard to get realistic backtesting results since a lot of the trades would have been filtered out or ignored. That's why I don't really opt for backtesting strategies when it comes to testing.
 
Recently came across this cool indicator called Opening Range Breakout by Mobius. This is more than just an indicator. There is also a strategy with risk and target lines included.



thinkScript Code

After adding the indicator, I couldn't quite understand it much. From looking at it, seems more like a support and resistance indicator to me. I watched a few YouTube videos about the Opening Range Breakout and was able to make some changes to the current code. As a result, I was able to have a clear picture of what this indicator does.

Here is my own version of it:

Rich (BB code):
declare Hide_On_Daily;
declare Once_per_bar;

input OrMeanS  = 0930.0; #hint OrMeanS: Begin Mean Period. Usually Market Open EST.
input OrMeanE  = 0935.0; #hint OrMeanE: End Mean period. Usually End of first bar.
input OrBegin  = 0930.0; #hint OrBegin: Beginning for Period of Opening Range Breakout.
input OrEnd    = 1000.0; #hint OrEnd: End of Period of Opening Range Breakout.
input CloudOn  = no;     #hint CloudOn: Clouds Opening Range.
input AlertOn  = yes;    #hint AlertOn: Alerts on cross of Opening Range.
input ShowTodayOnly = {"No", default "Yes"}; 
input nAtr = 4;          #hint nATR: Lenght for the ATR Risk and Target Lines.
input AtrTargetMult = 2.0; #hint ATRmult: Multiplier for the ATR calculations.

  def h = high;
  def l = low;
  def c = close;
  def bar = barNumber();
  def s = ShowTodayOnly;
  def ORActive = if secondsTillTime(OrMeanE) > 0 and
                    secondsFromTime(OrMeanS) >= 0
                 then 1
                 else 0;
  def today = if s == 0
              or getDay() == getLastDay() and
                 secondsFromTime(OrMeanS) >= 0
              then 1
              else 0;
  def ORHigh = if ORHigh[1] == 0
               or ORActive[1] == 0 and
                  ORActive == 1
               then h
               else if ORActive and
                       h > ORHigh[1]
               then h
               else ORHigh[1];
  def ORLow = if ORLow[1] == 0
              or ORActive[1] == 0 and
                 ORActive == 1
              then l
              else if ORActive and
                      l < ORLow[1]
              then l
              else ORLow[1];
  def ORWidth = ORHigh - ORLow;
  def na = double.nan;
  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 - Round(((ORHA - ORLA) / 2) / TickSize(), 0) * TickSize();
  def ORActive2 = if secondsTillTime(OREnd) > 0 and
                     secondsFromTime(ORBegin) >= 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(OREnd) == 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);
plot ORLext = if barNumber() >= highestAll(ORmeanBar)
              then HighestAll(if isNaN(c[-1])
                              then ORL[1]
                              else double.nan)
              else double.nan;
     ORLext.SetDefaultColor(color.Yellow);
     ORLext.SetStyle(curve.Long_DASH);
     ORLext.SetLineWeight(3);
     ORLext.HideTitle();
  def ORH2 = if ORActive2
             or today < 1
             then na
             else ORHigh2;
plot ORH2ext = if barNumber() >= highestAll(ORendBar)
               then HighestAll(if isNaN(c[-1])
                               then ORH2[1]
                               else double.nan)
               else double.nan;
     ORH2ext.SetDefaultColor(color.Green);
     ORH2ext.SetStyle(curve.Long_DASH);
     ORH2ext.SetLineWeight(3);
     ORH2ext.HideTitle();
  def ORL2 = if ORActive2
               or today < 1
             then na
             else ORLow2;
plot ORL2ext = if barNumber() >= highestAll(ORendBar)
               then HighestAll(if isNaN(c[-1])
                               then ORL2[1]
                               else double.nan)
               else double.nan;
     ORL2ext.SetDefaultColor(color.Red);
     ORL2ext.SetStyle(curve.Long_DASH);
     ORL2ext.SetLineWeight(3);
     ORL2ext.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;
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.POINTS);
     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.POINTS);
     d1.AssignValueColor(GetColor(Dcolor));
     d2.AssignValueColor(GetColor(Dcolor));
     d3.AssignValueColor(GetColor(Dcolor));
     d4.AssignValueColor(GetColor(Dcolor));
     d5.AssignValueColor(GetColor(Dcolor));
     d6.AssignValueColor(GetColor(Dcolor));
     d7.AssignValueColor(GetColor(Dcolor));
     d8.AssignValueColor(GetColor(Dcolor));
     d9.AssignValueColor(GetColor(Dcolor));
    d10.AssignValueColor(GetColor(Dcolor));
     d1.HideBubble();
     d2.HideBubble();
     d3.HideBubble();
     d4.HideBubble();
     d5.HideBubble();
     d6.HideBubble();
     d7.HideBubble();
     d8.HideBubble();
     d9.HideBubble();
    d10.HideBubble();
     d1.HideTitle();
     d2.HideTitle();
     d3.HideTitle();
     d4.HideTitle();
     d5.HideTitle();
     d6.HideTitle();
     d7.HideTitle();
     d8.HideTitle();
     d9.HideTitle();
    d10.HideTitle();
addCloud(if CloudOn == yes
         then orl
         else double.nan
       , orl2,createColor(244,83,66), createColor(244,83,66));
addCloud(if CloudOn == yes
         then orl
         else double.nan
       , orh2,createColor(66,244,131), createColor(66,244,131));
# Begin Risk Algorithm
# First Breakout or Breakdown bars
  def Bubbleloc1 = isNaN(close[-1]);
  def BreakoutBar = if ORActive
                    then double.nan
                    else if !ORActive and c crosses above ORH2
                         then bar
                         else if !isNaN(BreakoutBar[1]) and c crosses ORH2
                              then BreakoutBar[1]
                    else BreakoutBar[1];
  def ATR = if ORActive2
  then Round((Average(TrueRange(h, c, l), nATR)) / TickSize(), 0) * TickSize()
  else ATR[1];
  def cond1 =  if h > ORH2 and
                  h[1] <= ORH2
               then Round((ORH2  + (ATR * AtrTargetMult)) / TickSize(), 0) * TickSize()
               else cond1[1];
plot ORLriskUP = if bar >= OREndBar and !ORActive and today
                 then HighestAll(ORH2ext - 2)
                 else double.nan;
     ORLriskUP.SetStyle(Curve.Long_Dash);
     ORLriskUP.SetDefaultColor(Color.Green);
     ORLriskUP.HideTitle();
  def crossUpBar = if close crosses above ORH2
                   then bar
                   else double.nan;
AddChartBubble(bar == HighestAll(crossUpBar), ORLriskUP, "RiskON ORH", color.green, no);
plot ORLriskDN = if bar >= OREndBar and !ORActive and close < ORL
                 then HighestAll(ORL2ext + 2)
                 else double.nan;
     ORLriskDN.SetStyle(Curve.Long_Dash);
     ORLriskDN.SetDefaultColor(Color.Red);
     ORLriskDN.HideTitle();
  def crossDnBar = if close crosses below ORL2ext
                   then bar
                   else double.nan;
AddChartBubble(bar == HighestAll(crossDnBar), HighestAll(ORLriskDN), "Risk ON ORL", color.red, yes);
# High Targets
plot Htarget = if bar >= BreakoutBar
               then cond1
               else double.nan;
     Htarget.SetPaintingStrategy(paintingStrategy.Squares);
     Htarget.SetLineWeight(1);
     Htarget.SetDefaultColor(Color.White);
     Htarget.HideTitle();
AddChartBubble(BubbleLoc1, Htarget, "RO", color.white, if c > Htarget then no else yes);
  def condHtarget2 = if c crosses above cond1
  then Round((cond1 + (ATR * AtrTargetMult)) / TickSize(), 0) * TickSize()
  else condHtarget2[1];
plot Htarget2 = if bar >= BreakoutBar
                then  condHtarget2
                else double.nan;
     Htarget2.SetPaintingStrategy(PaintingStrategy.Squares);
     Htarget2.SetLineWeight(1);
     Htarget2.SetDefaultColor(Color.Plum);
     Htarget2.HideTitle();
AddChartBubble(BubbleLoc1, Htarget2, "2nd T", color.plum, if c > Htarget2
                                                          then no
                                                          else yes);
  def condHtarget3 = if c crosses above condHtarget2
  then Round((condHtarget2 + (ATR * AtrTargetMult)) / TickSize(), 0) * TickSize()
  else condHtarget3[1];
plot Htarget3 = if bar >= BreakoutBar
                then condHtarget3
                else double.nan;
     Htarget3.SetPaintingStrategy(PaintingStrategy.Squares);
     Htarget3.SetLineWeight(1);
     Htarget3.SetDefaultColor(Color.Plum);
     Htarget3.HideTitle();
AddChartBubble(isNaN(C[-1]), Htarget3, "3rd T", color.plum, if c > Htarget3 then no else yes);
  def condHtarget4 = if c crosses above condHtarget3
  then Round((condHtarget3 + (ATR * AtrTargetMult)) / TickSize(), 0) * TickSize()
  else condHtarget4[1];
plot Htarget4 = if bar >= HighestAll(BreakoutBar)
                then condHtarget4
                else double.nan;
     Htarget4.SetPaintingStrategy(PaintingStrategy.Squares);
     Htarget4.SetLineWeight(1);
     Htarget4.SetDefaultColor(Color.Plum);
     Htarget4.HideTitle();
AddChartBubble(BubbleLoc1, Htarget4, "4th T", color.plum, if c > Htarget4 then no else yes);
  def condHtarget5 = if c crosses above condHtarget4
  then Round((condHtarget4 + (ATR * AtrTargetMult)) / TickSize(), 0) * TickSize()
  else condHtarget5[1];
plot Htarget5 = if bar >= BreakoutBar
                then condHtarget5
                else double.nan;
     Htarget5.SetPaintingStrategy(PaintingStrategy.Squares);
     Htarget5.SetLineWeight(1);
     Htarget5.SetDefaultColor(Color.Plum);
     Htarget5.HideTitle();
AddChartBubble(BubbleLoc1, Htarget5, "5th T", color.plum, if c > Htarget5 then no else yes);
# Low Targets
  def cond2 = if L < ORL2 and
                 L[1] >= ORL2
              then Round((ORL2  - (AtrTargetMult * ATR)) / TickSize(), 0) * TickSize()
              else cond2[1];
plot Ltarget =  if bar >= HighestAll(OREndBar)
                then highestAll(if isNaN(c[-1])
                                then cond2
                                else double.nan)
                else double.nan;
     Ltarget.SetPaintingStrategy(PaintingStrategy.Squares);
     Ltarget.SetLineWeight(1);
     Ltarget.SetDefaultColor(Color.White);
     Ltarget.HideTitle();
AddChartBubble(BubbleLoc1, cond2, "RO", color.white, if c < Ltarget
                                                     then yes
                                                     else no);
  def condLtarget2 = if c crosses below cond2
  then Round((cond2 - (AtrTargetMult * ATR)) / TickSize(), 0) * TickSize()
  else condLtarget2[1];
plot Ltarget2 =  if bar >= HighestAll(OREndBar)
                 then highestAll(if isNaN(c[-1])
                                 then condLtarget2
                                 else double.nan)
                 else double.nan;
     Ltarget2.SetPaintingStrategy(PaintingStrategy.Squares);
     Ltarget2.SetLineWeight(1);
     Ltarget2.SetDefaultColor(Color.Plum);
     Ltarget2.HideTitle();
AddChartBubble(BubbleLoc1, condLtarget2, "2nd T", color.plum, if c < condLtarget2
                                                              then yes
                                                              else no);
  def condLtarget3 = if c crosses below condLtarget2
  then Round((condLtarget2 - (AtrTargetMult * ATR)) / TickSize(), 0) * TickSize()
  else condLtarget3[1];
plot Ltarget3 = if bar >= HighestAll(OREndBar)
                then highestAll(if isNaN(c[-1])
                                then condLtarget3
                                else double.nan)
                else double.nan;
     Ltarget3.SetPaintingStrategy(PaintingStrategy.Squares);
     Ltarget3.SetLineWeight(1);
     Ltarget3.SetDefaultColor(Color.Plum);
     Ltarget3.HideTitle();
AddChartBubble(BubbleLoc1, condLtarget3, "3rd T", color.plum, if c < Ltarget3
                                                              then yes
                                                              else no);
  def condLtarget4 = if c crosses condLtarget3
  then Round((condLtarget3 - (AtrTargetMult * ATR)) / TickSize(), 0) * TickSize()
  else condLtarget4[1];
plot Ltarget4 = if bar >= HighestAll(OREndBar)
                then highestAll(if isNaN(c[-1])
                                then condLtarget4
                                else double.nan)
                else double.nan;
     Ltarget4.SetPaintingStrategy(PaintingStrategy.Squares);
     Ltarget4.SetLineWeight(1);
     Ltarget4.SetDefaultColor(Color.Plum);
     Ltarget4.HideTitle();
AddChartBubble(BubbleLoc1, condLtarget4, "4th T", color.plum, if c < Ltarget4
                                                              then yes
                                                              else no);
  def condLtarget5 = if c crosses condLtarget4
  then Round((condLtarget4 - (AtrTargetMult * ATR)) / TickSize(), 0) * TickSize()
  else condLtarget5[1];
plot Ltarget5 = if bar >= HighestAll(OREndBar)
                then highestAll(if isNaN(c[-1])
                                then condLtarget5
                                else double.nan)
                else double.nan;
     Ltarget5.SetPaintingStrategy(PaintingStrategy.Squares);
     Ltarget5.SetLineWeight(1);
     Ltarget5.SetDefaultColor(Color.Plum);
     Ltarget5.HideTitle();
AddChartBubble(BubbleLoc1, condLtarget5, "5th T", color.plum, if c < Ltarget5
                                                              then yes
                                                              else no);
def last = if secondsTillTime(1600) == 0 and
              secondsFromTime(1600) == 0
           then c[1]
           else last[1];
plot LastClose = if Today and last != 0
                 then last
                 else Double.NaN;
     LastClose.SetPaintingStrategy(PaintingStrategy.Dashes);
     LastClose.SetDefaultColor(Color.White);
     LastClose.HideBubble();
     LastClose.HideTitle();
AddChartBubble(SecondsTillTime(0930) == 0, LastClose, "PC", color.gray, yes);
alert(c crosses above ORH2, "", Alert.Bar, Sound.Bell);
alert(c crosses below ORL2, "", Alert.Bar, Sound.Ring);
# End Code ORB with Risk and targets

Shareable Link: https://tos.mx/qu3Cu0

Now that you have the indicator added, let's get some terminology out of the way.
  • The green shadow is called the Bull Zone
  • The red shadow is called Bear Zone
  • Anywhere above the Bull Zone is called the Breakout Zone
  • Anywhere below the Bear Zone is called the Breakdown Zone

Hopefully you were able to understand those terms from this picture.

6TYzeF5.png


The Setup

  • 5 or 15 minutes timeframe
  • Heikin-Ashi candlestick
  • Disable pre-market and after-hour market
  • TEMA (30)
  • EMA (20)
  • Supertrend Indicator

Usage #1: Taking Advantage of Breakout Zone

Once the stock reaches above the breakout zone, we buy calls.

Usage #2: Taking Advantage of Breakdown Zone

Do the same as above. If the stock start to go from Bear Zone to breakdown zone, we start shorting it.

Usage #3: Avoid Misleading Signals given by Supertrend

A lot of people brought up a really good point about Supertrend. That is sometimes it would give false signals. And I also seen it first hand too. The Opening Range Breakout Indicator will allows us to resolve that.

Example #1: Don't short when the candles are still in the Bull Zone.

ITKLEOm.png


The only time that it is reasonable to short while the candles are still in Bull Zone is: IF the candle are by the border of Bull Zone and Bear Zone. Even better if it's already crossing the border into Bear Zone.

Example #2: Don't Buy Calls in Breakdown Zone

If you think the Bear Zone is worst, wait until you buy calls in the Breakdown Zone. That's a hard pass.

35EW7Rf.png


Again, sometimes it may be reasonable to buy calls if the candles are crossing the border going back to Bear Zone, then you may have a chance to pull thru and get above it. But anywhere between the Bear Zone and Breakdown Zone, be cautious, especially if you're already deep down in the Breakdown Zone.

Here is another example of "don't buy calls in the Breakdown zone"

EUamb16.png


The following screenshot will tell us a few things.

telbFSl.png


  1. When the Supertrend is giving us a buy signal, and that candle is crossing from Bear Zone into Bull Zone, then it's potentially setting up for a call play. (circle #1)
  2. Unlike the rule of not buying calls when you're in Breakdown Zone, shorting when in Breakout Zone could potentially be profitable too. But only if it's reasonable. Look at circle #2. It rejected the white dotted line, which is an additional border to enter another Breakout Zone. Since it rejected the second breakout area, we could take advantage of the Supertrend signal to go short.
  3. Circle #3 and #4, don't short in Breakout Zone without reasonable evidence (I like to use Support and Resistance during the Breakout and Breakdown Zone).

When the Supertrend is showing a buy signal while the candle is in Bull Zone then it's fairly safe to take it. When Supertrend is showing a short signal while the candle s in Bear Zone, then it's fairly safe to short at that point. Treat these zones as the home of Bears and Bulls.

I think the concept is pretty simple and straightforward here. Give it a spin and let me know how it goes for you guys.

Feel free to post questions, ideas, or any additional finding from this indicator.

P.S: I'll let Steve talk more about the usage of TEMA and EMA when he's on.

Update: A different version with Fibonacci Levels.

Here is the scanner for anyone interested.
Hi Ben,
Is there any way possible the plots and clouds for this indicator can end within the regular chart session and not get extended to the right? I will really appreciate it if this can be adjusted to keep the extended side clean to use other indicators needed. Thanks.
 
The White Dashed line is Highest OR c/o and Magenta is Lowest OR c/o.
Hi All, I absolutely love this indicator and I was wondering if we could add an extra feature.

Can this be modified so it will have the option to choose: show on expansion yes/no.
 
Last edited:
The Onexpansion option was added to the code in this post from above
https://usethinkscript.com/threads/opening-range-breakout-indicator-for-thinkorswim.16/post-113995

The image on the left is High Target testing and on the right Low Target testing

View attachment 18812
Couple of requests for this great work as well.

1. Can this also be scripts so when choosing show no on expansion the plots stops with the very last candle and does not go over the expansion side?

2. Can you add additional inputs to begin and end the plots for the ORLext function only? I am only interested in the opening range breakout high and low with its own beginning and end time in addition to the ORLext plot with a separate beginning and end time function.
 

Attachments

  • Screenshot 2023-06-01 at 11.24.42 AM.png
    Screenshot 2023-06-01 at 11.24.42 AM.png
    242.1 KB · Views: 154
Couple of requests for this great work as well.

1. Can this also be scripts so when choosing show no on expansion the plots stops with the very last candle and does not go over the expansion side?

2. Can you add additional inputs to begin and end the plots for the ORLext function only? I am only interested in the opening range breakout high and low with its own beginning and end time in addition to the ORLext plot with a separate beginning and end time function.

1. This should work as you requested now.
2. I have only reset it as with the other plots. If you want it otherwise, an image may be helpful.

Screenshot 2023-06-01 155129.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 = yes;
input OrMeanS = 0930.0; #hint OrMeanS: Begin Mean Period. Usually Market Open EST.
input OrMeanE = 0935.0; #hint OrMeanE: End Mean period. Usually End of first bar.
input OrBegin = 0930.0; #hint OrBegin: Beginning for Period of Opening Range Breakout.
input OrEnd = 1000.0; #hint OrEnd: End of Period of Opening Range Breakout.
input CloudOn = no; #hint CloudOn: Clouds Opening Range.
input AlertOn = yes; #hint AlertOn: Alerts on cross of Opening Range.
input ShowTodayOnly = {"No", default "Yes"};
input nAtr = 4; #hint nATR: Lenght for the ATR Risk and Target Lines.
input AtrTargetMult = 2.0; #hint ATRmult: Multiplier for the ATR calculations.

def h = high;
def l = low;
def c = close;

def bar = BarNumber();
def s = ShowTodayOnly;
def ORActive = if SecondsTillTime(OrMeanE) > 0 and
SecondsFromTime(OrMeanS) >= 0
then 1
else 0;

def today = if s == 0
or GetDay() == GetLastDay() and
SecondsFromTime(OrMeanS) >= 0
then 1
else 0;

def ORHigh = if ORHigh[1] == 0
or ORActive[1] == 0 and
ORActive == 1
then h
else if ORActive and
h > ORHigh[1]
then h
else ORHigh[1];

def ORLow = if ORLow[1] == 0
or ORActive[1] == 0 and
ORActive == 1
then l
else if ORActive and
l < ORLow[1]
then l
else ORLow[1];

def ORWidth = ORHigh - ORLow;

def na = Double.NaN;

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 - Round(((ORHA - ORLA) / 2) / TickSize(), 0) * TickSize();

def ORActive2 = if SecondsTillTime(OrEnd) > 0 and
SecondsFromTime(OrBegin) >= 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(OrEnd) == 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);

plot ORLext = if onexpansion and !isnan(close) then double.nan
              else if onexpansion and BarNumber() >= HighestAll(ORmeanBar)
                   then HighestAll(if IsNaN(c[-1])
                                   then ORL[1]
                                   else Double.NaN)
              else if !onexpansion  
              then ORL
              else Double.NaN;
ORLext.SetDefaultColor(Color.YELLOW);
ORLext.SetStyle(Curve.LONG_DASH);
ORLext.SetLineWeight(3);
ORLext.HideTitle();

def ORH2 = if ORActive2
or today < 1
then na
else ORHigh2;

plot ORH2ext = if onexpansion and !isnan(close) then double.nan
               else if !ShowTodayOnly
               then ORH2[1]
               else if onexpansion and BarNumber() >= HighestAll(ORendBar)
                    then HighestAll(if IsNaN(c[-1])
                    then ORH2[1]
                    else Double.NaN)
               else if !onexpansion          
               then ORH2  
               else Double.NaN;
ORH2ext.SetDefaultColor(Color.GREEN);
ORH2ext.SetStyle(Curve.LONG_DASH);
ORH2ext.SetLineWeight(3);
ORH2ext.HideTitle();

def ORL2 = if ORActive2
or today < 1
then na
else ORLow2;

plot ORL2ext = if onexpansion and !isnan(close) then double.nan
               else if !ShowTodayOnly
               then ORL2[1]
               else if onexpansion and BarNumber() >= HighestAll(ORendBar)
                    then HighestAll(if IsNaN(c[-1])
                                    then ORL2[1]
                                    else Double.NaN)
                else if !onexpansion
                then ORL2
                else Double.NaN;
ORL2ext.SetDefaultColor(Color.RED);
ORL2ext.SetStyle(Curve.LONG_DASH);
ORL2ext.SetLineWeight(3);
ORL2ext.HideTitle();

def ORcHi = if ORcHi[1] == 0
or ORActive2[1] == 0 and
ORActive2 == 1
then c
else if ORActive2 and
c > ORcHi[1]
then c
else ORcHi[1];

def ORcLo = if ORcLo[1] == 0
or ORActive2[1] == 0 and
ORActive2 == 1
then c
else if ORActive2 and
c < ORcLo[1]
then c
else ORcLo[1];

def ORoHi = if ORoHi[1] == 0
or ORActive2[1] == 0 and
ORActive2 == 1
then open
else if ORActive2 and
open > ORoHi[1]
then open
else ORoHi[1];

def ORoLo = if ORoLo[1] == 0
or ORActive2[1] == 0 and
ORActive2 == 1
then open
else if ORActive2 and
open < ORoLo[1]
then open
else ORoLo[1];

def ORHoc2 = if ORActive2
or today < 1
then na
else Max(ORcHi[1], ORoHi[1]) ;

plot ORHoc = if onexpansion and !isnan(close) then double.nan
             else if !ShowTodayOnly
             then ORHoc2
             else if onexpansion and BarNumber() >= HighestAll(ORendBar)
             then HighestAll(if IsNaN(c[-1])
                             then ORHoc2
                             else Double.NaN)
              else if !onexpansion
              then ORHoc2
              else Double.NaN;
ORHoc.SetDefaultColor(Color.WHITE);
ORHoc.SetStyle(Curve.LONG_DASH);
ORHoc.SetLineWeight(3);
ORHoc.HideTitle();

def ORLoc2 = if ORActive2
or today < 1
then na
else Min(ORcLo[1], ORoLo[1]) ;

plot ORLoc = if onexpansion and !isnan(close) then double.nan
             else if !ShowTodayOnly
             then ORLoc2
             else if onexpansion and BarNumber() >= HighestAll(ORendBar)
             then HighestAll(if IsNaN(c[-1])
                             then Min(ORcLo, ORoLo)
                             else Double.NaN)
             else if !onexpansion
             then ORLoc2
             else Double.NaN;
ORLoc.SetDefaultColor(Color.MAGENTA);
ORLoc.SetStyle(Curve.LONG_DASH);
ORLoc.SetLineWeight(3);
ORLoc.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;
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.POINTS);
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.POINTS);
d1.AssignValueColor(GetColor(dColor));
d2.AssignValueColor(GetColor(dColor));
d3.AssignValueColor(GetColor(dColor));
d4.AssignValueColor(GetColor(dColor));
d5.AssignValueColor(GetColor(dColor));
d6.AssignValueColor(GetColor(dColor));
d7.AssignValueColor(GetColor(dColor));
d8.AssignValueColor(GetColor(dColor));
d9.AssignValueColor(GetColor(dColor));
d10.AssignValueColor(GetColor(dColor));
d1.HideBubble();
d2.HideBubble();
d3.HideBubble();
d4.HideBubble();
d5.HideBubble();
d6.HideBubble();
d7.HideBubble();
d8.HideBubble();
d9.HideBubble();
d10.HideBubble();
d1.HideTitle();
d2.HideTitle();
d3.HideTitle();
d4.HideTitle();
d5.HideTitle();
d6.HideTitle();
d7.HideTitle();
d8.HideTitle();
d9.HideTitle();
d10.HideTitle();

AddCloud(if CloudOn == yes
then ORL
else Double.NaN
, ORL2, CreateColor(244, 83, 66), CreateColor(244, 83, 66));

AddCloud(if CloudOn == yes
then ORL
else Double.NaN
, ORH2, CreateColor(66, 244, 131), CreateColor(66, 244, 131));

# Begin Risk Algorithm
# First Breakout or Breakdown bars

def Bubbleloc1 = IsNaN(close) and !isnan(close[1]);
def Bubbleloc2 = IsNaN(close[-1]) and !isnan(close);

def BreakoutBar = if ORActive
then Double.NaN
else if !ORActive and c crosses above ORH2
then bar
else if !IsNaN(BreakoutBar[1]) and c crosses ORH2
then BreakoutBar[1]
else BreakoutBar[1];

def ATR = if ORActive2
then Round((Average(TrueRange(h, c, l), nAtr)) / TickSize(), 0) * TickSize()
else ATR[1];

def cond1 = if h > ORH2 and
h[1] <= ORH2
then Round((ORH2 + (ATR * AtrTargetMult)) / TickSize(), 0) * TickSize()
else cond1[1];

plot ORLriskUP = if onexpansion and !isnan(close) then double.nan
                 else if bar >= ORendBar and !ORActive and today
                 then HighestAll(ORH2ext - 2)                
                 else Double.NaN;
ORLriskUP.SetStyle(Curve.LONG_DASH);
ORLriskUP.SetDefaultColor(Color.GREEN);
ORLriskUP.HideTitle();

def crossUpBar = if close crosses above ORH2
then bar
else Double.NaN;

AddChartBubble(bar == HighestAll(crossUpBar), ORLriskUP, "Risk\nON ORH", Color.GREEN, no);

plot ORLriskDN = if onexpansion and !isnan(close) then double.nan
                 else if bar >= ORendBar and !ORActive and close < ORL
                 then HighestAll(ORL2ext + 2)
                 else Double.NaN;
ORLriskDN.SetStyle(Curve.LONG_DASH);
ORLriskDN.SetDefaultColor(Color.RED);
ORLriskDN.HideTitle();

def crossDnBar = if close crosses below ORL2ext
then bar
else Double.NaN;

AddChartBubble(bar == HighestAll(crossDnBar), HighestAll(ORLriskDN), "Risk\nON ORL", Color.RED, yes);

# High Targets
plot Htarget = if onexpansion and !isnan(c) then double.nan
               else if onexpansion and bar >= highestall(breakoutbar)
               then HighestAll(if isNaN(c[-1])
                               then cond1
                               else Double.NaN)
               else if !onexpansion
               then cond1
               else Double.NaN;
Htarget.SetPaintingStrategy(PaintingStrategy.SQUARES);
Htarget.SetLineWeight(1);
Htarget.SetDefaultColor(Color.WHITE);
Htarget.HideTitle();
AddChartBubble(Bubbleloc1, Htarget, "RO", Color.WHITE, if c > Htarget then no else yes);

def condHtarget2 = if c crosses above cond1
then Round((cond1 + (ATR * AtrTargetMult)) / TickSize(), 0) * TickSize()
else condHtarget2[1];

plot Htarget2 = if onexpansion and !isnan(c) then double.nan
                else if onexpansion and  bar >= highestall(orendBar)
                      then HighestAll(if isNaN(c[-1])
                                      then condHtarget2
                                       else Double.NaN)
                else if !onexpansion
                then condHtarget2          
                else Double.NaN;
Htarget2.SetPaintingStrategy(PaintingStrategy.SQUARES);
Htarget2.SetLineWeight(1);
Htarget2.SetDefaultColor(Color.PLUM);
Htarget2.HideTitle();

AddChartBubble(Bubbleloc1, Htarget2, "2nd T", Color.PLUM, if c > Htarget2
then no
else yes);

def condHtarget3 = if c crosses above condHtarget2
then Round((condHtarget2 + (ATR * AtrTargetMult)) / TickSize(), 0) * TickSize()
else condHtarget3[1];

plot Htarget3 = if onexpansion and !isnan(c) then double.nan
                else if onexpansion and  bar >= highestall(orendBar)
                      then HighestAll(if isNaN(c[-1])
                                      then condHtarget3
                                       else Double.NaN)
                else if !onexpansion
                then condHtarget3          
                else Double.NaN;
Htarget3.SetPaintingStrategy(PaintingStrategy.SQUARES);
Htarget3.SetLineWeight(1);
Htarget3.SetDefaultColor(Color.PLUM);
Htarget3.HideTitle();

AddChartBubble(Bubbleloc1, Htarget3, "3rd T", Color.PLUM, if c > Htarget3 then no else yes);

def condHtarget4 = if c crosses above condHtarget3
then Round((condHtarget3 + (ATR * AtrTargetMult)) / TickSize(), 0) * TickSize()
else condHtarget4[1];

plot Htarget4 = if onexpansion and !isnan(c) then double.nan
                else if onexpansion and  bar >= highestall(orendBar)
                      then HighestAll(if isNaN(c[-1])
                                      then condHtarget4
                                       else Double.NaN)
                else if !onexpansion
                then condHtarget4          
                else Double.NaN;
Htarget4.SetPaintingStrategy(PaintingStrategy.SQUARES);
Htarget4.SetLineWeight(1);
Htarget4.SetDefaultColor(Color.PLUM);
Htarget4.HideTitle();

AddChartBubble(Bubbleloc1, Htarget4, "4th T", Color.PLUM, if c > Htarget4 then no else yes);

def condHtarget5 = if c crosses above condHtarget4
then Round((condHtarget4 + (ATR * AtrTargetMult)) / TickSize(), 0) * TickSize()
else condHtarget5[1];

plot Htarget5 = if onexpansion and !isnan(c) then double.nan
                else if onexpansion and  bar >= highestall(orendBar)
                      then HighestAll(if isNaN(c[-1])
                                      then condHtarget5
                                       else Double.NaN)
                else if !onexpansion
                then condHtarget5          
                else Double.NaN;
Htarget5.SetPaintingStrategy(PaintingStrategy.SQUARES);
Htarget5.SetLineWeight(1);
Htarget5.SetDefaultColor(Color.PLUM);
Htarget5.HideTitle();
AddChartBubble(Bubbleloc1, Htarget5, "5th T", Color.PLUM, if c > Htarget5 then no else yes);

# Low Targets

def cond2 = if l < ORL2 and
l[1] >= ORL2
then Round((ORL2 - (AtrTargetMult * ATR)) / TickSize(), 0) * TickSize()
else cond2[1];

plot Ltarget = if onexpansion and !isnan(close) then double.nan
               else if onexpansion and bar >= HighestAll(ORendBar)
               then HighestAll(if IsNaN(c[-1])
                               then cond2
                               else Double.NaN)
               else if !onexpansion
               then cond2
               else Double.NaN;
Ltarget.SetPaintingStrategy(PaintingStrategy.SQUARES);
Ltarget.SetLineWeight(1);
Ltarget.SetDefaultColor(Color.WHITE);
Ltarget.HideTitle();

AddChartBubble(Bubbleloc2, cond2, "RO", Color.WHITE, if c < Ltarget
then yes
else no);

def condLtarget2 = if c crosses below cond2
then Round((cond2 - (AtrTargetMult * ATR)) / TickSize(), 0) * TickSize()
else condLtarget2[1];

plot Ltarget2 = if onexpansion and !isnan(close) then double.nan
                else if onexpansion and bar >= HighestAll(ORendBar)
                then HighestAll(if IsNaN(c[-1])
                                then condLtarget2
                                else Double.NaN)
                else if !onexpansion  
                then condLTarget2
                else Double.NaN;
Ltarget2.SetPaintingStrategy(PaintingStrategy.SQUARES);
Ltarget2.SetLineWeight(1);
Ltarget2.SetDefaultColor(Color.PLUM);
Ltarget2.HideTitle();

AddChartBubble(Bubbleloc2, condLtarget2, "2nd T", Color.PLUM, if c < condLtarget2
then yes
else no);

def condLtarget3 = if c crosses below condLtarget2
then Round((condLtarget2 - (AtrTargetMult * ATR)) / TickSize(), 0) * TickSize()
else condLtarget3[1];

plot Ltarget3 = if onexpansion and !isnan(close) then double.nan
                else if onexpansion and bar >= HighestAll(ORendBar)
                then HighestAll(if IsNaN(c[-1])
                                then condLtarget3
                                else Double.NaN)
                else if !onexpansion  
                then condLTarget3
                else Double.NaN;
Ltarget3.SetPaintingStrategy(PaintingStrategy.SQUARES);
Ltarget3.SetLineWeight(1);
Ltarget3.SetDefaultColor(Color.PLUM);
Ltarget3.HideTitle();

AddChartBubble(Bubbleloc2, condLtarget3, "3rd T", Color.PLUM, if c < Ltarget3
then yes
else no);

def condLtarget4 = if c crosses condLtarget3
then Round((condLtarget3 - (AtrTargetMult * ATR)) / TickSize(), 0) * TickSize()
else condLtarget4[1];

plot Ltarget4 = if onexpansion and !isnan(close) then double.nan
                else if onexpansion and bar >= HighestAll(ORendBar)
                then HighestAll(if IsNaN(c[-1])
                                then condLtarget4
                                else Double.NaN)
                else if !onexpansion  
                then condLTarget4
                else Double.NaN;
Ltarget4.SetPaintingStrategy(PaintingStrategy.SQUARES);
Ltarget4.SetLineWeight(1);
Ltarget4.SetDefaultColor(Color.PLUM);
Ltarget4.HideTitle();

AddChartBubble(Bubbleloc2, condLtarget4, "4th T", Color.PLUM, if c < Ltarget4
then yes
else no);

def condLtarget5 = if c crosses condLtarget4
then Round((condLtarget4 - (AtrTargetMult * ATR)) / TickSize(), 0) * TickSize()
else condLtarget5[1];

plot Ltarget5 = if onexpansion and !isnan(close) then double.nan
                else if onexpansion and bar >= HighestAll(ORendBar)
                then HighestAll(if IsNaN(c[-1])
                                then condLtarget5
                                else Double.NaN)
                else if !onexpansion  
                then condLTarget5
                else Double.NaN;
Ltarget5.SetPaintingStrategy(PaintingStrategy.SQUARES);
Ltarget5.SetLineWeight(1);
Ltarget5.SetDefaultColor(Color.PLUM);
Ltarget5.HideTitle();
AddChartBubble(Bubbleloc2, condLtarget5, "5th T", Color.PLUM, if c < Ltarget5
then yes
else no);
def last = if SecondsTillTime(1600) == 0 and
SecondsFromTime(1600) == 0
then c[1]
else last[1];

plot LastClose = if onexpansion and !isnan(close) then double.nan
else if today and last != 0
then last
else Double.NaN;
LastClose.SetPaintingStrategy(PaintingStrategy.DASHES);
LastClose.SetDefaultColor(Color.WHITE);
LastClose.HideBubble();
LastClose.HideTitle();

AddChartBubble(SecondsTillTime(0930) == 0, LastClose, "PC", Color.GRAY, yes);
Alert(c crosses above ORH2, "", Alert.BAR, Sound.Bell);
Alert(c crosses below ORL2, "", Alert.BAR, Sound.Ring);
# End Code ORB with Risk and targets
 
1. This should work as you requested now.
2. I have only reset it as with the other plots. If you want it otherwise, an image may be helpful.
Thanks for adjusting the plots to end with the candles.

Please refer to the image attached to complete the second part of this request.

The goal is to be able to manage the start time for the ORB high/low and the ORLext separately. The cyan dashed line is not necessary as a plot. I'm using it as a reference only. The only plots I need to see is the ORB high, ORB low and the ORLext plots that can be managed at the time needed.
 

Attachments

  • Screenshot 2023-06-02 at 8.37.51 AM.png
    Screenshot 2023-06-02 at 8.37.51 AM.png
    307.2 KB · Views: 150
Thanks for adjusting the plots to end with the candles.

Please refer to the image attached to complete the second part of this request.

The goal is to be able to manage the start time for the ORB high/low and the ORLext separately. The cyan dashed line is not necessary as a plot. I'm using it as a reference only. The only plots I need to see is the ORB high, ORB low and the ORLext plots that can be managed at the time needed.

The adds :

input ORHL_S = 0930;
input ORHL_E = 0945;
def ORActiveHL = if SecondsTillTime(ORHL_E) > 0 and
SecondsFromTime(ORHL_S) >= 0
then 1
else 0;


The changes:

ORHigh/Low to be dependent on the "adds"
Last close and ORLriskUP and ORLriskDN were fixed when !onexpansion to limited plot.


Any plots that you do not want can be unchecked at the input screen.

As I do not use this indicator, please let me know if the adds/changes are not working the way you expected.

Screenshot 2023-06-02 112810.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 = yes;
input ORHL_S  = 0930;
input ORHL_E  = 0945;
input OrMeanS = 0930.0; #hint OrMeanS: Begin Mean Period. Usually Market Open EST.
input OrMeanE = 0935.0; #hint OrMeanE: End Mean period. Usually End of first bar.
input OrBegin = 0930.0; #hint OrBegin: Beginning for Period of Opening Range Breakout.
input OrEnd = 1000.0; #hint OrEnd: End of Period of Opening Range Breakout.
input CloudOn = no; #hint CloudOn: Clouds Opening Range.
input AlertOn = yes; #hint AlertOn: Alerts on cross of Opening Range.
input ShowTodayOnly = {"No", default "Yes"};
input nAtr = 4; #hint nATR: Lenght for the ATR Risk and Target Lines.
input AtrTargetMult = 2.0; #hint ATRmult: Multiplier for the ATR calculations.

def h = high;
def l = low;
def c = close;

def bar = BarNumber();
def s = ShowTodayOnly;

def ORActive = if SecondsTillTime(OrMeanE) > 0 and
SecondsFromTime(OrMeanS) >= 0
then 1
else 0;

def ORActiveHL = if SecondsTillTime(ORHL_E) > 0 and
SecondsFromTime(ORHL_S) >= 0
then 1
else 0;

def today = if s == 0
or GetDay() == GetLastDay() and
SecondsFromTime(OrMeanS) >= 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 na = Double.NaN;

def ORHA = if ORActiveHL
or today < 1
then na
else ORHigh;

def ORLA = if ORActiveHL
or today < 1
then na
else ORLow;

def O = ORHA - Round(((ORHA - ORLA) / 2) / TickSize(), 0) * TickSize();

def ORActive2 = if SecondsTillTime(OrEnd) > 0 and
SecondsFromTime(OrBegin) >= 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(OrEnd) == 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);

plot ORLext = if onexpansion and !IsNaN(close) then Double.NaN
              else if onexpansion and BarNumber() >= HighestAll(ORmeanBar)
                   then HighestAll(if IsNaN(c[-1])
                                   then ORL[1]
                                   else Double.NaN)
              else if !onexpansion 
              then ORL
              else Double.NaN;
ORLext.SetDefaultColor(Color.YELLOW);
ORLext.SetStyle(Curve.LONG_DASH);
ORLext.SetLineWeight(3);
ORLext.HideTitle();

def ORH2 = if ORActive2
or today < 1
then na
else ORHigh2;

plot ORH2ext = if onexpansion and !IsNaN(close) then Double.NaN
               else if !ShowTodayOnly
               then ORH2[1]
               else if onexpansion and BarNumber() >= HighestAll(ORendBar)
                    then HighestAll(if IsNaN(c[-1])
                    then ORH2[1]
                    else Double.NaN)
               else if !onexpansion         
               then ORH2 
               else Double.NaN;
ORH2ext.SetDefaultColor(Color.GREEN);
ORH2ext.SetStyle(Curve.LONG_DASH);
ORH2ext.SetLineWeight(3);
ORH2ext.HideTitle();

def ORL2 = if ORActive2
or today < 1
then na
else ORLow2;

plot ORL2ext = if onexpansion and !IsNaN(close) then Double.NaN
               else if !ShowTodayOnly
               then ORL2[1]
               else if onexpansion and BarNumber() >= HighestAll(ORendBar)
                    then HighestAll(if IsNaN(c[-1])
                                    then ORL2[1]
                                    else Double.NaN)
                else if !onexpansion
                then ORL2
                else Double.NaN;
ORL2ext.SetDefaultColor(Color.RED);
ORL2ext.SetStyle(Curve.LONG_DASH);
ORL2ext.SetLineWeight(3);
ORL2ext.HideTitle();

def ORcHi = if ORcHi[1] == 0
or ORActive2[1] == 0 and
ORActive2 == 1
then c
else if ORActive2 and
c > ORcHi[1]
then c
else ORcHi[1];

def ORcLo = if ORcLo[1] == 0
or ORActive2[1] == 0 and
ORActive2 == 1
then c
else if ORActive2 and
c < ORcLo[1]
then c
else ORcLo[1];

def ORoHi = if ORoHi[1] == 0
or ORActive2[1] == 0 and
ORActive2 == 1
then open
else if ORActive2 and
open > ORoHi[1]
then open
else ORoHi[1];

def ORoLo = if ORoLo[1] == 0
or ORActive2[1] == 0 and
ORActive2 == 1
then open
else if ORActive2 and
open < ORoLo[1]
then open
else ORoLo[1];

def ORHoc2 = if ORActive2
or today < 1
then na
else Max(ORcHi[1], ORoHi[1]) ;

plot ORHoc = if onexpansion and !IsNaN(close) then Double.NaN
             else if !ShowTodayOnly
             then ORHoc2
             else if onexpansion and BarNumber() >= HighestAll(ORendBar)
             then HighestAll(if IsNaN(c[-1])
                             then ORHoc2
                             else Double.NaN)
              else if !onexpansion
              then ORHoc2
              else Double.NaN;
ORHoc.SetDefaultColor(Color.WHITE);
ORHoc.SetStyle(Curve.LONG_DASH);
ORHoc.SetLineWeight(3);
ORHoc.HideTitle();

def ORLoc2 = if ORActive2
or today < 1
then na
else Min(ORcLo[1], ORoLo[1]) ;

plot ORLoc = if onexpansion and !IsNaN(close) then Double.NaN
             else if !ShowTodayOnly
             then ORLoc2
             else if onexpansion and BarNumber() >= HighestAll(ORendBar)
             then HighestAll(if IsNaN(c[-1])
                             then Min(ORcLo, ORoLo)
                             else Double.NaN)
             else if !onexpansion
             then ORLoc2
             else Double.NaN;
ORLoc.SetDefaultColor(Color.MAGENTA);
ORLoc.SetStyle(Curve.LONG_DASH);
ORLoc.SetLineWeight(3);
ORLoc.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;
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.POINTS);
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.POINTS);
d1.AssignValueColor(GetColor(dColor));
d2.AssignValueColor(GetColor(dColor));
d3.AssignValueColor(GetColor(dColor));
d4.AssignValueColor(GetColor(dColor));
d5.AssignValueColor(GetColor(dColor));
d6.AssignValueColor(GetColor(dColor));
d7.AssignValueColor(GetColor(dColor));
d8.AssignValueColor(GetColor(dColor));
d9.AssignValueColor(GetColor(dColor));
d10.AssignValueColor(GetColor(dColor));
d1.HideBubble();
d2.HideBubble();
d3.HideBubble();
d4.HideBubble();
d5.HideBubble();
d6.HideBubble();
d7.HideBubble();
d8.HideBubble();
d9.HideBubble();
d10.HideBubble();
d1.HideTitle();
d2.HideTitle();
d3.HideTitle();
d4.HideTitle();
d5.HideTitle();
d6.HideTitle();
d7.HideTitle();
d8.HideTitle();
d9.HideTitle();
d10.HideTitle();

AddCloud(if CloudOn == yes
then ORL
else Double.NaN
, ORL2, CreateColor(244, 83, 66), CreateColor(244, 83, 66));

AddCloud(if CloudOn == yes
then ORL
else Double.NaN
, ORH2, CreateColor(66, 244, 131), CreateColor(66, 244, 131));

# Begin Risk Algorithm
# First Breakout or Breakdown bars

def Bubbleloc1 = IsNaN(close) and !IsNaN(close[1]);
def Bubbleloc2 = IsNaN(close[-1]) and !IsNaN(close);

def BreakoutBar = if ORActive
then Double.NaN
else if !ORActive and c crosses above ORH2
then bar
else if !IsNaN(BreakoutBar[1]) and c crosses ORH2
then BreakoutBar[1]
else BreakoutBar[1];

def ATR = if ORActive2
then Round((Average(TrueRange(h, c, l), nAtr)) / TickSize(), 0) * TickSize()
else ATR[1];

def cond1 = if h > ORH2 and
h[1] <= ORH2
then Round((ORH2 + (ATR * AtrTargetMult)) / TickSize(), 0) * TickSize()
else cond1[1];

plot ORLriskUP = if onexpansion and !IsNaN(close) then Double.NaN
                 else if onexpansion and bar >= ORendBar and !ORActive and today
                 then HighestAll(ORH2ext - 2)   
                 else if !onexpansion and !IsNaN(close) and bar >= ORendBar and !ORActive and today
                 then HighestAll(ORH2ext - 2)                               
                 else Double.NaN;
ORLriskUP.SetStyle(Curve.LONG_DASH);
ORLriskUP.SetDefaultColor(Color.GREEN);
ORLriskUP.HideTitle();

def crossUpBar = if close crosses above ORH2
then bar
else Double.NaN;

AddChartBubble(bar == HighestAll(crossUpBar), ORLriskUP, "Risk\nON ORH", Color.GREEN, no);

plot ORLriskDN = if onexpansion and !IsNaN(close) then Double.NaN
                 else if onexpansion and bar >= ORendBar and !ORActive and close < ORL
                 then HighestAll(ORL2ext + 2)
                 else if !onexpansion and !IsNaN(close) and bar >= ORendBar and !ORActive and close < ORL
                 then HighestAll(ORL2ext + 2)
                 else Double.NaN;
ORLriskDN.SetStyle(Curve.LONG_DASH);
ORLriskDN.SetDefaultColor(Color.RED);
ORLriskDN.HideTitle();

def crossDnBar = if close crosses below ORL2ext
then bar
else Double.NaN;

AddChartBubble(bar == HighestAll(crossDnBar), HighestAll(ORLriskDN), "Risk\nON ORL", Color.RED, yes);

# High Targets
plot Htarget = if onexpansion and !IsNaN(c) then Double.NaN
               else if onexpansion and bar >= HighestAll(BreakoutBar)
               then HighestAll(if IsNaN(c[-1])
                               then cond1
                               else Double.NaN)
               else if !onexpansion
               then cond1
               else Double.NaN;
Htarget.SetPaintingStrategy(PaintingStrategy.SQUARES);
Htarget.SetLineWeight(1);
Htarget.SetDefaultColor(Color.WHITE);
Htarget.HideTitle();
AddChartBubble(Bubbleloc1, Htarget, "RO", Color.WHITE, if c > Htarget then no else yes);

def condHtarget2 = if c crosses above cond1
then Round((cond1 + (ATR * AtrTargetMult)) / TickSize(), 0) * TickSize()
else condHtarget2[1];

plot Htarget2 = if onexpansion and !IsNaN(c) then Double.NaN
                else if onexpansion and  bar >= HighestAll(ORendBar)
                      then HighestAll(if IsNaN(c[-1])
                                      then condHtarget2
                                       else Double.NaN)
                else if !onexpansion
                then condHtarget2         
                else Double.NaN;
Htarget2.SetPaintingStrategy(PaintingStrategy.SQUARES);
Htarget2.SetLineWeight(1);
Htarget2.SetDefaultColor(Color.PLUM);
Htarget2.HideTitle();

AddChartBubble(Bubbleloc1, Htarget2, "2nd T", Color.PLUM, if c > Htarget2
then no
else yes);

def condHtarget3 = if c crosses above condHtarget2
then Round((condHtarget2 + (ATR * AtrTargetMult)) / TickSize(), 0) * TickSize()
else condHtarget3[1];

plot Htarget3 = if onexpansion and !IsNaN(c) then Double.NaN
                else if onexpansion and  bar >= HighestAll(ORendBar)
                      then HighestAll(if IsNaN(c[-1])
                                      then condHtarget3
                                       else Double.NaN)
                else if !onexpansion
                then condHtarget3         
                else Double.NaN;
Htarget3.SetPaintingStrategy(PaintingStrategy.SQUARES);
Htarget3.SetLineWeight(1);
Htarget3.SetDefaultColor(Color.PLUM);
Htarget3.HideTitle();

AddChartBubble(Bubbleloc1, Htarget3, "3rd T", Color.PLUM, if c > Htarget3 then no else yes);

def condHtarget4 = if c crosses above condHtarget3
then Round((condHtarget3 + (ATR * AtrTargetMult)) / TickSize(), 0) * TickSize()
else condHtarget4[1];

plot Htarget4 = if onexpansion and !IsNaN(c) then Double.NaN
                else if onexpansion and  bar >= HighestAll(ORendBar)
                      then HighestAll(if IsNaN(c[-1])
                                      then condHtarget4
                                       else Double.NaN)
                else if !onexpansion
                then condHtarget4         
                else Double.NaN;
Htarget4.SetPaintingStrategy(PaintingStrategy.SQUARES);
Htarget4.SetLineWeight(1);
Htarget4.SetDefaultColor(Color.PLUM);
Htarget4.HideTitle();

AddChartBubble(Bubbleloc1, Htarget4, "4th T", Color.PLUM, if c > Htarget4 then no else yes);

def condHtarget5 = if c crosses above condHtarget4
then Round((condHtarget4 + (ATR * AtrTargetMult)) / TickSize(), 0) * TickSize()
else condHtarget5[1];

plot Htarget5 = if onexpansion and !IsNaN(c) then Double.NaN
                else if onexpansion and  bar >= HighestAll(ORendBar)
                      then HighestAll(if IsNaN(c[-1])
                                      then condHtarget5
                                       else Double.NaN)
                else if !onexpansion
                then condHtarget5         
                else Double.NaN;
Htarget5.SetPaintingStrategy(PaintingStrategy.SQUARES);
Htarget5.SetLineWeight(1);
Htarget5.SetDefaultColor(Color.PLUM);
Htarget5.HideTitle();
AddChartBubble(Bubbleloc1, Htarget5, "5th T", Color.PLUM, if c > Htarget5 then no else yes);

# Low Targets

def cond2 = if l < ORL2 and
l[1] >= ORL2
then Round((ORL2 - (AtrTargetMult * ATR)) / TickSize(), 0) * TickSize()
else cond2[1];

plot Ltarget = if onexpansion and !IsNaN(close) then Double.NaN
               else if onexpansion and bar >= HighestAll(ORendBar)
               then HighestAll(if IsNaN(c[-1])
                               then cond2
                               else Double.NaN)
               else if !onexpansion
               then cond2
               else Double.NaN;
Ltarget.SetPaintingStrategy(PaintingStrategy.SQUARES);
Ltarget.SetLineWeight(1);
Ltarget.SetDefaultColor(Color.WHITE);
Ltarget.HideTitle();

AddChartBubble(Bubbleloc2, cond2, "RO", Color.WHITE, if c < Ltarget
then yes
else no);

def condLtarget2 = if c crosses below cond2
then Round((cond2 - (AtrTargetMult * ATR)) / TickSize(), 0) * TickSize()
else condLtarget2[1];

plot Ltarget2 = if onexpansion and !IsNaN(close) then Double.NaN
                else if onexpansion and bar >= HighestAll(ORendBar)
                then HighestAll(if IsNaN(c[-1])
                                then condLtarget2
                                else Double.NaN)
                else if !onexpansion 
                then condLtarget2
                else Double.NaN;
Ltarget2.SetPaintingStrategy(PaintingStrategy.SQUARES);
Ltarget2.SetLineWeight(1);
Ltarget2.SetDefaultColor(Color.PLUM);
Ltarget2.HideTitle();

AddChartBubble(Bubbleloc2, condLtarget2, "2nd T", Color.PLUM, if c < condLtarget2
then yes
else no);

def condLtarget3 = if c crosses below condLtarget2
then Round((condLtarget2 - (AtrTargetMult * ATR)) / TickSize(), 0) * TickSize()
else condLtarget3[1];

plot Ltarget3 = if onexpansion and !IsNaN(close) then Double.NaN
                else if onexpansion and bar >= HighestAll(ORendBar)
                then HighestAll(if IsNaN(c[-1])
                                then condLtarget3
                                else Double.NaN)
                else if !onexpansion 
                then condLtarget3
                else Double.NaN;
Ltarget3.SetPaintingStrategy(PaintingStrategy.SQUARES);
Ltarget3.SetLineWeight(1);
Ltarget3.SetDefaultColor(Color.PLUM);
Ltarget3.HideTitle();

AddChartBubble(Bubbleloc2, condLtarget3, "3rd T", Color.PLUM, if c < Ltarget3
then yes
else no);

def condLtarget4 = if c crosses condLtarget3
then Round((condLtarget3 - (AtrTargetMult * ATR)) / TickSize(), 0) * TickSize()
else condLtarget4[1];

plot Ltarget4 = if onexpansion and !IsNaN(close) then Double.NaN
                else if onexpansion and bar >= HighestAll(ORendBar)
                then HighestAll(if IsNaN(c[-1])
                                then condLtarget4
                                else Double.NaN)
                else if !onexpansion 
                then condLtarget4
                else Double.NaN;
Ltarget4.SetPaintingStrategy(PaintingStrategy.SQUARES);
Ltarget4.SetLineWeight(1);
Ltarget4.SetDefaultColor(Color.PLUM);
Ltarget4.HideTitle();

AddChartBubble(Bubbleloc2, condLtarget4, "4th T", Color.PLUM, if c < Ltarget4
then yes
else no);

def condLtarget5 = if c crosses condLtarget4
then Round((condLtarget4 - (AtrTargetMult * ATR)) / TickSize(), 0) * TickSize()
else condLtarget5[1];

plot Ltarget5 = if onexpansion and !IsNaN(close) then Double.NaN
                else if onexpansion and bar >= HighestAll(ORendBar)
                then HighestAll(if IsNaN(c[-1])
                                then condLtarget5
                                else Double.NaN)
                else if !onexpansion 
                then condLtarget5
                else Double.NaN;
Ltarget5.SetPaintingStrategy(PaintingStrategy.SQUARES);
Ltarget5.SetLineWeight(1);
Ltarget5.SetDefaultColor(Color.PLUM);
Ltarget5.HideTitle();
AddChartBubble(Bubbleloc2, condLtarget5, "5th T", Color.PLUM, if c < Ltarget5
then yes
else no);
def last = if SecondsTillTime(1600) == 0 and
SecondsFromTime(1600) == 0
then c[1]
else last[1];

plot LastClose = if onexpansion and !IsNaN(close) then Double.NaN
else if onexpansion and today and last != 0
then last
else if !onexpansion and !IsNaN(close) and today and last != 0
then last
else Double.NaN;
LastClose.SetPaintingStrategy(PaintingStrategy.DASHES);
LastClose.SetDefaultColor(Color.WHITE);
LastClose.HideBubble();
LastClose.HideTitle();

AddChartBubble(SecondsTillTime(0930) == 0, LastClose, "PC", Color.GRAY, yes);
Alert(c crosses above ORH2, "", Alert.BAR, Sound.Bell);
Alert(c crosses below ORL2, "", Alert.BAR, Sound.Ring);
# End Code ORB with Risk and targets
 
The adds :

input ORHL_S = 0930;
input ORHL_E = 0945;
def ORActiveHL = if SecondsTillTime(ORHL_E) > 0 and
SecondsFromTime(ORHL_S) >= 0
then 1
else 0;


The changes:

ORHigh/Low to be dependent on the "adds"
Last close and ORLriskUP and ORLriskDN were fixed when !onexpansion to limited plot.

Any plots that you do not want can be unchecked at the input screen.

As I do not use this indicator, please let me know if the adds/changes are not working the way you expected.
Fantastic work SleepyZ! Just Genius!!
 

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
583 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