#hint: Virtual Volume
# Mr.Script
#Explanation - Virtual Volume analyzes up to the second volume and displays the anticipated volume quantity for the day.
• Example - 6.5 hours in a trading day or 390 minutes or 23,400 seconds. If I check the volume for a stock and we are 33 minutes or 1980 seconds into the trading day and volume is 537,500. The formula would be (23,400 x 537,500) / 1980 = 6,352,272.727 Virtual Volume.
declare hide_on_daily;
declare on_volume;
input OpenTime = 0930;
input closeTime = 1600;
input length = 10;
input averageType = AverageType.EXPONENTIAL;
assert(Opentime < 1200, "Open Time must be less than 1200");
assert(closetime > 1200, "close Time must be greater than 1200");
def volumeavg = MovingAverage(averageType, volume(period = aggregationPeriod.DAY), length);
def hoursa = floor(closetime/100);
def hoursb = floor(opentime/100);
def hoursc = absValue(12 - hoursb) + hoursa - 12;
def hoursd = hoursc * 60 * 60;
def mina = ((closetime - ((floor(closetime/100)) * 100)) * 60);
def minb = ((opentime - ((floor(opentime/100)) * 100)) * 60);
def secondsperday = absValue(hoursd - (minb - mina));
def secondsPassed = secondsFromTime(OpenTime);
def a = if secondsPassed >= 0 and secondspassed <= (closetime * 60 * 60) then secondspassed else 0;
rec b = CompoundValue(1, if IsNaN(a) then b[1] else a, a);
def day = getDay();
def month = getMonth();
def year = getYear();
def lastDay = getLastDay();
def lastmonth = getLastMonth();
def lastyear = getLastYear();
def isToday = if(day == lastDay and month == lastmonth and year == lastyear, 1, 0);
def d = if istoday then b else double.nan;
def h = if secondsPassed >= 0 and secondspassed <= (closetime * 60 * 60) and close == close(period = aggregationPeriod.DAY) then secondspassed else 0;
def vol = if istoday then volume else 0;
rec index = compoundValue(1, index[1] + vol, 0);
plot "Cumulative Volume" = if secondsPassed >= 0 and secondsFromTime(closetime) <= 0 and istoday then index else double.nan;
def j = "cumulative volume";
def k = highestall(j);
def l = if j == k then secondspassed else double.nan;
def m = highestall(l);
def n = (secondsperday * k) / m;
addLabel(yes, concat("Virtual Volume: ", round(n, 0)), if (n > volumeavg) then Color.GREEN else color.RED);
addLabel(yes, concat(concat(length, " Day's"), concat(" Volume Avg: ", round(volumeavg, 0))), if (n < volumeavg) then Color.GREEN else color.RED);
# end study code ---