ThinkorSwim Total Volume Traded Indicator

markos

Well-known member
VIP
ThinkorSwim label to show the current total volume traded and the total volume of the previous trading day.

Code:
declare upper;

input aggregationPeriod = AggregationPeriod.DAY;
def volume = volume(period = aggregationPeriod);
def old_volume = volume(period = aggregationPeriod)[1];
AddLabel(yes, Concat("Today's Total Volume = ", volume), color.orange);
AddLabel(yes, Concat("Previous Day Traded Volume = ", old_volume), color.red);

GGKA8dZ.png


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

Volume comparison indicator for ThinkorSwim. :)

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

6kHC0KO.png
 

Attachments

  • GGKA8dZ.png
    GGKA8dZ.png
    17 KB · Views: 231
  • 6kHC0KO.png
    6kHC0KO.png
    88.8 KB · Views: 227
Last edited by a moderator:

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

First time poster here. Love the site btw. This is a really cool indicator by Mobius.

I'm not sure if this is possible, but is there any way to show this indicator even when charting option chains? For instance, get this to show in the lower i.e. AMD stock volume when looking at an options chart for AMD. I wasn't sure if there was anything that could be done using GetUnderlyingSymbol(). I'm guessing that the BarNumber() messes that up trying to display the underlying stock volume on an options chart.

If anyone knows of a workaround please share.

Thanks!
 
I'm trying to add another condition to my scanner with no success, I want to add condition to scan all stocks that the current volume is equal or greater than 1milion for example... not total volume, the current volume... any ideas?
 
@Cheytac no, I do not believe that it is possible. Try reviewing the code & the manuals in the first entry of our Tutorial section.

@greges2109 please review the script. I noticed that there is an input for the study. Change that to 14.

@J007RMC Glad it could be brought to you!
 
A closer examination of the code in post #1 shows that it is written for intraday, i,e, aggregation periods less than DAILY. Hence you'll need to restate your request precisely what you're looking for so that @markos (whom you directed your response to) or one of the coders here can follow up with the specifics.
 
Thank you @tomsk and @markos ! I am new here but will be very much excited to learn from you.

I am looking for a script that will help me to calculate relative volume especially during trading the open.

The script above does almost what i have been looking for! The only difference that i would love to learn how to implement is to take a volume of each bar from the past 14 sessions (instead of a previous day only; for example a volume at9:31,9:32,9:33 etc each from previous 14 days) and calculate an average. Then use this value to compare to a volume at a current bar. I will be grateful so very much for your help! Thanks
 
From a technical standpoint there are a few issues you'll need to be aware of. If you want to keep track of bar volumes at each of the previous 14 days, you will need to maintain 14 separate variables. The other BIGGER problem is that in ThinkScript there's a midnight rollover that is somewhat a pain to code. These were the exact issues that were previously discussed in the Thinkscript lounge when similar requests were made, and that was the general consensus from the experts there.
 
This is a masterpiece. Thank you for this amazing piece of work. Mobius for creating this and @markos for sharing. Here's the updated version thanks to @skynetgen

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;
declare lower;

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 getday()<>getday()[1]
              then x
              else RTHbar1[1];
#Original code: if GetTime() crosses above RegularTradingStart(GetYYYYMMDD())

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
 
I want to compare the previous day's volume to the current. basically, I want a code like this

When the market opens in the morning, if the first bar (30-minute aggregation period) is greater than or equal to the previous day's whole volume then color code/highlight it.
 
I want to compare the previous day's volume to the current. basically, I want a code like this

When the market opens in the morning, if the first bar (30-minute aggregation period) is greater than or equal to the previous day's whole volume then color code/highlight it.

here you go @Stoynks
This only works on 30 Minute Timeframe:
Code:
declare upper;

input pointInTime = 0929;

def isAppointedHour = if SecondsFromTime(pointInTime) > 0 then 1 else 0;

def volAtTime = if isAppointedHour == 1 and isAppointedHour[1] == 0 then volume
    else if isAppointedHour == 1 then volAtTime[1]
        else Double.NaN;
def vol30 = volAtTime;

def yvol =(volume(period = AggregationPeriod.DAY)[1]);

AddLabel (yes, "Yeterday Total Vol " +  (yvol) + "  Todays 30Min Vol " +  (vol30),(if vol30>yvol then color.green else color.red));
 
This code is great, and i try to use it for a scanner to find out the stock which volume is higher than previous day at same time.
But it shows "Secondary period not allowed: Day"
How can I solve this problem? Thanks!
Code:
declare on_volume;

input avgLength = 10;
input unusualpercent = 200;

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;
def prevVol = if IsNaN(c)
               then nan
               else GetValue(v, indexBar);

def Vol = v;

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];
def TodaycumVol = if RTH and !RTH[1]
                   then v
                   else if RTH
                        then compoundValue(1,  TodaycumVol[1] + v, v)
                   else TodaycumVol[1];
def todaybar=RTHbar1-x;
#plot data=TodaycumVol;
#plot data2= PrevRTHbar1;

def compvolume=vD/prevDailyVol*100;

plot comp= compvolume > unusualpercent;
was there ever a solution to the "Secondary period not allowed: Day" problem for the scanner?
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
291 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