Average Volume Stats

Analyze and compare today's daily volume with historical volume, in less than 1 second.

26 mins
Beginner-Friendly
youtube-video-thumbnail
Table of Contents
    Add a header to begin generating the table of contents
    Table of Contents
      Add a header to begin generating the table of contents

      Introduction to the Average Volume Stats Indicator

      In this tutorial, we’ll build the Average Volume Stats indicator for ThinkOrSwim. This indicator will show you not only today’s volume but how it compares to the average volume over two different time frames of your choosing.

      You can customize these periods to suit your trading strategy, making this indicator both flexible and powerful.

      Additionally, we’ll show how to toggle between a short number format (millions) and a long number format (exact share count).

      This will be a fun thinkScript coding tutorial, along with a useful indicator for those of you that like to use volume in your trading.

      Volatility Box Invite

      We are TOS Indicators.com, home of the Volatility Box.

      The Volatility Box is our secret tool, to help us consistently profit from the market place. We’re a small team, and we spend hours every day, after the market close, doing nothing but studying thousands of data points to keep improving and perfecting the Volatility Box price ranges.

      We have two different Volatility Boxes - a Futures Volatility Box and a Stock Volatility Box.

      Futures Volatility Box - Trade Major Markets With an Edge

      Designed For: Futures, Micro-Futures and Index Market Traders
      Supported Models: Hourly Volatility Box models
      Supported Markets: 10 Major Futures Markets

      The Futures Volatility Box comes with:

      • 5 Volatility Models for each market
      • Support for 10 Futures Markets (/ES, /NQ, /YM, /RTY, /CL, /GC, /SI, /ZB, /HG, /NG)
      • Video Setup Guide
      • Trade Plan
      • Access to all members-only resources, including Squeeze Course

      Learn More About the Futures Volatility Box

      Trade futures and micro futures with a consistent volatility edge

      Stock Volatility Box - Powerful Web Based Volatility Platform

      Designed For: Stock and Options Traders
      Supported Models: Hourly and Daily Volatility Box models
      Supported Markets: 10,000+ Stocks and ETFs (new markets added frequently)

      A Stock Volatility Box membership includes access to: 

      • Live Scanner - A powerful scanner we've built from scratch, to scan 10,000 symbols every 2 seconds for new volatility breaches
      • Dashboard - A quick and easy way to view daily volatility model levels online
      • Short Interest Scanner - Short interest, Squeeze, and EMA data to find short squeezes
      • Squeeze Course - All of our proprietary squeeze tools, including robust backtesters
      • All Members Only Indicators - We don't nickel and dime you. Everything really is included.
      • And much more!

      Learn More About the Stock Volatility Box

      Trade stocks and options with a consistent volatility edge

      Step 1: Starting the Script

      Open the ThinkOrSwim platform and go to Studies > Edit Studies > Create. Name the indicator something like AverageVolumeStats and remove any default code inside.

      Step 2: Declaring Inputs

      We’ll begin by declaring the key inputs that allow users to customize the period lengths for the averages:

      input length1 = 30;
      input length2 = 90;
      input numFormat = {default short, long};

      This code allows traders to adjust the two time frames (defaulting to 30 and 90 days) and choose between the short or long number formats.

      Step 3: Fetching Volume Data

      Next, let’s bring in the daily volume data:

      def vol = volume(period = "Day");

      This code captures the total daily volume, regardless of which time frame you have on your chart.

      Step 4: Calculating Averages

      We’ll use the Average function to calculate the average volume over the past length1 and length2 days:

      def avg1 = Average(vol, length1);
      def avg2 = Average(vol, length2);

      Here, we compute the 30-day and 90-day averages (or whichever values you set for length1 and length2).

      Step 5: Displaying Volume and Averages

      Now, let’s create labels to display the current volume and averages in a readable format:

      def volPlot;
      def avg1Plot;
      def avg2Plot;
      
      switch(numFormat){
      case short:
          volPlot = if vol > 1000000 then Round(vol / 1000000, 0) else Round(vol / 1000000, 2);
          avg1Plot = if avg1 > 1000000 then Round(avg1 / 1000000, 0) else Round(avg1 / 1000000, 2);
          avg2Plot = if avg2 > 1000000 then Round(avg2 / 1000000, 0) else Round(avg2 / 1000000, 2);
      case long:
          volPlot = Round(vol, 0);
          avg1Plot = Round(avg1, 0);
          avg2Plot = Round(avg2, 0);
      }

      Step 6: Adding Labels for Visual Representation

      The labels are where we’ll show the current volume and how it compares to the averages. We also color-code the labels based on whether today’s volume exceeds the average:

      AddLabel(yes, "Volume: " + volPlot, color.light_gray);
      AddLabel(yes, length1 + "D Avg: " + avg1Plot + " | " + AsPercent(vol/avg1), if vol/avg1 <= 1 then color.light_gray else color.green);
      AddLabel(yes, length2 + "D Avg: " + avg2Plot + " | " + AsPercent(vol/avg2), if vol/avg2 <= 1 then color.light_gray else color.green);

      Step 7: Testing and Adjusting

      Once you’ve added the code, apply the script and test it on a few tickers. Try adjusting the length1 and length2 values, as well as switching between the short and long number formats to see how the labels change dynamically.

      Conclusion

      In this tutorial, we’ve built a dynamic Average Volume Stats indicator. By comparing today’s volume against the past averages, this tool helps you spot unusual trading activity quickly and easily. Download the final version for free from our website.

      downloads

      Download the Average Volume Stats Indicator for ThinkorSwim.

      The download contains a STUDY.ts file, which you can directly import into your ThinkOrSwim platform.

      Download Indicator

      Download the Average Volume Stats Indicator for ThinkorSwim.

      The download contains a STUDY.ts file, which you can directly import into your ThinkOrSwim platform.

      Have your own idea?

      Let us help you turn your trading strategy into a powerful indicator, scan and backtester.