#OpeningRange_Developing_in_Separate_Cloud_Color
script r {
input oTime = 2300;
input cTime = 0500;
input extend = yes;
input showlastonly = yes;
def sec1 = SecondsFromTime(oTime);
def sec2 = SecondsFromTime(cTime);
def isTime1 = (sec1 >= 0 and sec1[1] < 0) or (sec1 < sec1[1] and sec1 >= 0);
def isTime2 = (sec2 >= 0 and sec2[1] < 0) or (sec2 < sec2[1] and sec2 >= 0);
def inRange = CompoundValue(1, if isTime1 then 1 else if isTime2 then 0 else inRange[1], 0);
def bars = 200000;
input pricePerRowHeightMode = { AUTOMATIC, default TICKSIZE, CUSTOM};
input customRowHeight = 1.0;
input timePerProfile = {default BAR};
input onExpansion = no;
input profiles = 1000;
def period;
switch (timePerProfile) {
case BAR:
period = BarNumber() - 1;
}
def count = CompoundValue(1, if inRange and period != period[1] then (count[1] + period - period[1]) % bars else count[1], 0);
def cond = count < count[1] + period - period[1];
def height;
switch (pricePerRowHeightMode) {
case AUTOMATIC:
height = PricePerRow.AUTOMATIC;
case TICKSIZE:
height = PricePerRow.TICKSIZE;
case CUSTOM:
height = customRowHeight;
}
profile vol = VolumeProfile("startNewProfile" = cond, "onExpansion" = no, "numberOfProfiles" = 1000, "pricePerRow" = height, "value area percent" = 0);
def con = CompoundValue(1, onExpansion, no);
def hProfile = if inRange and IsNaN(vol.GetHighest()) and con then hProfile[1] else vol.GetHighest();
def lProfile = if inRange and IsNaN(vol.GetLowest()) and con then lProfile[1] else vol.GetLowest();
def plotsDomain = IsNaN(close) == onExpansion;
def ProfileHigh = if inRange and plotsDomain then hProfile else if extend then ProfileHigh[1] else Double.NaN;
def ProfileLow = if inRange and plotsDomain then lProfile else if extend then ProfileLow[1] else Double.NaN;
def dataCount = CompoundValue(1, if cond != cond[1] then dataCount[1] + 1 else dataCount[1] , 0);
plot hrange = if !showlastonly then ProfileHigh else if showlastonly and HighestAll(dataCount) - dataCount <= if cTime <= 0000 then 2 else 1 then ProfileHigh else Double.NaN;
plot lrange = if !showlastonly then ProfileLow else if showlastonly and HighestAll(dataCount) - dataCount <= if cTime <= 0000 then 2 else 1 then ProfileLow else Double.NaN;
}
input showclouds = yes;
input showbubbles = yes;
input showbubble_times = yes;
input showlastonly = yes;
input otime1 = 0930;
input ctime1 = 1030;
#Horizontal Lines - Separate input for line_extend was necessary as request was for extended lines, whereas the clouds were not wanted to extend by the times input
input line_extend = yes;
plot r1h = r(otime1, ctime1, extend = line_extend, showlastonly = showlastonly);
plot r1l = r(otime1, ctime1, extend = line_extend, showlastonly = showlastonly).lrange;
plot mid = (r1h + r1l) / 2;
DefineGlobalColor("H", Color.LIGHT_GREEN);
DefineGlobalColor("L", Color.LIGHT_RED);
r1h.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
r1l.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
r1h.SetDefaultColor(GlobalColor("H"));
r1l.SetDefaultColor(GlobalColor("L"));
#Clouds - Cloud plots for cloud1-3 hl are needed
input cloud_extend = no;
plot cloud1h = r(otime1, ctime1, extend = cloud_extend, showlastonly = showlastonly);
plot cloud1l = r(otime1, ctime1, extend = cloud_extend, showlastonly = showlastonly).lrange;
DefineGlobalColor("OR", Color.WHITE);
DefineGlobalColor("OR EXT", Color.CYAN);
input show_cloud_1 = yes;
input show_cloud_2 = yes;
AddCloud(if showclouds and show_cloud_1 then r(otime1, ctime1, extend = no, showlastonly = showlastonly) else Double.NaN, r(otime1, ctime1, extend = no, showlastonly = showlastonly).lrange, GlobalColor("OR"), GlobalColor("OR"));
AddCloud(if showclouds and show_cloud_2 and SecondsFromTime(ctime1) >= 0 then r(otime1, ctime1, extend = yes, showlastonly = showlastonly) else Double.NaN, r(otime1, ctime1, extend = yes, showlastonly = showlastonly).lrange, GlobalColor("OR EXT"), GlobalColor("OR EXT"));
input bubblemover = 5;
def b = bubblemover;
def b1 = b + 1;
def mover = showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]);
AddChartBubble(mover, r1h[b1],
if showbubble_times then AsPrice(otime1) + " : " + AsPrice(ctime1) + "\nH: " + AsText(r1h) else "H: " + AsText(r1h), r1h.TakeValueColor());
AddChartBubble(mover, r1l,
if showbubble_times then AsPrice(otime1) + " : " + AsPrice(ctime1) + "\nL: " + AsText(r1l) else "L: " + AsText(r1l), r1l.TakeValueColor(), up = no);
AddChartBubble(mover, mid,
if showbubble_times then AsPrice(otime1) + " : " + AsPrice(ctime1) + "\nM: " + AsText(mid) else "M: " + AsText(mid), mid.TakeValueColor(), up = no);
#