Opening Range Breakout Indicator for ThinkorSwim

GreenPeny,
No worries at all. By going into the settings portion of the code, if you un-check the "Show bubble" checkmark box, it will remove the highlighting value bubble from the right of your chart, the vertical price area. That is removing "a" from my previous post.

To remove "b", which I think is what you are actually requesting, that requires adjusting the actual code. In any case, if you don't want a section of code to be recognized, using the "#" at the beginning of the line will essentially comment out that portion of code. The code is still there, but will be skipped over when it runs as ThinkScript... this allows you (the user) to alter what portions of code are used or not used without having to delete code you may potentially want to save for a later use.

Find below is the original code as posted by Ben in post 1 of this thread, but with the AddChartBubble areas commented out for you. I only commented out the Color.PLUM ones as those are the ones you were asking about, but if you want the "RO" and other chart bubbles to be removed, you can just scan through the code and anywhere you see AddChartBubble, just go ahead and place a # in front of any of the lines of the associated code you want to comment out and that should do it.

All my best.



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

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

GreenPeny,
No worries at all. By going into the settings portion of the code, if you un-check the "Show bubble" checkmark box, it will remove the highlighting value bubble from the right of your chart, the vertical price area. That is removing "a" from my previous post.

To remove "b", which I think is what you are actually requesting, that requires adjusting the actual code. In any case, if you don't want a section of code to be recognized, using the "#" at the beginning of the line will essentially comment out that portion of code. The code is still there, but will be skipped over when it runs as ThinkScript... this allows you (the user) to alter what portions of code are used or not used without having to delete code you may potentially want to save for a later use.

Find below is the original code as posted by Ben in post 1 of this thread, but with the AddChartBubble areas commented out for you. I only commented out the Color.PLUM ones as those are the ones you were asking about, but if you want the "RO" and other chart bubbles to be removed, you can just scan through the code and anywhere you see AddChartBubble, just go ahead and place a # in front of any of the lines of the associated code you want to comment out and that should do it.

All my best.



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

GaltsAtlantis,

Thank you so much for both explaining on how to disable the bubble for the future reference, and adjusting the code. I was trying to figure this for a while. This is greatly appreciated.
Yes I did unchecked the show bubble option from the setting as you mentioned above, but it only removes the lines not the actual bubble.
 
Hi all....i am going to set this one up in my TOS account....can someone please tag me which one is the latest and working code for this strategy? thank you for your help !
 
Hi @BenTen,

I am a recent member of the community and wanted to express my gratitude for all your contributions. Exploring and testing the material shared here has been quite a ride. I was hoping you could help me configure a strategy to assess the performance of the ORB. I'm considering using the close above ORH as a trigger for entering long positions and vice versa, utilizing Ltarget and Htarget as take-profit levels. I'm not sure if this would complicate the matter, but my idea is to set a stop-loss just below the entry if the take-profit levels are not reached.
 
Learning log v12.20

Second day of using the indicator. Great result!

Amazon Put Play

Like I mentioned earlier, once a stock start entering Breakdown zone, most likely it is going to breakdown. In the case of Amazon. It did exactly just that.

Take a look:

View attachment 4251

A few things to note:

  • 1. I entered at the yellow arrow, which was a risky play. Why? Because only the wick entered the Breakout Zone. This could have bounced up and my put would have been in trouble. Next time I would be more cautious and wait for confirmation of the break below Bear Zone entering Breakdown Zone.
  • 2. I sold at the blue arrow. Nothing wrong with taking profit. But I did not follow what I usually preached. I should have let Amazon break down further.

All and all. Great play in my opinion. I'll take another bite again when the opportunity presents itself.

View attachment 4252

P/S: +$119 / 43% in 7 minutes.
Thanks for sharing
 
Hi,
Can this be modified so each indicator can plot only for RTH when not in expansion?
https://usethinkscript.com/threads/...dicator-for-thinkorswim.16/page-8#post-113995

# 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_Begin = 0930;
input ORHL_Start = 0935;
input MARKETOpen = 0930.0; #hint OrMeanS: Begin Mean Period. Usually Market Open EST.
input EndOfFirstBar = 0935.0; #hint OrMeanE: End Mean period. Usually End of first bar.
input ORB_HL_Begin = 0930.0; #hint OrBegin: Beginning for Period of Opening Range Breakout.
input ORB_HL_Start = 1030.0; #hint OrEnd: End of Period of Opening Range Breakout.
input CloudOn = 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.
input pricecolor = yes;

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

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

def ORActive = if SecondsTillTime(EndOfFirstBar) > 0 and SecondsFromTime(MARKETOpen) >= 0 then 1 else 0;

def ORActiveHL = if SecondsTillTime(ORHL_Start) > 0 and
SecondsFromTime(ORHL_Begin) >= 0
then 1
else 0;

def today = if s == 0 or GetDay() == GetLastDay() and SecondsFromTime(MARKETOpen) >= 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(ORB_HL_Start) > 0 and
SecondsFromTime(ORB_HL_Begin) >= 0
then 1
else 0;

def ORHigh2 = if ORHigh2[1] == 0
or ORActive2[1] == 0 and
ORActive2 == 1
then h
else if ORActive2 and
h > ORHigh2[1]
then h
else ORHigh2[1];

def ORLow2 = if ORLow2[1] == 0
or ORActive2[1] == 0 and
ORActive2 == 1
then l
else if ORActive2 and
l < ORLow2[1]
then l
else ORLow2[1];

def ORWidth2 = ORHigh2 - ORLow2;

def TimeLine = if SecondsTillTime(ORB_HL_Start) == 0
then 1
else 0;

def ORmeanBar = if !ORActive and ORActive[1] then BarNumber() else ORmeanBar[1];

def ORendBar = if !ORActive2 and ORActive2[1]
then BarNumber()
else ORendBar[1];

def ORL = If (O == 0 , na, O);

plot ORB_BAL = 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;
ORB_BAL.SetDefaultColor(Color.YELLOW);
ORB_BAL.SetStyle(Curve.LONG_DASH);
ORB_BAL.SetLineWeight(3);
ORB_BAL.HideTitle();

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

plot ORB_H = 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;
ORB_H.SetDefaultColor(Color.GREEN);
ORB_H.SetStyle(Curve.LONG_DASH);
ORB_H.SetLineWeight(3);
ORB_H.HideTitle();

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

plot ORB_L = 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;
ORB_L.SetDefaultColor(Color.RED);
ORB_L.SetStyle(Curve.LONG_DASH);
ORB_L.SetLineWeight(3);
ORB_L.HideTitle();

def RelDay = (ORL - ORL2) / (ORH2 - ORL2);
def dColor = if RelDay > .5
then 5
else if RelDay < .5
then 6
else 4;

def pos = (ORH2 - ORL2) / 10;

AddCloud(if CloudOn == yes then ORL else Double.NaN, ORL2, Color.Light_Red, Color.Light_Red);
AddCloud(if CloudOn == yes then ORL else Double.NaN, ORH2, Color.Green, Color.Green);

input vertical_line = yes;

AddVerticalLine((vertical_line and SecondsFromTime(1030) == 0), " IB ", Color.CYAN, Curve.MEDIUM_DASH);

### ADX

input ADXlength = 14;
input averageType = AverageType.WILDERS;
input show_SmartADX_label = yes;
input paintbars = yes;

def currentADX = ADX(ADXlength);

DefineGlobalColor("ADXMaxHigh2", Color.CYAN);
DefineGlobalColor("ADXMaxHigh1", Color.MAGENTA);
DefineGlobalColor("ADXHigh", Color.GREEN);
DefineGlobalColor("ADXMid", Color.WHITE);
DefineGlobalColor("ADXLow", Color.RED);

AssignPriceColor (if currentADX > 55 then GlobalColor("ADXMaxHigh2") else if currentADX > 40 then GlobalColor ("ADXMAxHigh1") else if !pricecolor then Color.CURRENT else if close > ORB_BAL then color.green else if close < ORB_BAL then color.red else color.gray);
 
Last edited by a moderator:
Hi,
Can this be modified so each indicator can plot only for RTH when not in expansion?
https://usethinkscript.com/threads/...dicator-for-thinkorswim.16/page-8#post-113995

Added the following def rthrs and included it in the plots when the logic was not onexpansion.
###########
def rthrs = secondsfromTime(0930)>=0 and secondsfromTime(1600)<0;
###########

The image shows the new limiting of the plots to rthrs

Screenshot 2024-02-21 054633.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_Begin = 0930;
input ORHL_Start = 0935;
input MARKETOpen = 0930.0; #hint OrMeanS: Begin Mean Period. Usually Market Open EST.
input EndOfFirstBar = 0935.0; #hint OrMeanE: End Mean period. Usually End of first bar.
input ORB_HL_Begin = 0930.0; #hint OrBegin: Beginning for Period of Opening Range Breakout.
input ORB_HL_Start = 1030.0; #hint OrEnd: End of Period of Opening Range Breakout.
input CloudOn = 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.
input pricecolor = yes;

###########
def rthrs = secondsfromTime(0930)>=0 and secondsfromTime(1600)<0;
###########

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

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

def ORActive = if SecondsTillTime(EndOfFirstBar) > 0 and SecondsFromTime(MARKETOpen) >= 0 then 1 else 0;

def ORActiveHL = if SecondsTillTime(ORHL_Start) > 0 and
SecondsFromTime(ORHL_Begin) >= 0
then 1
else 0;

def today = if s == 0 or GetDay() == GetLastDay() and SecondsFromTime(MARKETOpen) >= 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(ORB_HL_Start) > 0 and
SecondsFromTime(ORB_HL_Begin) >= 0
then 1
else 0;

def ORHigh2 = if ORHigh2[1] == 0
or ORActive2[1] == 0 and
ORActive2 == 1
then h
else if ORActive2 and
h > ORHigh2[1]
then h
else ORHigh2[1];

def ORLow2 = if ORLow2[1] == 0
or ORActive2[1] == 0 and
ORActive2 == 1
then l
else if ORActive2 and
l < ORLow2[1]
then l
else ORLow2[1];

def ORWidth2 = ORHigh2 - ORLow2;

def TimeLine = if SecondsTillTime(ORB_HL_Start) == 0
then 1
else 0;

def ORmeanBar = if !ORActive and ORActive[1] then BarNumber() else ORmeanBar[1];

def ORendBar = if !ORActive2 and ORActive2[1]
then BarNumber()
else ORendBar[1];

def ORL = If (O == 0 , na, O);

plot ORB_BAL = 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 and rthrs
then ORL
else Double.NaN;
ORB_BAL.SetDefaultColor(Color.YELLOW);
ORB_BAL.SetStyle(Curve.LONG_DASH);
ORB_BAL.SetLineWeight(3);
ORB_BAL.HideTitle();

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

plot ORB_H = if onexpansion and !IsNaN(close) then Double.NaN
else if !ShowTodayOnly and rthrs
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 and rthrs
then ORH2
else Double.NaN;
ORB_H.SetDefaultColor(Color.GREEN);
ORB_H.SetStyle(Curve.LONG_DASH);
ORB_H.SetLineWeight(3);
ORB_H.HideTitle();

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

plot ORB_L = if onexpansion and !IsNaN(close) then Double.NaN
else if !ShowTodayOnly and rthrs
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 and rthrs
then ORL2
else Double.NaN;
ORB_L.SetDefaultColor(Color.RED);
ORB_L.SetStyle(Curve.LONG_DASH);
ORB_L.SetLineWeight(3);
ORB_L.HideTitle();

def RelDay = (ORL - ORL2) / (ORH2 - ORL2);
def dColor = if RelDay > .5
then 5
else if RelDay < .5
then 6
else 4;

def pos = (ORH2 - ORL2) / 10;

AddCloud(if CloudOn == yes then ORL else Double.NaN, ORL2, Color.Light_Red, Color.Light_Red);
AddCloud(if CloudOn == yes then ORL else Double.NaN, ORH2, Color.Green, Color.Green);

input vertical_line = yes;

AddVerticalLine((vertical_line and SecondsFromTime(1030) == 0), " IB ", Color.CYAN, Curve.MEDIUM_DASH);

### ADX

input ADXlength = 14;
input averageType = AverageType.WILDERS;
input show_SmartADX_label = yes;
input paintbars = yes;

def currentADX = ADX(ADXlength);

DefineGlobalColor("ADXMaxHigh2", Color.CYAN);
DefineGlobalColor("ADXMaxHigh1", Color.MAGENTA);
DefineGlobalColor("ADXHigh", Color.GREEN);
DefineGlobalColor("ADXMid", Color.WHITE);
DefineGlobalColor("ADXLow", Color.RED);

AssignPriceColor (if currentADX > 55 then GlobalColor("ADXMaxHigh2") else if currentADX > 40 then GlobalColor ("ADXMAxHigh1") else if !pricecolor then Color.CURRENT else if close > ORB_BAL then color.green else if close < ORB_BAL then color.red else color.gray);
 
Added the following def rthrs and included it in the plots when the logic was not onexpansion.
###########
def rthrs = secondsfromTime(0930)>=0 and secondsfromTime(1600)<0;
###########

The image shows the new limiting of the plots to rthrs
This is Fire! Can you also add bubbles for each plot that can be controlled using bubble movers with the options to choose on expansion yes/no please?
 
This is Fire! Can you also add bubbles for each plot that can be controlled using bubble movers with the options to choose on expansion yes/no please?

This has optional bubbles that can be moved sideways. There is a separate set of bubbles tha should work wne onexpanison = yes or another set to when onexpansion is set to no.

Screenshot 2024-02-24 122507.png
Code:
# Opening_Range_Breakout_Strategy_with_Risk_and_Target_Lines_OnexpansionOption
# 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_Begin = 0930;
input ORHL_Start = 0935;
input MARKETOpen = 0930.0; #hint OrMeanS: Begin Mean Period. Usually Market Open EST.
input EndOfFirstBar = 0935.0; #hint OrMeanE: End Mean period. Usually End of first bar.
input ORB_HL_Begin = 0930.0; #hint OrBegin: Beginning for Period of Opening Range Breakout.
input ORB_HL_Start = 1030.0; #hint OrEnd: End of Period of Opening Range Breakout.
input CloudOn = 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.
input pricecolor = yes;

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

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

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

def ORActive = if SecondsTillTime(EndOfFirstBar) > 0 and SecondsFromTime(MARKETOpen) >= 0 then 1 else 0;

def ORActiveHL = if SecondsTillTime(ORHL_Start) > 0 and
SecondsFromTime(ORHL_Begin) >= 0
then 1
else 0;

def today = if s == 0 or GetDay() == GetLastDay() and SecondsFromTime(MARKETOpen) >= 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(ORB_HL_Start) > 0 and
SecondsFromTime(ORB_HL_Begin) >= 0
then 1
else 0;

def ORHigh2 = if ORHigh2[1] == 0
or ORActive2[1] == 0 and
ORActive2 == 1
then h
else if ORActive2 and
h > ORHigh2[1]
then h
else ORHigh2[1];

def ORLow2 = if ORLow2[1] == 0
or ORActive2[1] == 0 and
ORActive2 == 1
then l
else if ORActive2 and
l < ORLow2[1]
then l
else ORLow2[1];

def ORWidth2 = ORHigh2 - ORLow2;

def TimeLine = if SecondsTillTime(ORB_HL_Start) == 0
then 1
else 0;

def ORmeanBar = if !ORActive and ORActive[1] then BarNumber() else ORmeanBar[1];

def ORendBar = if !ORActive2 and ORActive2[1]
then BarNumber()
else ORendBar[1];

def ORL = If (O == 0 , na, O);

plot ORB_BAL = 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 and rthrs
then ORL
else Double.NaN;
ORB_BAL.SetDefaultColor(Color.YELLOW);
ORB_BAL.SetStyle(Curve.LONG_DASH);
ORB_BAL.SetLineWeight(3);
ORB_BAL.HideTitle();

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

plot ORB_H = if onexpansion and !IsNaN(close) then Double.NaN
else if !ShowTodayOnly and rthrs
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 and rthrs
then ORH2
else Double.NaN;
ORB_H.SetDefaultColor(Color.GREEN);
ORB_H.SetStyle(Curve.LONG_DASH);
ORB_H.SetLineWeight(3);
ORB_H.HideTitle();

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

plot ORB_L = if onexpansion and !IsNaN(close) then Double.NaN
else if !ShowTodayOnly and rthrs
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 and rthrs
then ORL2
else Double.NaN;
ORB_L.SetDefaultColor(Color.RED);
ORB_L.SetStyle(Curve.LONG_DASH);
ORB_L.SetLineWeight(3);
ORB_L.HideTitle();

def RelDay = (ORL - ORL2) / (ORH2 - ORL2);
def dColor = if RelDay > .5
then 5
else if RelDay < .5
then 6
else 4;

def pos = (ORH2 - ORL2) / 10;

AddCloud(if CloudOn == yes then ORL else Double.NaN, ORL2, Color.LIGHT_RED, Color.LIGHT_RED);
AddCloud(if CloudOn == yes then ORL else Double.NaN, ORH2, Color.GREEN, Color.GREEN);

input vertical_line = yes;

AddVerticalLine((vertical_line and SecondsFromTime(1030) == 0), " IB ", Color.CYAN, Curve.MEDIUM_DASH);

### ADX

input ADXlength = 14;
input averageType = AverageType.WILDERS;
input show_SmartADX_label = yes;
input paintbars = yes;

def currentADX = ADX(ADXlength);

DefineGlobalColor("ADXMaxHigh2", Color.CYAN);
DefineGlobalColor("ADXMaxHigh1", Color.MAGENTA);
DefineGlobalColor("ADXHigh", Color.GREEN);
DefineGlobalColor("ADXMid", Color.WHITE);
DefineGlobalColor("ADXLow", Color.RED);

AssignPriceColor (if currentADX > 55 then GlobalColor("ADXMaxHigh2") else if currentADX > 40 then GlobalColor ("ADXMAxHigh1") else if !pricecolor then Color.CURRENT else if close > ORB_BAL then Color.GREEN else if close < ORB_BAL then Color.RED else Color.GRAY);

input bubble = yes;
input bubblemover = 2;
def   mover = bubble and onexpansion and IsNaN(close[bubblemover]) and !IsNaN(close[bubblemover + 1]);
AddChartBubble(bubble and !onexpansion and !ORActive[2] and IsNaN(ORB_H[bubblemover - 1]) and !IsNaN(ORB_H[bubblemover]), ORB_H[bubblemover],  "H: " + AsText(ORB_H[bubblemover]), ORB_H.TakeValueColor());
AddChartBubble(bubble and !onexpansion and !ORActive[2] and IsNaN(ORB_L[bubblemover - 1]) and !IsNaN(ORB_L[bubblemover]), ORB_L[bubblemover],  "L: " + AsText(ORB_L[bubblemover]),  ORB_L.TakeValueColor());
AddChartBubble(bubble and !onexpansion and !ORActive[2] and IsNaN(ORB_BAL[bubblemover - 1]) and !IsNaN(ORB_BAL[bubblemover]), ORB_BAL[bubblemover],  "BAL: " + AsText(ORB_BAL[bubblemover]),  ORB_BAL.TakeValueColor());

AddChartBubble(bubble and mover, ORB_H[bubblemover],  "H: " + AsText(ORB_H[bubblemover]),  ORB_H.TakeValueColor());
AddChartBubble(bubble and mover, ORB_L[bubblemover],  "L: " + AsText(ORB_L[bubblemover]),  ORB_L.TakeValueColor());
AddChartBubble(bubble and mover, ORB_BAL[bubblemover],  "BAL: " + AsText(ORB_BAL[bubblemover]),  ORB_BAL.TakeValueColor());

#
 
Last edited:
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.

View attachment 4237

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.

View attachment 4238

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.

View attachment 4239

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"

View attachment 4240

The following screenshot will tell us a few things.

View attachment 4241

  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,
Again, thanks for the great indicator. It used to work very well on previous versions of ToS, however with current version there are some issues with the RiskOn lines and target lines, especially on the downside. They are not being painted or painted broken. I guess something with the software update of ToS is causing the issues. Is there an updated version for this indicator? Has anyone else seen these same issues on Tos (not drawing well the RiskON ORL and the lower targets?
 
Hi BenTen,
Again, thanks for the great indicator. It used to work very well on previous versions of ToS, however with current version there are some issues with the RiskOn lines and target lines, especially on the downside. They are not being painted or painted broken. I guess something with the software update of ToS is causing the issues. Is there an updated version for this indicator? Has anyone else seen these same issues on Tos (not drawing well the RiskON ORL and the lower targets?
No, the ToS app has not changed.
You did not provide enough information to say where you went astray.
If you are having issues, you may need to adjust your chart settings.
Or perhaps the instrument that you are viewing is missing data.

If you want a specific response.
Please provide an annotated image highlighting the problem.
Please post a shared chart link, so members can see what you are seeing.

How to create a shared chart link:
https://usethinkscript.com/threads/how-to-share-a-chart-in-thinkorswim.14221/
 
Please help with the RO white line (What is RO) and how to use ?
What is Risk On ORL (open Range low) is this correct? 2bd target purple color on chart below the RO
please point to the place if it is explained already
 
Is there a way to avoid showing the ORB bubbles from the previous day at the opening of the current day session? Oh, and actually this is an ongoing issue for all previous days as well.

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

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

###########

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

###########

def h = high;
def l = low;
def c = close;
def s = ShowTodayOnly;
def today = if s == 0 or GetDay() == GetLastDay() and SecondsFromTime(MARKETOpen) >= 0 then 1 else 0;
def na = double.nan;
def ORActive = if SecondsTillTime(EndOfFirstBar) > 0 and SecondsFromTime(MARKETOpen) >= 0 then 1 else 0;
def ORActiveHL = if SecondsTillTime(ORHL_Start) > 0 and
SecondsFromTime(ORHL_Begin) >= 0 then 1 else 0;
def ORHigh = if ORHigh[1] == 0 or ORActiveHL[1] == 0 and ORActiveHL == 1 then h else if ORActiveHL and h > ORHigh[1] then h else ORHigh[1];
def ORLow = if ORLow[1] == 0 or ORActiveHL[1] == 0 and ORActiveHL == 1 then l else if ORActiveHL and l < ORLow[1] then l else ORLow[1];
def ORWidth = ORHigh - ORLow;
def ORHA = if ORActiveHL or today < 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(ORB_HL_Start) > 0 and SecondsFromTime(ORB_HL_Begin) >= 0 then 1 else 0;
def ORHigh2 = if ORHigh2[1] == 0 or ORActive2[1] == 0 and ORActive2 == 1 then h else if ORActive2 and h > ORHigh2[1] then h else ORHigh2[1];
def ORLow2 = if ORLow2[1] == 0 or ORActive2[1] == 0 and ORActive2 == 1 then l else if ORActive2 and l < ORLow2[1] then l else ORLow2[1];
def ORWidth2 = ORHigh2 - ORLow2;
def TimeLine = if SecondsTillTime(ORB_HL_Start) == 0 then 1 else 0;
def ORmeanBar = if !ORActive and ORActive[1] then BarNumber() else ORmeanBar[1];
def ORendBar = if !ORActive2 and ORActive2[1]
then BarNumber() else ORendBar[1];
def ORL = If (O == 0 , na, O);
def ORH2 = if ORActive2 or today < 1 then na else ORHigh2;

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

ORB_BAL.SetDefaultColor(Color.YELLOW);
ORB_BAL.SetStyle(Curve.LONG_DASH);
ORB_BAL.SetLineWeight(3);
ORB_BAL.HideTitle();

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

ORB_H.SetDefaultColor(Color.GREEN);
ORB_H.SetStyle(Curve.LONG_DASH);
ORB_H.SetLineWeight(3);
ORB_H.HideTitle();

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

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

ORB_L.SetDefaultColor(Color.RED);
ORB_L.SetStyle(Curve.LONG_DASH);
ORB_L.SetLineWeight(3);
ORB_L.HideTitle();

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

AddCloud(if CloudOn_ORB and rthrs == yes then ORL else Double.NaN, ORL2, Color.Light_Red, Color.Light_Red);
AddCloud(if CloudOn_ORB and rthrs == yes then ORL else Double.NaN, ORH2, Color.Green, Color.Green);

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

AddChartBubble(bubble_ORB and mover_ORB, ORB_H[bubblemover_ORB], "IB_H" + AsText(ORB_H[bubblemover_ORB]), ORB_H.TakeValueColor());
AddChartBubble(bubble_ORB and mover_ORB, ORB_L[bubblemover_ORB], "IB_L" + AsText(ORB_L[bubblemover_ORB]), ORB_L.TakeValueColor());
AddChartBubble(bubble_ORB and mover_ORB, ORB_BAL[bubblemover_ORB], "BAL" + AsText(ORB_BAL[bubblemover_ORB]), ORB_BAL.TakeValueColor());
 

Attachments

  • Screenshot 2024-03-01 at 9.49.42 PM.png
    Screenshot 2024-03-01 at 9.49.42 PM.png
    341.7 KB · Views: 267
Last edited by a moderator:
Is there a way to avoid showing the ORB bubbles from the previous day at the opening of the current day session? Oh, and actually this is an ongoing issue for all previous days as well.

Please refer to the attached for your reference.

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

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

###########

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

###########

def h = high;
def l = low;
def c = close;
def s = ShowTodayOnly;
def today = if s == 0 or GetDay() == GetLastDay() and SecondsFromTime(MARKETOpen) >= 0 then 1 else 0;
def na = double.nan;
def ORActive = if SecondsTillTime(EndOfFirstBar) > 0 and SecondsFromTime(MARKETOpen) >= 0 then 1 else 0;
def ORActiveHL = if SecondsTillTime(ORHL_Start) > 0 and
SecondsFromTime(ORHL_Begin) >= 0 then 1 else 0;
def ORHigh = if ORHigh[1] == 0 or ORActiveHL[1] == 0 and ORActiveHL == 1 then h else if ORActiveHL and h > ORHigh[1] then h else ORHigh[1];
def ORLow = if ORLow[1] == 0 or ORActiveHL[1] == 0 and ORActiveHL == 1 then l else if ORActiveHL and l < ORLow[1] then l else ORLow[1];
def ORWidth = ORHigh - ORLow;
def ORHA = if ORActiveHL or today < 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(ORB_HL_Start) > 0 and SecondsFromTime(ORB_HL_Begin) >= 0 then 1 else 0;
def ORHigh2 = if ORHigh2[1] == 0 or ORActive2[1] == 0 and ORActive2 == 1 then h else if ORActive2 and h > ORHigh2[1] then h else ORHigh2[1];
def ORLow2 = if ORLow2[1] == 0 or ORActive2[1] == 0 and ORActive2 == 1 then l else if ORActive2 and l < ORLow2[1] then l else ORLow2[1];
def ORWidth2 = ORHigh2 - ORLow2;
def TimeLine = if SecondsTillTime(ORB_HL_Start) == 0 then 1 else 0;
def ORmeanBar = if !ORActive and ORActive[1] then BarNumber() else ORmeanBar[1];
def ORendBar = if !ORActive2 and ORActive2[1]
then BarNumber() else ORendBar[1];
def ORL = If (O == 0 , na, O);
def ORH2 = if ORActive2 or today < 1 then na else ORHigh2;

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

ORB_BAL.SetDefaultColor(Color.YELLOW);
ORB_BAL.SetStyle(Curve.LONG_DASH);
ORB_BAL.SetLineWeight(3);
ORB_BAL.HideTitle();

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

ORB_H.SetDefaultColor(Color.GREEN);
ORB_H.SetStyle(Curve.LONG_DASH);
ORB_H.SetLineWeight(3);
ORB_H.HideTitle();

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

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

ORB_L.SetDefaultColor(Color.RED);
ORB_L.SetStyle(Curve.LONG_DASH);
ORB_L.SetLineWeight(3);
ORB_L.HideTitle();

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

AddCloud(if CloudOn_ORB and rthrs == yes then ORL else Double.NaN, ORL2, Color.Light_Red, Color.Light_Red);
AddCloud(if CloudOn_ORB and rthrs == yes then ORL else Double.NaN, ORH2, Color.Green, Color.Green);

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

AddChartBubble(bubble_ORB and mover_ORB, ORB_H[bubblemover_ORB], "IB_H" + AsText(ORB_H[bubblemover_ORB]), ORB_H.TakeValueColor());
AddChartBubble(bubble_ORB and mover_ORB, ORB_L[bubblemover_ORB], "IB_L" + AsText(ORB_L[bubblemover_ORB]), ORB_L.TakeValueColor());
AddChartBubble(bubble_ORB and mover_ORB, ORB_BAL[bubblemover_ORB], "BAL" + AsText(ORB_BAL[bubblemover_ORB]), ORB_BAL.TakeValueColor());

The following fixes this issue when onexpansion is no and showtoday only is no:

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

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

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

###########

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

###########

def h = high;
def l = low;
def c = close;
def s = ShowTodayOnly;
def today = if s == 0 or GetDay() == GetLastDay() and SecondsFromTime(MARKETOpen) >= 0 then 1 else 0;
def na = double.nan;
def ORActive = if SecondsTillTime(EndOfFirstBar) > 0 and SecondsFromTime(MARKETOpen) >= 0 then 1 else 0;
def ORActiveHL = if SecondsTillTime(ORHL_Start) > 0 and
SecondsFromTime(ORHL_Begin) >= 0 then 1 else 0;
def ORHigh = if ORHigh[1] == 0 or ORActiveHL[1] == 0 and ORActiveHL == 1 then h else if ORActiveHL and h > ORHigh[1] then h else ORHigh[1];
def ORLow = if ORLow[1] == 0 or ORActiveHL[1] == 0 and ORActiveHL == 1 then l else if ORActiveHL and l < ORLow[1] then l else ORLow[1];
def ORWidth = ORHigh - ORLow;
def ORHA = if ORActiveHL or today < 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(ORB_HL_Start) > 0 and SecondsFromTime(ORB_HL_Begin) >= 0 then 1 else 0;
def ORHigh2 = if ORHigh2[1] == 0 or ORActive2[1] == 0 and ORActive2 == 1 then h else if ORActive2 and h > ORHigh2[1] then h else ORHigh2[1];
def ORLow2 = if ORLow2[1] == 0 or ORActive2[1] == 0 and ORActive2 == 1 then l else if ORActive2 and l < ORLow2[1] then l else ORLow2[1];
def ORWidth2 = ORHigh2 - ORLow2;
def TimeLine = if SecondsTillTime(ORB_HL_Start) == 0 then 1 else 0;
def ORmeanBar = if !ORActive and ORActive[1] then BarNumber() else ORmeanBar[1];
def ORendBar = if !ORActive2 and ORActive2[1]
then BarNumber() else ORendBar[1];
def ORL = If (O == 0 , na, O);
def ORH2 = if ORActive2 or today < 1 then na else ORHigh2;

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

ORB_BAL.SetDefaultColor(Color.YELLOW);
ORB_BAL.SetStyle(Curve.LONG_DASH);
ORB_BAL.SetLineWeight(3);
ORB_BAL.HideTitle();

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

ORB_H.SetDefaultColor(Color.GREEN);
ORB_H.SetStyle(Curve.LONG_DASH);
ORB_H.SetLineWeight(3);
ORB_H.HideTitle();

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

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

ORB_L.SetDefaultColor(Color.RED);
ORB_L.SetStyle(Curve.LONG_DASH);
ORB_L.SetLineWeight(3);
ORB_L.HideTitle();

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

AddCloud(if CloudOn_ORB and rthrs == yes then ORL else Double.NaN, ORL2, Color.Light_Red, Color.Light_Red);
AddCloud(if CloudOn_ORB and rthrs == yes then ORL else Double.NaN, ORH2, Color.Green, Color.Green);

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

AddChartBubble(bubble_ORB and mover_ORB, ORB_H[bubblemover_ORB], "IB_H" + AsText(ORB_H[bubblemover_ORB]), ORB_H.TakeValueColor());
AddChartBubble(bubble_ORB and mover_ORB, ORB_L[bubblemover_ORB], "IB_L" + AsText(ORB_L[bubblemover_ORB]), ORB_L.TakeValueColor());
AddChartBubble(bubble_ORB and mover_ORB, ORB_BAL[bubblemover_ORB], "BAL" + AsText(ORB_BAL[bubblemover_ORB]), ORB_BAL.TakeValueColor());
 
This is awesome. Can you also do the same fix for the ORB plots that has the same issues as well?
 

Attachments

  • Screenshot 2024-03-02 at 8.26.17 AM.png
    Screenshot 2024-03-02 at 8.26.17 AM.png
    307.2 KB · Views: 166

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

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

###########

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

###########

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

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

ORB_BAL.SetDefaultColor(Color.YELLOW);
ORB_BAL.SetStyle(Curve.LONG_DASH);
ORB_BAL.SetLineWeight(3);
ORB_BAL.HideTitle();

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

ORB_H.SetDefaultColor(Color.GREEN);
ORB_H.SetStyle(Curve.LONG_DASH);
ORB_H.SetLineWeight(3);
ORB_H.HideTitle();

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

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

ORB_L.SetDefaultColor(Color.RED);
ORB_L.SetStyle(Curve.LONG_DASH);
ORB_L.SetLineWeight(3);
ORB_L.HideTitle();

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

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

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

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

###########

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

###########

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

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

ORB_BAL.SetDefaultColor(Color.YELLOW);
ORB_BAL.SetStyle(Curve.LONG_DASH);
ORB_BAL.SetLineWeight(3);
ORB_BAL.HideTitle();

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

ORB_H.SetDefaultColor(Color.GREEN);
ORB_H.SetStyle(Curve.LONG_DASH);
ORB_H.SetLineWeight(3);
ORB_H.HideTitle();

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

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

ORB_L.SetDefaultColor(Color.RED);
ORB_L.SetStyle(Curve.LONG_DASH);
ORB_L.SetLineWeight(3);
ORB_L.HideTitle();

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

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

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

There were just pieces of missing code. The bubbles were already fixed in your code.

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

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


###########

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

###########

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

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

ORB_BAL.SetDefaultColor(Color.YELLOW);
ORB_BAL.SetStyle(Curve.LONG_DASH);
ORB_BAL.SetLineWeight(3);
ORB_BAL.HideTitle();

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

ORB_H.SetDefaultColor(Color.GREEN);
ORB_H.SetStyle(Curve.LONG_DASH);
ORB_H.SetLineWeight(3);
ORB_H.HideTitle();

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

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

ORB_L.SetDefaultColor(Color.RED);
ORB_L.SetStyle(Curve.LONG_DASH);
ORB_L.SetLineWeight(3);
ORB_L.HideTitle();

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

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

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

Ben's Swing Trading Strategy + Indicator

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

I'm Interested

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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