Investitrade's Average Volume by Time Block Imitation For ThinkOrSwim

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
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:
And here's the code for dollar volume (I think I've calculated it correctly):

Updated 03/07/2022
Code:
script DVByTime {
    input startTime = 0930;
    input endTime = 0934;
    input price = close;
    def Active   = SecondsFromTime(startTime) >= 0 and SecondsTillTime(endTime) >= 0;
    def dv = (price * volume / 1000000);
    def VolMins  = if Active and !Active[1] then dv
                   else if Active then VolMins[1] + dv
                   else VolMins[1];
    plot "$Vol"  = VolMins;
}

script BarsPerDay {
    input length = 5; # number of days
    input price = close;
    def dv = (price * volume / 1000000);
    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(dv, (bpd * e))) / length; # calculates dollar volume by all bars per day times the given back period plus a day
}


declare upper;
declare hide_on_daily;

input length = 5; # Number of days
input price = close;
input unusualVolume = 200;
input showLabels = yes;

AddLabel(showLabels, "Avg. " + length + "-day $Vols", Color.White);

### first 5 minutes
def IsActive5  = SecondsFromTime(0930) >= 0 and SecondsTillTime(0934) >= 0;
# cumulative volume from start time to given end time
def cumVolume5 = Round(DVByTime(0930, 0934, price)."$Vol", 0);
# This is the average cumulative volume over the same time period from the previous x days (x = length)
def cumVolumePrev5 = Round(if IsActive5 and !IsActive5[1]
                     then BarsPerDay(length, price).cumVolumePref
                     else if IsActive5 then cumVolumePrev5[1] + BarsPerDay(length, price).cumVolumePref
                     else cumVolumePrev5[1], 0);
def Avg5 = Round((cumVolume5 / cumvolumePrev5) * 100, 0);
AddLabel(GetAggregationPeriod() <= AggregationPeriod.FIVE_MIN && showLabels, "Avg 5m: " + AsDollars(cumVolumePrev5 / 100), Color.Light_Gray);
AddLabel(GetAggregationPeriod() <= AggregationPeriod.FIVE_MIN && showLabels, "Today: " + AsDollars(cumvolume5 / 100) + " | " + 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(DVByTime(0930, 0944, price)."$Vol", 0);
def cumVolumePrev15 = Round(if IsActive15 and !IsActive15[1]
                      then BarsPerDay(length, price).cumVolumePref
                      else if IsActive15 then cumVolumePrev15[1] + BarsPerDay(length, price).cumVolumePref
                      else cumVolumePrev15[1], 0);
def Avg15 = Round((cumVolume15 / cumvolumePrev15) * 100, 0);
AddLabel(GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN && showLabels, "Avg 15m: " + AsDollars(cumVolumePrev15 / 100), Color.Light_Gray);
AddLabel(GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN && showLabels, "Today: " + AsDollars(cumvolume15 / 100) + " | " + 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(DVByTime(0930, 0959, price)."$Vol", 0);
def cumVolumePrev30 = Round(if IsActive30 and !IsActive30[1]
                      then BarsPerDay(length, price).cumVolumePref
                      else if IsActive30 then cumVolumePrev30[1] + BarsPerDay(length, price).cumVolumePref
                      else cumVolumePrev30[1], 0);
def Avg30 = Round((cumVolume30 / cumvolumePrev30) * 100, 0);
AddLabel(GetAggregationPeriod() <= AggregationPeriod.THIRTY_MIN && showLabels, "Avg 30m: " + AsDollars(cumVolumePrev30 / 100), Color.Light_Gray);
AddLabel(GetAggregationPeriod() <= AggregationPeriod.THIRTY_MIN && showLabels, "Today: " + AsDollars(cumvolume30 / 100) + " | " + 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(DVByTime(0930, 1029, price)."$Vol", 0);
def cumVolumePrev1H = Round(if IsActive1H and !IsActive1H[1]
                      then BarsPerDay(length, price).cumVolumePref
                      else if IsActive1H then cumVolumePrev1H[1] + BarsPerDay(length, price).cumVolumePref
                      else cumVolumePrev1H[1], 0);
def Avg1H = Round((cumVolume1H / cumvolumePrev1H) * 100, 0);
AddLabel(GetAggregationPeriod() <= AggregationPeriod.HOUR && showLabels, "Avg 1h: " + AsDollars(cumVolumePrev1H / 100), Color.Light_Gray);
AddLabel(GetAggregationPeriod() <= AggregationPeriod.HOUR && showLabels, "Today: " + AsDollars(cumvolume1H / 100) + " | " + 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(DVByTime(0930, 1059, price)."$Vol", 0);
def cumVolumePrev90 = Round(if IsActive90 and !IsActive90[1]
                      then BarsPerDay(length, price).cumVolumePref
                      else if IsActive90 then cumVolumePrev90[1] + BarsPerDay(length, price).cumVolumePref
                      else cumVolumePrev90[1], 0);
def Avg90 = Round((cumVolume90 / cumvolumePrev90) * 100, 0);
AddLabel(showLabels, "Avg 90m: " + AsDollars(cumVolumePrev90 / 100), Color.Light_Gray);
AddLabel(showLabels, "Today: " + AsDollars(cumvolume90 / 100) + " | " + 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(DVByTime(0930, 1329, price)."$Vol", 0);
def cumVolumePrev4H = Round(if IsActive4H and !IsActive4H[1]
                      then BarsPerDay(length, price).cumVolumePref
                      else if IsActive4H then cumVolumePrev4H[1] + BarsPerDay(length, price).cumVolumePref
                      else cumVolumePrev4H[1], 0);
def Avg4H = Round((cumVolume4H / cumvolumePrev4H) * 100, 0);
AddLabel(GetAggregationPeriod() <= AggregationPeriod.FOUR_HOURS && showLabels, "Avg 4h: " + AsDollars(cumVolumePrev4H / 100), Color.Light_Gray);
AddLabel(GetAggregationPeriod() <= AggregationPeriod.FOUR_HOURS && showLabels, "Today: " + AsDollars(cumvolume4H / 100) + " | " + AsPercent(Avg4H / 100), (if avg4H >= unusualVolume then Color.Green else if avg4H >= 100 then Color.Orange else Color.Light_Gray));
 
Last edited:
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.
Hi there, thank you so much for sharing this! I pulled some data to cross check the accuracy specifically on the 15m interval and it seems to be off/very low compared to pulled data. Do you know what might cause this to take place? I really hope I could help in some way as I think this indicator is incredibly valuable.

EDIT:

Sorry I missed the extended hours part, turning them off fixed things, but that really is a strange bug
 
Last edited:
Hi there, thank you so much for sharing this! I pulled some data to cross check the accuracy specifically on the 15m interval and it seems to be off/very low compared to pulled data. Do you know what might cause this to take place? I really hope I could help in some way as I think this indicator is incredibly valuable.

EDIT:

Sorry I missed the extended hours part, turning them off fixed things, but that really is a strange bug
The indicator is only meant to be used on a 5min chart.
 
script BarsPerDay {
input length = 5; # number of days
input price = close;

then this

declare upper;
declare hide_on_daily;

input length = 22; # Number of days
input price = close;
input unusualVolume = 200;
input showLabels = yes;

why did you use a length of 22 instead of 5 again for the dollar volume?
 
script BarsPerDay {
input length = 5; # number of days
input price = close;

then this

declare upper;
declare hide_on_daily;

input length = 22; # Number of days
input price = close;
input unusualVolume = 200;
input showLabels = yes;

why did you use a length of 22 instead of 5 again for the dollar volume?
That number is merely a placeholder; it's starter code, so to speak. You can change it.
 
any luck fixing Ext Hours bug?

is there a way to be able to add EXT hours?
 
Last edited by a moderator:
is there a way to be able to add EXT hours?
The essence of the indicator is designed for RTH.
Therefore it cannot be modified to extended hours
Ruby:
script DVByTime {
input startTime = 0930;
input endTime = 0934;
def bpd = 78; # the total number of bars (candles) during regular trading hours on a 5 minute chart
 
Figured it out.

Modified code posted below. I only modified the first 5, 15 and 30 minutes (as I only use those). The rest were kept as is (for reference) and were commented out.

Results are pretty close. Good enough for me.

Code:
# Dollar-Volumes by time block by DudeDastic
# Mod by NeoEon 06.29.22; Just first 5, 15 and 30 mins of RTH; Use 5 min aggregation chart; Turn of extended hours



script DVByTime {

    input startTime = 0930;

    input endTime = 0934;

    input price = close;

    def Active   = SecondsFromTime(startTime) >= 0 and SecondsTillTime(endTime) >= 0;

    ## def dv = (price * volume / 1000000);
    def dv = (hl2 * volume / 1000000);

    def VolMins  = if Active and !Active[1] then dv

                   else if Active then VolMins[1] + dv

                   else VolMins[1];

    plot "$Vol"  = VolMins;

}


script BarsPerDay {

    input length = 5; # number of days

    input price = close;

    def dv = (hl2 * volume / 1000000);

    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(dv, (bpd * e))) / length; # calculates dollar volume by all bars per day times the given back period plus a day

}



declare upper;

declare hide_on_daily;


input length = 5; # Number of days

input price = close;

input unusualVolume = 200;

input showLabels = yes;


AddLabel(showLabels, "Avg. " + length + "-day Dollar-volumes", Color.White);


### first 5 minutes

def IsActive5  = SecondsFromTime(0930) >= 0 and SecondsTillTime(0934) >= 0;

# cumulative volume from start time to given end time

def cumVolume5 = Round(DVByTime(0930, 0934, price)."$Vol", 0);

# This is the average cumulative volume over the same time period from the previous x days (x = length)

def cumVolumePrev5 = Round(if IsActive5 and !IsActive5[1]

                     then BarsPerDay(length, price).cumVolumePref

                     else if IsActive5 then cumVolumePrev5[1] + BarsPerDay(length, price).cumVolumePref

                     else cumVolumePrev5[1], 0);

def Avg5 = Round((cumVolume5 / cumvolumePrev5) * 100, 0);

## AddLabel(GetAggregationPeriod() <= AggregationPeriod.FIVE_MIN && showLabels, "Today: " + AsDollars(cumvolume5 / 100) + " | " + AsPercent(Avg5 / 100), (if avg5 >= unusualVolume then Color.Green else if avg5 >= 100 then Color.Orange else Color.Light_Gray));

AddLabel(GetAggregationPeriod() <= AggregationPeriod.FIVE_MIN && showLabels, "$ " + Round(cumvolume5,0) + " m" + " :first5min |" + AsPercent(Avg5 / 100), (if avg5 >= unusualVolume then Color.Red else if avg5 >= 100 then Color.Orange else Color.Cyan));


## AddLabel(GetAggregationPeriod() <= AggregationPeriod.FIVE_MIN && showLabels, "Avg 5m: " + AsDollars(cumVolumePrev5 / 100), Color.Light_Gray);

AddLabel(GetAggregationPeriod() <= AggregationPeriod.FIVE_MIN && showLabels, "$ " + Round(cumVolumePrev5,0) + " m" + " :Avg5min", Color.Light_Gray);




### first 15 minutes

def IsActive15  = SecondsFromTime(0930) >= 0 and SecondsTillTime(0944) >= 0;

def cumVolume15 = Round(DVByTime(0930, 0944, price)."$Vol", 0);

def cumVolumePrev15 = Round(if IsActive15 and !IsActive15[1]

                      then BarsPerDay(length, price).cumVolumePref

                      else if IsActive15 then cumVolumePrev15[1] + BarsPerDay(length, price).cumVolumePref

                      else cumVolumePrev15[1], 0);

def Avg15 = Round((cumVolume15 / cumvolumePrev15) * 100, 0);

## AddLabel(GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN && showLabels, "Today: " + AsDollars(cumvolume15 / 100) + " | " + AsPercent(Avg15 / 100), (if avg15 >= unusualVolume then Color.Green else if avg15 >= 100 then Color.Orange else Color.Light_Gray));

AddLabel(GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN && showLabels, "$ " + Round(cumvolume15,0) + " m" + " :first15min |" + AsPercent(Avg15 / 100), (if avg15 >= unusualVolume then Color.Red else if avg15 >= 100 then Color.Orange else Color.Cyan));

## AddLabel(GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN && showLabels, "Avg 15m: " + AsDollars(cumVolumePrev15 / 100), Color.Light_Gray);


AddLabel(GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN && showLabels, "$ " + Round(cumVolumePrev15,0) + " m" + " :Avg15min", Color.Light_Gray);




### first 30 minutes

def IsActive30  = SecondsFromTime(0930) >= 0 and SecondsTillTime(0959) >= 0;

def cumVolume30 = Round(DVByTime(0930, 0959, price)."$Vol", 0);

def cumVolumePrev30 = Round(if IsActive30 and !IsActive30[1]

                      then BarsPerDay(length, price).cumVolumePref

                      else if IsActive30 then cumVolumePrev30[1] + BarsPerDay(length, price).cumVolumePref

                      else cumVolumePrev30[1], 0);

def Avg30 = Round((cumVolume30 / cumvolumePrev30) * 100, 0);

## AddLabel(GetAggregationPeriod() <= AggregationPeriod.THIRTY_MIN && showLabels, "Today: " + AsDollars(cumvolume30 / 100) + " | " + AsPercent(Avg30 / 100), (if avg30 >= unusualVolume then Color.Green else if avg30 >= 100 then Color.Orange else Color.Light_Gray));


AddLabel(GetAggregationPeriod() <= AggregationPeriod.THIRTY_MIN && showLabels, "$ " + Round(cumvolume30,0) + " m" + " :first30min |" + AsPercent(Avg30 / 100), (if avg30 >= unusualVolume then Color.Red else if avg30 >= 100 then Color.Orange else Color.Cyan));


## AddLabel(GetAggregationPeriod() <= AggregationPeriod.THIRTY_MIN && showLabels, "Avg 30m: " + AsDollars(cumVolumePrev30 / 100), Color.Light_Gray);

AddLabel(GetAggregationPeriod() <= AggregationPeriod.THIRTY_MIN && showLabels, "$ " + Round(cumVolumePrev30,0) + " m" + " :Avg30min", Color.Light_Gray);




### first hour

def IsActive1H  = SecondsFromTime(0930) >= 0 and SecondsTillTime(1029) >= 0;

def cumVolume1H = Round(DVByTime(0930, 1029, price)."$Vol", 0);

def cumVolumePrev1H = Round(if IsActive1H and !IsActive1H[1]

                      then BarsPerDay(length, price).cumVolumePref

                      else if IsActive1H then cumVolumePrev1H[1] + BarsPerDay(length, price).cumVolumePref

                      else cumVolumePrev1H[1], 0);

def Avg1H = Round((cumVolume1H / cumvolumePrev1H) * 100, 0);

# AddLabel(GetAggregationPeriod() <= AggregationPeriod.HOUR && showLabels, "Avg 1h: " + AsDollars(cumVolumePrev1H / 100), Color.Light_Gray);

# AddLabel(GetAggregationPeriod() <= AggregationPeriod.HOUR && showLabels, "Today: " + AsDollars(cumvolume1H / 100) + " | " + 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(DVByTime(0930, 1059, price)."$Vol", 0);

def cumVolumePrev90 = Round(if IsActive90 and !IsActive90[1]

                      then BarsPerDay(length, price).cumVolumePref

                      else if IsActive90 then cumVolumePrev90[1] + BarsPerDay(length, price).cumVolumePref

                      else cumVolumePrev90[1], 0);

def Avg90 = Round((cumVolume90 / cumvolumePrev90) * 100, 0);

# AddLabel(showLabels, "Avg 90m: " + AsDollars(cumVolumePrev90 / 100), Color.Light_Gray);

# AddLabel(showLabels, "Today: " + AsDollars(cumvolume90 / 100) + " | " + 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(DVByTime(0930, 1329, price)."$Vol", 0);

def cumVolumePrev4H = Round(if IsActive4H and !IsActive4H[1]

                      then BarsPerDay(length, price).cumVolumePref

                      else if IsActive4H then cumVolumePrev4H[1] + BarsPerDay(length, price).cumVolumePref

                      else cumVolumePrev4H[1], 0);

def Avg4H = Round((cumVolume4H / cumvolumePrev4H) * 100, 0);

# AddLabel(GetAggregationPeriod() <= AggregationPeriod.FOUR_HOURS && showLabels, "Avg 4h: " + AsDollars(cumVolumePrev4H / 100), Color.Light_Gray);

# AddLabel(GetAggregationPeriod() <= AggregationPeriod.FOUR_HOURS && showLabels, "Today: " + AsDollars(cumvolume4H / 100) + " | " + AsPercent(Avg4H / 100), (if avg4H >= unusualVolume then Color.Green else if avg4H >= 100 then Color.Orange else Color.Light_Gray));
 
Last edited by a moderator:
Figured it out.

Modified code posted below. I only modified the first 5, 15 and 30 minutes (as I only use those). The rest were kept as is (for reference) and were commented out.

Results are pretty close. Good enough for me.

EQTRTPp.png


Code:
# Dollar-Volumes by time block by DudeDastic
# Mod by NeoEon 06.29.22; Just first 5, 15 and 30 mins of RTH; Use 5 min aggregation chart; Turn of extended hours



script DVByTime {

    input startTime = 0930;

    input endTime = 0934;

    input price = close;

    def Active   = SecondsFromTime(startTime) >= 0 and SecondsTillTime(endTime) >= 0;

    ## def dv = (price * volume / 1000000);
    def dv = (hl2 * volume / 1000000);

    def VolMins  = if Active and !Active[1] then dv

                   else if Active then VolMins[1] + dv

                   else VolMins[1];

    plot "$Vol"  = VolMins;

}


script BarsPerDay {

    input length = 5; # number of days

    input price = close;

    def dv = (hl2 * volume / 1000000);

    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(dv, (bpd * e))) / length; # calculates dollar volume by all bars per day times the given back period plus a day

}



declare upper;

declare hide_on_daily;


input length = 5; # Number of days

input price = close;

input unusualVolume = 200;

input showLabels = yes;


AddLabel(showLabels, "Avg. " + length + "-day Dollar-volumes", Color.White);


### first 5 minutes

def IsActive5  = SecondsFromTime(0930) >= 0 and SecondsTillTime(0934) >= 0;

# cumulative volume from start time to given end time

def cumVolume5 = Round(DVByTime(0930, 0934, price)."$Vol", 0);

# This is the average cumulative volume over the same time period from the previous x days (x = length)

def cumVolumePrev5 = Round(if IsActive5 and !IsActive5[1]

                     then BarsPerDay(length, price).cumVolumePref

                     else if IsActive5 then cumVolumePrev5[1] + BarsPerDay(length, price).cumVolumePref

                     else cumVolumePrev5[1], 0);

def Avg5 = Round((cumVolume5 / cumvolumePrev5) * 100, 0);

## AddLabel(GetAggregationPeriod() <= AggregationPeriod.FIVE_MIN && showLabels, "Today: " + AsDollars(cumvolume5 / 100) + " | " + AsPercent(Avg5 / 100), (if avg5 >= unusualVolume then Color.Green else if avg5 >= 100 then Color.Orange else Color.Light_Gray));

AddLabel(GetAggregationPeriod() <= AggregationPeriod.FIVE_MIN && showLabels, "$ " + Round(cumvolume5,0) + " m" + " :first5min |" + AsPercent(Avg5 / 100), (if avg5 >= unusualVolume then Color.Red else if avg5 >= 100 then Color.Orange else Color.Cyan));


## AddLabel(GetAggregationPeriod() <= AggregationPeriod.FIVE_MIN && showLabels, "Avg 5m: " + AsDollars(cumVolumePrev5 / 100), Color.Light_Gray);

AddLabel(GetAggregationPeriod() <= AggregationPeriod.FIVE_MIN && showLabels, "$ " + Round(cumVolumePrev5,0) + " m" + " :Avg5min", Color.Light_Gray);




### first 15 minutes

def IsActive15  = SecondsFromTime(0930) >= 0 and SecondsTillTime(0944) >= 0;

def cumVolume15 = Round(DVByTime(0930, 0944, price)."$Vol", 0);

def cumVolumePrev15 = Round(if IsActive15 and !IsActive15[1]

                      then BarsPerDay(length, price).cumVolumePref

                      else if IsActive15 then cumVolumePrev15[1] + BarsPerDay(length, price).cumVolumePref

                      else cumVolumePrev15[1], 0);

def Avg15 = Round((cumVolume15 / cumvolumePrev15) * 100, 0);

## AddLabel(GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN && showLabels, "Today: " + AsDollars(cumvolume15 / 100) + " | " + AsPercent(Avg15 / 100), (if avg15 >= unusualVolume then Color.Green else if avg15 >= 100 then Color.Orange else Color.Light_Gray));

AddLabel(GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN && showLabels, "$ " + Round(cumvolume15,0) + " m" + " :first15min |" + AsPercent(Avg15 / 100), (if avg15 >= unusualVolume then Color.Red else if avg15 >= 100 then Color.Orange else Color.Cyan));

## AddLabel(GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN && showLabels, "Avg 15m: " + AsDollars(cumVolumePrev15 / 100), Color.Light_Gray);


AddLabel(GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN && showLabels, "$ " + Round(cumVolumePrev15,0) + " m" + " :Avg15min", Color.Light_Gray);




### first 30 minutes

def IsActive30  = SecondsFromTime(0930) >= 0 and SecondsTillTime(0959) >= 0;

def cumVolume30 = Round(DVByTime(0930, 0959, price)."$Vol", 0);

def cumVolumePrev30 = Round(if IsActive30 and !IsActive30[1]

                      then BarsPerDay(length, price).cumVolumePref

                      else if IsActive30 then cumVolumePrev30[1] + BarsPerDay(length, price).cumVolumePref

                      else cumVolumePrev30[1], 0);

def Avg30 = Round((cumVolume30 / cumvolumePrev30) * 100, 0);

## AddLabel(GetAggregationPeriod() <= AggregationPeriod.THIRTY_MIN && showLabels, "Today: " + AsDollars(cumvolume30 / 100) + " | " + AsPercent(Avg30 / 100), (if avg30 >= unusualVolume then Color.Green else if avg30 >= 100 then Color.Orange else Color.Light_Gray));


AddLabel(GetAggregationPeriod() <= AggregationPeriod.THIRTY_MIN && showLabels, "$ " + Round(cumvolume30,0) + " m" + " :first30min |" + AsPercent(Avg30 / 100), (if avg30 >= unusualVolume then Color.Red else if avg30 >= 100 then Color.Orange else Color.Cyan));


## AddLabel(GetAggregationPeriod() <= AggregationPeriod.THIRTY_MIN && showLabels, "Avg 30m: " + AsDollars(cumVolumePrev30 / 100), Color.Light_Gray);

AddLabel(GetAggregationPeriod() <= AggregationPeriod.THIRTY_MIN && showLabels, "$ " + Round(cumVolumePrev30,0) + " m" + " :Avg30min", Color.Light_Gray);




### first hour

def IsActive1H  = SecondsFromTime(0930) >= 0 and SecondsTillTime(1029) >= 0;

def cumVolume1H = Round(DVByTime(0930, 1029, price)."$Vol", 0);

def cumVolumePrev1H = Round(if IsActive1H and !IsActive1H[1]

                      then BarsPerDay(length, price).cumVolumePref

                      else if IsActive1H then cumVolumePrev1H[1] + BarsPerDay(length, price).cumVolumePref

                      else cumVolumePrev1H[1], 0);

def Avg1H = Round((cumVolume1H / cumvolumePrev1H) * 100, 0);

# AddLabel(GetAggregationPeriod() <= AggregationPeriod.HOUR && showLabels, "Avg 1h: " + AsDollars(cumVolumePrev1H / 100), Color.Light_Gray);

# AddLabel(GetAggregationPeriod() <= AggregationPeriod.HOUR && showLabels, "Today: " + AsDollars(cumvolume1H / 100) + " | " + 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(DVByTime(0930, 1059, price)."$Vol", 0);

def cumVolumePrev90 = Round(if IsActive90 and !IsActive90[1]

                      then BarsPerDay(length, price).cumVolumePref

                      else if IsActive90 then cumVolumePrev90[1] + BarsPerDay(length, price).cumVolumePref

                      else cumVolumePrev90[1], 0);

def Avg90 = Round((cumVolume90 / cumvolumePrev90) * 100, 0);

# AddLabel(showLabels, "Avg 90m: " + AsDollars(cumVolumePrev90 / 100), Color.Light_Gray);

# AddLabel(showLabels, "Today: " + AsDollars(cumvolume90 / 100) + " | " + 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(DVByTime(0930, 1329, price)."$Vol", 0);

def cumVolumePrev4H = Round(if IsActive4H and !IsActive4H[1]

                      then BarsPerDay(length, price).cumVolumePref

                      else if IsActive4H then cumVolumePrev4H[1] + BarsPerDay(length, price).cumVolumePref

                      else cumVolumePrev4H[1], 0);

def Avg4H = Round((cumVolume4H / cumvolumePrev4H) * 100, 0);

# AddLabel(GetAggregationPeriod() <= AggregationPeriod.FOUR_HOURS && showLabels, "Avg 4h: " + AsDollars(cumVolumePrev4H / 100), Color.Light_Gray);

# AddLabel(GetAggregationPeriod() <= AggregationPeriod.FOUR_HOURS && showLabels, "Today: " + AsDollars(cumvolume4H / 100) + " | " + AsPercent(Avg4H / 100), (if avg4H >= unusualVolume then Color.Green else if avg4H >= 100 then Color.Orange else Color.Light_Gray));
Thank u! was looking for a way to compare opening volume! This is perfect, Has everything i was looking for, literally
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
467 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top