#HorizonalLines_High_Low_Multiple_Time_Ranges
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 = 2000;
input ctime1 = 0000;
input otime2 = 0200;
input ctime2 = 0500;
input otime3 = 0830;
input ctime3 = 0930;
#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 r2h = r(otime2, ctime2, extend = line_extend, showlastonly = showlastonly);
plot r2l = r(otime2, ctime2, extend = line_extend, showlastonly = showlastonly).lrange;
plot r3h = r(otime3, ctime3, extend = line_extend, showlastonly = showlastonly);
plot r3l = r(otime3, ctime3, extend = line_extend, showlastonly = showlastonly).lrange;
DefineGlobalColor("H", Color.LIGHT_GREEN);
DefineGlobalColor("L", Color.LIGHT_RED);
r1h.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
r1l.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
r2h.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
r2l.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
r3h.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
r3l.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
r1h.SetDefaultColor(GlobalColor("H"));
r1l.SetDefaultColor(GlobalColor("L"));
r2h.SetDefaultColor(GlobalColor("H"));
r2l.SetDefaultColor(GlobalColor("L"));
r3h.SetDefaultColor(GlobalColor("H"));
r3l.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;
plot cloud2h = r(otime2, ctime2, extend = cloud_extend, showlastonly = showlastonly);
plot cloud2l = r(otime2, ctime2, extend = cloud_extend, showlastonly = showlastonly).lrange;
plot cloud3h = r(otime3, ctime3, extend = cloud_extend, showlastonly = showlastonly);
plot cloud3l = r(otime3, ctime3, extend = cloud_extend, showlastonly = showlastonly).lrange;
AddCloud(if showclouds then cloud1h else Double.NaN, cloud1l, Color.CYAN, Color.CYAN);
AddCloud(if showclouds then cloud2h else Double.NaN, cloud2l, Color.CYAN, Color.CYAN);
AddCloud(if showclouds then cloud3h else Double.NaN, cloud3l, Color.CYAN, Color.CYAN);
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) + "\n" + r1h else "" + AsText(r1h), r1h.TakeValueColor());
AddChartBubble(mover, r1l,
if showbubble_times then AsPrice(otime1) + " : " + AsPrice(ctime1) + "\n" + r1l else "" + AsText(r1l), r1l.TakeValueColor(), up = no);
AddChartBubble(mover, r2h,
if showbubble_times then AsPrice(otime2) + " : " + AsPrice(ctime2) + "\n" + r2h else "" + AsText(r2h), r2h.TakeValueColor());
AddChartBubble(mover , r2l,
if showbubble_times then AsPrice(otime2) + " : " + AsPrice(ctime2) + "\n" + r2l else "" + AsText(r2l), r2l.TakeValueColor(), up = no);
AddChartBubble(mover, r3h,
if showbubble_times then AsPrice(otime3) + " : " + AsPrice(ctime3) + "\n" + r3h else "" + AsText(r3h), r3h.TakeValueColor());
AddChartBubble(mover, r3l,
if showbubble_times then AsPrice(otime3) + " : " + AsPrice(ctime3) + "\n" + r3l else "" + AsText(r3l), r3l.TakeValueColor(), up = no);