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
input showriskbubbles = no;
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;
input b = 5;
def b1 = b + 1;
AddChartBubble(showriskbubbles and !isnan(close[b1]) and isnan(close), ORLriskUP, "ROn \nORH", 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;
input bb = 5;
def bb1 = bb + 1;
AddChartBubble(showriskbubbles and !isnan(close[bb1]) and isnan(close[bb]), HighestAll(ORLriskDN[bb1]), "ROn \nORL", 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();
input a = 2;
def a1 = a + 1;
AddChartBubble(showriskbubbles and !isnan(close[a1]) and isnan(close[a]), Htarget[a1], "ROff", Color.WHITE, if c[a1] > Htarget[a1] 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();
input aa = 2;
def aa1 = aa + 1;
AddChartBubble(showriskbubbles and !isnan(close[aa1]) and isnan(close[aa]), cond2[a1], "ROff", 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);
def cross = if c crosses above ORH2 then 1
else if c crosses below ORL2 then -1
else 0;
input showlabels = yes;
AddLabel(showlabels, if cross == 1 then "Crossing Above"
else if c > ORH2 then "Above" else "", Color.GREEN);
AddLabel(showlabels, if cross == -1 then "Crossing Below"
else if c < ORL2 then "Below" else "", Color.RED);
AddLabel(showlabels, if Between(c, ORL2, ORH2) then "Neutral" else "", Color.YELLOW);
# End Code ORB with Risk and targets