Yesterday's Volume vs Today's Volume at Same Time Indicator



Well-known member
Here is a treat for my Day Trading Friends: Volume comparison indicator for ThinkorSwim. :)

thinkScript Code

# 09:30 Mobius: Good Morning - Don't have time to stay but wanted to post a volume study that plots a comparison of yesterdays total volume at the same bar and compares an average volume to the same time yesterday.
# Volume Comparison 
# Plots Yesterdays Total Volume At Same Bar and Average Volume At Same Bar
# Mobius
# V02.06.2018 Posted to Chat Room 07.13.2018

declare on_volume;

input avgLength = 10;

def v = volume;
def vD = volume(period = AggregationPeriod.Day);
def c = close;
def x = BarNumber();
def nan = double.nan;
def RTHbar1 = if GetTime() crosses above RegularTradingStart(GetYYYYMMDD())
              then x
              else RTHbar1[1];
def RTH = GetTime() >= RegularTradingStart(GetYYYYMMDD()) and
          GetTime() <= RegularTradingEnd(GetYYYYMMDD());
def PrevRTHbar1 = if RTHbar1 != RTHbar1[1]
                  then RTHbar1[1]
                  else PrevRTHbar1[1];
def indexBar = RTHbar1 - PrevRTHbar1;
plot prevVol = if IsNaN(c)
               then nan
               else GetValue(v, indexBar);
prevVol.SetDefaultColor(CreateColor(75, 75, 75));
plot Vol = v;
Vol.AssignValueColor(if close > open then CreateColor(5, 250, 12) else CreateColor(250, 5, 25));
AssignPriceColor(if close > open then CreateColor(5, 250, 12) else CreateColor(250, 5, 25));
def avgPrev = Average(prevVol, avgLength);
def avgCurr = Average(Vol, avgLength);
def prevDailyVol = if RTH and !RTH[1]
                   then getValue(v, indexBar)
                   else if RTH
                        then compoundValue(1, prevDailyVol[1] + GetValue(v, indexBar), GetValue(v, indexBar))
                   else prevDailyVol[1];
AddLabel(1, "Prev D Vol = " + prevDailyVol +
          "  Prev Vol avg(" + avgLength + ") = " + Round(avgPrev, 0), prevVol.TakeValueColor());
AddLabel(1, "Current D Vol = " + vD +
          "  Curr Vol avg(" + avgLength + ") = " + Round(avgCurr, 0), if vD > prevDailyVol
# End Code Volume Comparison

Shareable Link

Last edited by a moderator:


Thank you!
For some reason was not working for me until i changed:
def RTHbar1 = #if GetTime() crosses above RegularTradingStart(GetYYYYMMDD())
if getday()<>getday()[1]


Well-known member
Thank you!
For some reason was not working for me until i changed:
@skynetgen So that we all learn, please post the line above and below (if possible) the part of the offending code. btw, using # to comment out is appreciated. Thanks!
Then, please repaste the whole code (within reason) along with the share that has it corrected.

I don't want to look like a "dufus" if I ask Mobius or Paris in the thinkScript Lounge about the code. :oops::unsure:


Well-known member
This worked for me as advertised. I used 2 day average.


New member
Hi All,
This is a neat script to compare current volume to previous day's volume at same bar.
I noticed that the after hours bars throw off the indexbar. When I turn off after hours on the chart, the script doesn't work (due NaNs).
I found this on thinkscript learning website:
Example 2
declare lower;
input symbol = "IBM";
def closeSymbol = close(symbol);
def closeSymbolWithoutNaN = CompoundValue(1, if IsNaN(closeSymbol) then closeSymbolWithOutNaN[1] else closeSymbol, closeSymbol);
plot Data = closeSymbolWithOutNaN;
This code plots the close price of an input symbol across the current chart. Any gap in the input symbol price data (NaN value) is replaced with the last-known close price value before the gap.

But I couldn't integrate it to the thinkscript. Any ideas on how to get this script to ignore the after hours bars?

Thank you.