Extended Hours Volume Label

xiaika

New member
Hello, I am a registered broker with schwab and work the graveyard shift. I frequently get asked questions from clients to quote the volume in the premarket and after hours sessions and my thinkorswim cannot do this by default. I have thinkscript code that i wrote that calculates the Day change after hours and pre market but i cannot for the life of me figure out how to get the volume to aggregate for each entire session..

My main goals for the script
1) It should only be a label, no plotting needed
2) It should not show the label if the aggregation period is not set to 1m
3) It should be visible no matter what time of my shift it is. So it should work for after hours and premarket. and i would like to be able to see the previous day after hours data after the premarket has begun for the next day.

Basically anytime a client could call in in the middle of the night or early morning and ask me what is the volume in the after hours or pre market, i need to be able to answer immediately without going to nasdaq website.
 
Solution

SPY 2D 1Min chart

Code:
# AfterMarket/PreMarket Volume
# this code is modified from:
#
# Globex Volume and Average
# Mobius
# From TASC 2017-06 | Daytrading With Night Volume
# 03.11.2018

declare lower;

# AfterMarket Volume
def am = getTime() > regularTradingEnd(getYYYYMMDD());
def amVol = if am and !am[1]
            then volume
            else if am
            then CompoundValue(1, amVol[1] + volume, volume)
            else amVol[1];
plot vAM = if am 
         then amVol 
         else double.nan;
vaM.setdefaultcolor(getcolor(1));

# PreMarket Volume
def pm = getTime() < regularTradingStart(getYYYYMMDD());
def pmVol = if pm and !pm[1]
            then...

SPY 2D 1Min chart

Code:
# AfterMarket/PreMarket Volume
# this code is modified from:
#
# Globex Volume and Average
# Mobius
# From TASC 2017-06 | Daytrading With Night Volume
# 03.11.2018

declare lower;

# AfterMarket Volume
def am = getTime() > regularTradingEnd(getYYYYMMDD());
def amVol = if am and !am[1]
            then volume
            else if am
            then CompoundValue(1, amVol[1] + volume, volume)
            else amVol[1];
plot vAM = if am 
         then amVol 
         else double.nan;
vaM.setdefaultcolor(getcolor(1));

# PreMarket Volume
def pm = getTime() < regularTradingStart(getYYYYMMDD());
def pmVol = if pm and !pm[1]
            then volume
            else if pm
            then CompoundValue(1, pmVol[1] + volume, volume)
            else pmVol[1];
plot vPM = if pm 
         then pmVol
         else double.nan;
vPM.setdefaultcolor(getcolor(2));

# Total and Labels
def comVol = if pm then amVol + pmVol else comVol[1];
plot combinedVol = if pm then comVol else double.nan;
combinedVol.setstyle(curve.short_dash);
combinedVol.setdefaultcolor(GetColor(3));

Addlabel(1, "AM Volume = " + amVol, getcolor(1));
Addlabel(1, "PM Volume = " + pmVol, getcolor(2));
Addlabel(1, "Combined Volume = " + comVol, getcolor(3));

# end code
@xiaika Here is something for you to tinker with. You will need to verify if it is or is not giving the correct data. I compared the output to https://www.nasdaq.com/market-activity/after-hours and noticed that their aftermarket hours start at 4pm ET. This code starts at 3pm ET. Good luck and best wishes.
 
Solution

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

Thank you for sharing this. I tried looking at the code and can't figure out how I can modify it to start the AH from 4PM and not 3PM?

Also, I noticed it is not as acurate but best one I have found so far. Right now for IONM PM volume today it is showing 62.9M, however DAS is showing the volume as 81.1M.

Thanks!
 
Thank you for sharing this. I tried looking at the code and can't figure out how I can modify it to start the AH from 4PM and not 3PM?

Also, I noticed it is not as acurate but best one I have found so far. Right now for IONM PM volume today it is showing 62.9M, however DAS is showing the volume as 81.1M.

Thanks!


try this:

EXTENDED HOURS (PreMarket / Aftermarket) VOLUME LABEL

REMEMBER:
TO ENABLE EXTENDED HOURS AND 1 Minute AGGREGATION

Code:
#   ENABLE EXTENDED HOURS AND 1 Minute AGGREGATION
#premarket
def Pre_startTime = SecondsFromTime(0400);
def Pre_endTime = secondsTillTime(0929);

#Regular Trading Hours:
def rth_startTime = SecondsFromTime(0930);
def rth_endTime = secondsTillTime(1559);

#AfterMarket Trading Hours:
def AM_startTime = SecondsFromTime(1600);
def AM_endTime = secondsTillTime(1959);
#
def aggregationPeriod = AggregationPeriod.DAY;
def day_close = close(period = aggregationPeriod);
def dif = close  - day_close;
def AMorPM_start = (if isnan(dif) then Pre_startTime else AM_startTime);
def AMorPM_end = (if isnan(dif) then Pre_endTime else AM_endTime);
def dailyVolumeSum = compoundValue(1, if AMorPM_start == 0 then volume else if AMorPM_end >= 0 then dailyVolumeSum[1] + volume else dailyVolumeSum[1], 1);
def scan =ceil(dailyVolumeSum);
Addlabel(1, "EXT Volume = " + scan, getcolor(1));
 
try this:

EXTENDED HOURS (PreMarket / Aftermarket) VOLUME LABEL

REMEMBER:
TO ENABLE EXTENDED HOURS AND 1 Minute AGGREGATION

Code:
#   ENABLE EXTENDED HOURS AND 1 Minute AGGREGATION
#premarket
def Pre_startTime = SecondsFromTime(0400);
def Pre_endTime = secondsTillTime(0929);

#Regular Trading Hours:
def rth_startTime = SecondsFromTime(0930);
def rth_endTime = secondsTillTime(1559);

#AfterMarket Trading Hours:
def AM_startTime = SecondsFromTime(1600);
def AM_endTime = secondsTillTime(1959);
#
def aggregationPeriod = AggregationPeriod.DAY;
def day_close = close(period = aggregationPeriod);
def dif = close  - day_close;
def AMorPM_start = (if isnan(dif) then Pre_startTime else AM_startTime);
def AMorPM_end = (if isnan(dif) then Pre_endTime else AM_endTime);
def dailyVolumeSum = compoundValue(1, if AMorPM_start == 0 then volume else if AMorPM_end >= 0 then dailyVolumeSum[1] + volume else dailyVolumeSum[1], 1);
def scan =ceil(dailyVolumeSum);
Addlabel(1, "EXT Volume = " + scan, getcolor(1));
Hi @XeoNoX , can you please help me with this code so that it shows four labels as "pre-market volume," "RTH volume," "post-market volume," and "total volume"..thank you so much
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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