Average Premarket Volume For ThinkOrSwim

I just add " Mark % Change" to my market watch list and it gives me premarket volume and price change,net change

Also, it will work in all scanners once the column is added to the scan chart column, and I also use it in watchlists
 
Last edited by a moderator:

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

Okay I think Ik why the watchlist might not work , do you have set to 30 minute period aggregation? You may need to try 5 minutes if not. As for pv of zero , I honestly have no idea how to fix that , only thing I can perhaps suggest is try avgs[1] instead of “avgs” that should give you the average from the day before to compare against instead of today’s average. Let me know if that helps other than that, I have no idea how to fix it
try 5 min 5 day. seems to fix av vol 0 problem
 
Ok, here's what I've come up with:

Code:
# 5-day Average Premarket Volume
declare upper;

########## Scripts
script BarsPerPeriod {
    input barCount = 32; #hint barCount: the number of 30 minute candles in a full trading day
    input length = 11; #hint length: the number of premarket candles to count
    plot cumulativeVolume = (fold i = 0 to length with o = 0 do o + GetValue(volume, (barCount - i), 0));
}

script PremarketVolume {
    # code for today's premarket volume
    def st = 0400; # today's premarket start time
    def et = 0929; # today's premarket end time
    def Active = SecondsFromTime(st) >= 0 and SecondsTillTime(et) >= 0;
    def tPV = if Active and !Active[1] then volume
              else if Active then (tPV[1] + volume)
              else tPV[1];
    plot TodaysPremarketVolume = tPV;
     
    # code for prior days' premarket volume
    input barCount = 32; #hint barCount: the number of 30 minute candles in a full trading day
    def pst = 0400; # prior days' premarket start time
    def pet = 0429; # prior days' premarket end time
    def pActive = SecondsFromTime(pst) >= 0 and SecondsTillTime(pet) >= 0;
    def pPV = if pActive and !pActive[1] then BarsPerPeriod(barCount).cumulativeVolume
              else if pActive Then pPV[1] + BarsPerPeriod(barCount).cumulativeVolume
              else pPV[1];
    plot PremarketVolume = pPV;
}
########## /Scripts

input showLabels = yes;

def day1 = PremarketVolume(32).PremarketVolume;
def day2 = PremarketVolume(64).PremarketVolume;
def day3 = PremarketVolume(96).PremarketVolume;
def day4 = PremarketVolume(128).PremarketVolume;
def day5 = PremarketVolume(160).PremarketVolume;

AddLabel(showLabels, "Day 1: " + day1, Color.Light_Gray);
AddLabel(showLabels, "Day 2: " + day2, Color.Light_Gray);
AddLabel(showLabels, "Day 3: " + day3, Color.Light_Gray);
AddLabel(showLabels, "Day 4: " + day4, Color.Light_Gray);
AddLabel(showLabels, "Day 5: " + day5, Color.Light_Gray);

def AvgPremarketVolume = Round((day1 + day2 + day3 + day4 + day5) / 5, 0); # tried to implement as a fold function but couldn't get it to work
def todaysPremarketVolume = PremarketVolume(0).TodaysPremarketVolume;
def Avg = Round((todaysPremarketVolume / AvgPremarketVolume) * 100, 0);

AddLabel(showLabels, "Avg PV: " + AvgPremarketVolume, Color.LIGHT_GRAY);
AddLabel(showLabels, "Today: " + todaysPremarketVolume + " | " + AsPercent(Avg / 100), Color.Orange);

Apply this on a 30min chart with extended hours on. It gets the premarket volume of the previous 5 days, averages that volume, and compares it with the current day's premarket volume. The labels for each of the 5 days are given just to show you what the numbers look like, but they can easily be commented out.

I used the 30min timeframe because it gives you the least amount of candles while accounting for the last 30 minutes of premarket volume (the hourly timeframes don't make it easy to get that data). This timeframe gives you a total of 32 candles from the start of premarket all the way to the end of after hours (11 premarket, 13 regular trading hours, 8 after hours). To get premarket data for the previous day:

1. Start with the first premarket candle of the current day
2. Count backwards 32 candles until you reach the first premarket candle of the previous day
3. Beginning with that first premarket candle, get the volume associated with it and move forward 1 candle until you've gone forward 11 candles, adding each candle's volume to the prior candle's volume. (Another way to look at it, you'll be counting down from 32 to 21.)

To get the same data for additional days, do the same steps listed above except in #2 multiply 32 by the number of days in the past you want. Of course, my code doesn't allow anything past 5 days, so you'll have to adjust it to suit your needs. Also, my code doesn't account for partial/short trading days or days in which a stock doesn't have 11 total premarket candles.

To ensure that the numbers are correct, you'll have to view a ticker and do some math by hand and compare the volume numbers you get with the numbers the labels show. My tests with TSLA show that I'm right, but take that with a half grain of salt.

My code is by no means perfect. Some of the code I don't fully understand as I reused code I've seen in other indicators to make this work. Hopefully someone can optimize it.

Hope this helps.
Thank you
 
I found a script on here:
https://usethinkscript.com/threads/pre-market-volume-for-thinkorswim.2383/page-2#post-86825
and modified it to show premarket volume sessions relative to the past 10 sessions and show as label



Ruby:
input Day_Session_From_Open = 0600;

input Day_Session_End = 0925;

def v = volume;
def na = Double.NaN;

def Is_Session_From_Open = SecondsFromTime(Day_Session_From_Open) >= 0

                        && SecondsTillTime(Day_Session_End) > 0;

 

def New_Session_From_Open = Is_Session_From_Open

                        && !Is_Session_From_Open[1];

def Cum_Vol = if New_Session_From_Open

              then v

                  else if Is_Session_From_Open

                  then Cum_Vol[1] + v

              else Cum_Vol[1];

 

def count = count[1] + if New_Session_From_Open

                       then 1

                       else 0;

 

def Session_Volume1;

def Session_Volume2;

def Session_Volume3;

def Session_Volume4;

def Session_Volume5;

def Session_Volume6;

def Session_Volume7;

def Session_Volume8;

def Session_Volume9;

def Session_Volume10;

 

if (New_Session_From_Open and count > 1) {

    Session_Volume1 = Cum_Vol[1];

    Session_Volume2 = Session_Volume1[1];#Corrected typo here

    Session_Volume3 = Session_Volume2[1];#Corrected Typo Here

    Session_Volume4 = Session_Volume3[1];#Corrected typo here
 
    Session_Volume5 = Session_Volume4[1];#Corrected typo here

    Session_Volume6 = Session_Volume5[1];#Corrected typo here

    Session_Volume7 = Session_Volume6[1];#Corrected Typo Here

    Session_Volume8 = Session_Volume7[1];#Corrected typo here
 
    Session_Volume9 = Session_Volume8[1];#Corrected typo here

    Session_Volume10 = Session_Volume9[1];#Corrected typo here

} else {

    Session_Volume1 = Session_Volume1[1];

    Session_Volume2 = Session_Volume2[1];

    Session_Volume3 = Session_Volume3[1];

    Session_Volume4 = Session_Volume4[1];

    Session_Volume5 = Session_Volume4[1];
 
    Session_Volume6 = Session_Volume5[1];#Corrected typo here

    Session_Volume7 = Session_Volume6[1];#Corrected Typo Here

    Session_Volume8 = Session_Volume7[1];#Corrected typo here
 
    Session_Volume9 = Session_Volume8[1];#Corrected typo here

    Session_Volume10 = Session_Volume9[1];#Corrected typo here

}

 



def avgs = (Session_Volume1 +

                                    Session_Volume2 +

                                    Session_Volume3 +

                                    Session_Volume4 +

                                    Session_Volume5 +

                                    Session_Volume6 +

                                    Session_Volume7 +

                                    Session_Volume8 +

                                    Session_Volume9 +

                                    Session_Volume10 ) / 10;

 def avg = Round(number = (cum_Vol / Avgs));


input showlabels = yes;

AddLabel(showLabels, "Avg PV: " + Avgs, Color.LIGHT_GRAY);
AddLabel(showLabels, "Today: " + cum_Vol + " | " + AsPercent(Avg), Color.Orange);
as label.
It seem work well for only 4 days. for the 5th day back to 10th day it will take the volume of the 4th day
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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