DudeDastic
Member
Ok guys and gals, here's my attempt at coding the average volume by time block labels indicator (don't know what he calls it) sometimes seen on Carmine Rosato's YouTube videos.
Updated 02/03/2022
This code only works on a 5 minute chart. Keep in mind that it doesn't take into account the amount of dollar moves in those intervals, only volume. With a few modifications, it can be made to work with dollar volume. Also, it seems to produce different values depending on whether you have extended hours on or off. And the averages are off by a few points (perhaps rounding is the issue?)
Hope this helps. Any additional help in making it more accurate and/or less resource intensive is greatly appreciated.
Updated 02/03/2022
Code:
script VolumeByTime {
input startTime = 0930;
input endTime = 0934;
def Active = SecondsFromTime(startTime) >= 0 and SecondsTillTime(endTime) >= 0;
def VolMins = if Active and !Active[1] then volume
else if Active then VolMins[1] + volume
else VolMins[1];
plot cumulativeVolume = VolMins;
}
script BarsPerDay {
input length = 5; # number of days
def bpd = 78; # the total number of bars (candles) during regular trading hours on a 5 minute chart
plot cumVolumePref = (fold e = 1 to (length + 1) with v = 0 do v + getValue(volume, (bpd * e))) / length;
}
declare upper;
declare hide_on_daily;
input length = 5; # Number of days
input unusualVolume = 100;
input showLabels = yes;
AddLabel(showLabels, "Avg. " + length + "-day Volumes", Color.White);
### first 5 minutes
def IsActive5 = SecondsFromTime(0930) >= 0 and SecondsTillTime(0934) >= 0;
def cumVolume5 = Round(VolumeByTime(0930, 0934).cumulativeVolume, 0);
def cumVolumePrev5 = Round(if IsActive5 and !IsActive5[1]
then BarsPerDay(length).cumVolumePref
else if IsActive5 then cumVolumePrev5[1] + BarsPerDay(length).cumVolumePref
else cumVolumePrev5[1], 0);
def Avg5 = Round((cumVolume5 / cumvolumePrev5) * 100, 0);
AddLabel(GetAggregationPeriod() <= AggregationPeriod.FIVE_MIN && showLabels, "Avg 5m: " + cumVolumePrev5, Color.Light_Gray);
AddLabel(GetAggregationPeriod() <= AggregationPeriod.FIVE_MIN && showLabels, "Today: " + cumvolume5 + " | " + AsPercent(Avg5 / 100), (if avg5 >= unusualVolume then Color.Green else if avg5 >= 100 then Color.Orange else Color.Light_Gray));
### first 15 minutes
def IsActive15 = SecondsFromTime(0930) >= 0 and SecondsTillTime(0944) >= 0;
def cumVolume15 = Round(VolumeByTime(0930, 0944).cumulativeVolume, 0);
def cumVolumePrev15 = Round(if IsActive15 and !IsActive15[1]
then BarsPerDay(length).cumVolumePref
else if IsActive15 then cumVolumePrev15[1] + BarsPerDay(length).cumVolumePref
else cumVolumePrev15[1], 0);
def Avg15 = Round((cumVolume15 / cumvolumePrev15) * 100, 0);
AddLabel(GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN && showLabels, "Avg 15m: " + cumVolumePrev15, Color.Light_Gray);
AddLabel(GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN && showLabels, "Today: " + cumvolume15 + " | " + AsPercent(Avg15 / 100), (if avg15 >= unusualVolume then Color.Green else if avg15 >= 100 then Color.Orange else Color.Light_Gray));
### first 30 minutes
def IsActive30 = SecondsFromTime(0930) >= 0 and SecondsTillTime(0959) >= 0;
def cumVolume30 = Round(VolumeByTime(0930, 0959).cumulativeVolume, 0);
def cumVolumePrev30 = Round(if IsActive30 and !IsActive30[1]
then BarsPerDay(length).cumVolumePref
else if IsActive30 then cumVolumePrev30[1] + BarsPerDay(length).cumVolumePref
else cumVolumePrev30[1], 0);
def Avg30 = Round((cumVolume30 / cumvolumePrev30) * 100, 0);
AddLabel(GetAggregationPeriod() <= AggregationPeriod.THIRTY_MIN && showLabels, "Avg 30m: " + cumVolumePrev30, Color.Light_Gray);
AddLabel(GetAggregationPeriod() <= AggregationPeriod.THIRTY_MIN && showLabels, "Today: " + cumvolume30 + " | " + AsPercent(Avg30 / 100), (if avg30 >= unusualVolume then Color.Green else if avg30 >= 100 then Color.Orange else Color.Light_Gray));
### first hour
def IsActive1H = SecondsFromTime(0930) >= 0 and SecondsTillTime(1029) >= 0;
def cumVolume1H = Round(VolumeByTime(0930, 1029).cumulativeVolume, 0);
def cumVolumePrev1H = Round(if IsActive1H and !IsActive1H[1]
then BarsPerDay(length).cumVolumePref
else if IsActive1H then cumVolumePrev1H[1] + BarsPerDay(length).cumVolumePref
else cumVolumePrev1H[1], 0);
def Avg1H = Round((cumVolume1H / cumvolumePrev1H) * 100, 0);
AddLabel(GetAggregationPeriod() <= AggregationPeriod.HOUR && showLabels, "Avg 1h: " + cumVolumePrev1H, Color.Light_Gray);
AddLabel(GetAggregationPeriod() <= AggregationPeriod.HOUR && showLabels, "Today: " + cumvolume1H + " | " + AsPercent(Avg1H / 100), (if avg1H >= unusualVolume then Color.Green else if avg1H >= 100 then Color.Orange else Color.Light_Gray));
### first 90 minutes (1h 30m)
def IsActive90 = SecondsFromTime(0930) >= 0 and SecondsTillTime(1059) >= 0;
def cumVolume90 = Round(VolumeByTime(0930, 1059).cumulativeVolume, 0);
def cumVolumePrev90 = Round(if IsActive90 and !IsActive90[1]
then BarsPerDay(length).cumVolumePref
else if IsActive90 then cumVolumePrev90[1] + BarsPerDay(length).cumVolumePref
else cumVolumePrev90[1], 0);
def Avg90 = Round((cumVolume90 / cumvolumePrev90) * 100, 0);
AddLabel(showLabels, "Avg 90m: " + cumVolumePrev90, Color.Light_Gray);
AddLabel(showLabels, "Today: " + cumvolume90 + " | " + AsPercent(Avg90 / 100), (if avg90 >= unusualVolume then Color.Green else if avg90 >= 100 then Color.Orange else Color.Light_Gray));
### first 4 hours
def IsActive4H = SecondsFromTime(0930) >= 0 and SecondsTillTime(1329) >= 0;
def cumVolume4H = Round(VolumeByTime(0930, 1329).cumulativeVolume, 0);
def cumVolumePrev4H = Round(if IsActive4H and !IsActive4H[1]
then BarsPerDay(length).cumVolumePref
else if IsActive4H then cumVolumePrev4H[1] + BarsPerDay(length).cumVolumePref
else cumVolumePrev4H[1], 0);
def Avg4H = Round((cumVolume4H / cumvolumePrev4H) * 100, 0);
AddLabel(GetAggregationPeriod() <= AggregationPeriod.FOUR_HOURS && showLabels, "Avg 4h: " + cumVolumePrev4H, Color.Light_Gray);
AddLabel(GetAggregationPeriod() <= AggregationPeriod.FOUR_HOURS && showLabels, "Today: " + cumvolume4H + " | " + AsPercent(Avg4H / 100), (if avg4H >= unusualVolume then Color.Green else if avg4H >= 100 then Color.Orange else Color.Light_Gray));
This code only works on a 5 minute chart. Keep in mind that it doesn't take into account the amount of dollar moves in those intervals, only volume. With a few modifications, it can be made to work with dollar volume. Also, it seems to produce different values depending on whether you have extended hours on or off. And the averages are off by a few points (perhaps rounding is the issue?)
Hope this helps. Any additional help in making it more accurate and/or less resource intensive is greatly appreciated.
Last edited: