#VolumeProfile_Defined_Time
#Lines extended beyond range (begin - end) til input until time
input begin = 0400;
input end = 0920;
input until = 1130;
input pricePerRowHeightMode = { default AUTOMATIC, TICKSIZE, CUSTOM};
input customRowHeight = 1.0;
input timePerProfile = { CHART, MINUTE, HOUR, default DAY, WEEK, MONTH, "OPT EXP", BAR};
input multiplier = 1;
input onExpansion = no;
input profiles = 2;
input showPointOfControl = yes;
def range = if SecondsFromTime(begin) >= 0 and SecondsTillTime(end) >= 0 then 1 else 0;
def cond = range != range[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" = onExpansion, "numberOfProfiles" = profiles, "pricePerRow" = height, "value area percent" = 70);
def con = CompoundValue(1, onExpansion, no);
def pc = if range == 0 then pc[1] else if IsNaN(vol.GetPointOfControl()) and con then pc[1] else vol.GetPointOfControl();
def hVA = if range == 0 then hVA[1] else if IsNaN(vol.GetHighestValueArea()) and con then hVA[1] else vol.GetHighestValueArea();
def lVA = if range == 0 then lVA[1] else if IsNaN(vol.GetLowestValueArea()) and con then lVA[1] else vol.GetLowestValueArea();
def plotsDomain = IsNaN(close) == onExpansion;
plot POC = if plotsDomain and SecondsTillTime(until) > 0 then pc else Double.NaN;
plot VAHigh = if plotsDomain and SecondsTillTime(until) > 0 then hVA else Double.NaN;
plot VALow = if plotsDomain and SecondsTillTime(until) > 0 then lVA else Double.NaN;
DefineGlobalColor("Point of Control", Color.RED);
DefineGlobalColor("Value Area", Color.LIGHT_GRAY);
POC.SetDefaultColor(GlobalColor("Point Of Control"));
POC.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VALow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAHigh.SetDefaultColor(GlobalColor("Value Area"));
VALow.SetDefaultColor(GlobalColor("Value Area"));
input showcloud = yes;
AddCloud(if showcloud then VAHigh else Double.NaN, VALow, GlobalColor("Value Area"), GlobalColor("Value Area") );
####### Watchlist
def extended_range = if SecondsFromTime(begin) >= 0 and SecondsTillTime(until) >= 0 then 1 else 0;
input near_percent = .3;
input show_expanded_vahigh_valow_lines = no;
plot vahigh_expanded = VAHigh * (1 + near_percent / 100);
plot valow_expanded = VALow * (1 - near_percent / 100);
vahigh_expanded.SetHiding(!show_expanded_vahigh_valow_lines);
valow_expanded.SetHiding(!show_expanded_vahigh_valow_lines);
def near_cond =
if extended_range
then if Between(close, VAHigh, vahigh_expanded) or Between(close, valow_expanded, VALow)
then 1
else if Between(close, VALow, VAHigh)
then 2
else 3
else Double.NaN;
input show_bubbles = yes;
AddChartBubble(show_bubbles and extended_range, low * .9995, near_cond, if near_cond == 1 then Color.YELLOW else if near_cond == 2 then Color.RED else Color.GRAY, no);
input show_watchlist_label = yes;
AddLabel(show_watchlist_label, near_cond, if near_cond == 1 then Color.YELLOW else if near_cond == 2 then Color.RED else Color.GRAY);