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

markos

markos

Member
VIP
Here is a treat for my Day Trading Friends: Volume comparison indicator for ThinkorSwim. :)



thinkScript Code

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.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
prevVol.SetDefaultColor(CreateColor(75, 75, 75));
prevVol.SetLineWeight(1);
plot Vol = v;
Vol.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
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
                                                                      then color.green
                                                                      else color.red);
# End Code Volume Comparison

Shareable Link

 
Last edited by a moderator:
S

skynetgen

New member
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]
 
markos

markos

Member
VIP
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 tos.mx 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:
 

Top