#HLCO_Range_Market_Times_Using_Automatic_Calculation_Of_Minutes
#
script times {
input a1 = 0930;
input b1 = 1600;
input showlastonly = no;
input extend_line = yes;
# Minutes #### Calculates the length between times a1 and b1 used to plot Close line back to sec1 onset
def minutes = If(a1 > b1,
((2300 - RoundDown(a1, -2)) / 100 * 60) + (RoundDown(b1, -2) / 100) * 60,
((RoundDown(b1, -2) / 100) - (RoundDown(a1, -2) / 100)) * 60) +
If(a1 > b1, 60 - (a1 - Floor(a1 / 100) * 100) + (b1 - Floor(b1 / 100) * 100), (b1 - Floor(b1 / 100) * 100) - (a1 - Floor(a1 / 100) * 100)) + 1;
# Range #### Defines range from a1 to b1
def sec1 = SecondsFromTime(a1);
def sec2 = SecondsFromTime(b1);
def inrange = CompoundValue(1, if sec1 == 0 then 1 else if sec2 > 0 then 0 else inrange[1], 0);
# Volumeprofile used to defineColor High/Low to start plotting at sec1 onset
def bars = 20000;
def 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];
profile vol = VolumeProfile("startNewProfile" = cond[1], "onExpansion" = no);
def hProfile = if inrange and IsNaN(vol.GetHighest()) then hProfile[1] else vol.GetHighest();
def lProfile = if inrange and IsNaN(vol.GetLowest()) then lProfile[1] else vol.GetLowest();
def ProfileHigh = if inrange then hProfile else if extend_line then ProfileHigh[1] else Double.NaN;
def ProfileLow = if inrange then lProfile else if extend_line then ProfileLow[1] else Double.NaN;
def dataCount = CompoundValue(1, if cond != cond[1] then dataCount[1] + 1 else dataCount[1] , 0);
# High #### using Volumeprofile
plot hrange = if !showlastonly then ProfileHigh
else if showlastonly and HighestAll(dataCount) - dataCount <= if b1 <= 0000 then 2 else 1
then ProfileHigh else Double.NaN;
# Low #### using Volumeprofile
plot lrange = if !showlastonly then ProfileLow
else if showlastonly and HighestAll(dataCount) -
dataCount <= if b1 <= 0000 then 2 else 1
then ProfileLow else Double.NaN;
# Open #### using sec1 and sec2
def o = if sec1 == 0
then open
else if !extend_line and sec2 <= 0
then o[1]
else if extend_line then o[1] else Double.NaN;
plot orange = if !showlastonly then o
else if showlastonly and HighestAll(dataCount) -
dataCount <= if b1 <= 0000 then 2 else 1
then o else Double.NaN;
# Close #### using inrange and minutes offset
def dayc = if inrange[1] == 0 and inrange == 1
then close
else if inrange == 1
then close
else 0;
def daycl = if inrange[1] == 1 and inrange == 0
then dayc[1]
else daycl[1];
plot cend = if showlastonly and GetDay() != GetLastDay()
then Double.NaN
else if GetDay() <= GetLastDay() and inrange
then daycl[-minutes / (GetAggregationPeriod() / 60000)]
else if extend_line and sec2 > 0 then daycl[1]
else Double.NaN;
} # End Times Script
input showlastonly = no;
input show_cloud = yes;
input start1 = 0930;
input end1 = 0959;
input extendline = no;
plot high1 = times(start1, end1, showlastonly = showlastonly, extend_line = extendline).hrange;
plot low1 = times(start1, end1, showlastonly = showlastonly, extend_line = extendline).lrange;
plot close1 = times(start1, end1, showlastonly = showlastonly, extend_line = extendline).cend;
plot open1 = times(start1, end1, showlastonly = showlastonly, extend_line = extendline).orange;#
close1.SetPaintingStrategy(PaintingStrategy.DASHES);
open1.SetPaintingStrategy(PaintingStrategy.POINTS);
DefineGlobalColor("H", Color.GREEN);
DefineGlobalColor("L", Color.RED);
DefineGlobalColor("O", Color.WHITE);
DefineGlobalColor("C", Color.YELLOW);
high1.SetDefaultColor(GlobalColor("H"));
low1.SetDefaultColor(GlobalColor("L"));
close1.SetDefaultColor(GlobalColor("C"));
open1.SetDefaultColor(GlobalColor("O"));
# Cloud **************
DefineGlobalColor("Cloud", Color.LIGHT_GRAY);
AddCloud(if show_cloud then high1 else Double.NaN, low1, GlobalColor("Cloud"), GlobalColor("Cloud"));
# End Code