Cumulative Intraday Volume % Change for ThinkorSwim

jake77

New member
Hello, I am new to ThinkScript and would like some help for some volume indicators. TIA!!

Code:
#
# Copyright 2020 Scott J. Johnson (https://scottjjohnson.com)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

#
# CumulativeIntradayVolumePercentChange
#
# Displays a chart of the percent change in close price since 1 market session ago.
#
# The chart period should be less than one day.
#
# This study was designed to be used with TOS Total Volume symbols like $TVOLC/Q
# (NASDAQ Composite Total Volume) or $TVOLC (NYSE Composite Total volume). The
# OHLC "prices" for these symbols are actually cumulative daily volume. But this
# study will show price percent change over the same time period if a stock or
# ETF symbol is used.
#

declare lower;

# did this bar just start a new calendar day?
def newDay = GetDay() <> GetDay()[1];

# get the index of today's first bar
def newDayIndex = if newDay then
                    1
                  else
                    newDayIndex[1] + 1;

# save the index of the previous day's first bar
def prevNewDayIndex = if newDay then
                        newDayIndex[1]
                      else
                        prevNewDayIndex[1] + 1;

# number of bars in the prior day
def indexOffset = prevNewDayIndex - newDayIndex + 1;

# volume today and yesterday
def todayVol = close;
def yesterdayVol = GetValue(close, indexOffset);
                    
# % change
plot s = (todayVol / yesterdayVol - 1) * 100;

1) I would like a volume counter starting again for each session between market open and market close (9:30-16:00). In the form of a cumulative plot and a label. I could get it running but only if I turned off extended hours. But I would like to run it with extended hours on a 1min chart.

2) Also I would like a premarket volume indicator with cumulative plot and label between premarket open and market open (4-9:30).
I got this code running for pmvol but the label just shows "N/A" after the regular market opens at 9:30. Is there a way to keep it showing recorded pm volume throughout the session?

Code:
input pmVol = yes;
def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1];
def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD());
def vol = if isRollover and beforeStart then volume else if beforeStart then vol[1] + volume else Double.NaN;
plot PreMarketVolume = vol;
AddLabel(pmVol, "pmVol: " + Round(vol/1000000,2)+"M", color.DARK_ORANGE);
 
Last edited by a moderator:

Similar threads

Top