Premarket Volume For ThinkOrSwim

HolyDiver

New member
Can u guys help me write a simple script that displays only the premarket volume?
Or to simplify only the volume of the first 4 hours. 5am-9:30am.
 

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

Hi

Many discussions on Volume.

I have a specific labels I would like to have in my volume sub chart.

Has anyone ever seen a volume label that just adds up all the premarket volumes
1. label for the post market of the prior day
2. label for the premarket of that day only
3. Total of post and pre market volume also

If I go back to prior charts in the weeks then the calculation is only based on that days transactions.

Has anyone looked at this?

Thank you in advance.

Cheers
 
Hi

Many discussions on Volume.

I have a specific labels I would like to have in my volume sub chart.

Has anyone ever seen a volume label that just adds up all the premarket volumes
1. label for the post market of the prior day
2. label for the premarket of that day only
3. Total of post and pre market volume also

If I go back to prior charts in the weeks then the calculation is only based on that days transactions.

Has anyone looked at this?

Thank you in advance.

Cheers
Here you go
Ruby:
# Box Volume Stats
# Version 1.2
# Created by: Enigma
# Created: 05/18/17
# Modified by: Surya Kiran C ## Included rVolume label and Changed length as input. ## Additionally Pre-Market, 1Hr Volume, AfterHour Volume labels are added.


declare on_volume;

input length = 30;
input ShowDayAvg = yes;
input ShowTodayVolume = yes;
input ShowPercentOfDayAvg = yes;
input UnusualVolumePercent = 200;
input ShowBarAvg = yes;
input ShowCurrentBar = yes;

input PreMktVol = yes;
input RTH1HrVol = yes;
input PostMktVol = yes;


def VolDayAvg = (fold index = 1 to length + 1 with Avg = 0 do (Avg + volume(period = "DAY")[index])) / length;
def AvgBars = (fold index2 = 1 to length + 1 with Bar = 0 do (Bar + volume[index2])) / length;

def Today = volume(period = "DAY");
def PercentOfDayAvg = Round((Today / VolDayAvg) * 100, 0);

def CurVol = volume;


def offset = 1;
def ADV = Average(volume, length)[offset];
def rVol = volume / ADV;

# Labels

#if GetAggregationPeriod() >= AggregationPeriod.DAY then 0 else if 1HrRTHVol then 1 else 0,

AddLabel(ShowDayAvg, length + "Day Avg: " + Round(VolDayAvg, 0) + " ", Color.LIGHT_GRAY);
AddLabel(ShowTodayVolume, "Today: " + Today + " ", (if PercentOfDayAvg >= UnusualVolumePercent then Color.GREEN else if PercentOfDayAvg >= 100 then Color.ORANGE else Color.LIGHT_GRAY));
AddLabel(ShowPercentOfDayAvg, PercentOfDayAvg + "%", (if PercentOfDayAvg >= UnusualVolumePercent then Color.GREEN else if PercentOfDayAvg >= 100 then Color.ORANGE else Color.WHITE) );
AddLabel(ShowBarAvg, "Avg" + length + "Bars: " + Round(AvgBars, 0) + " ", Color.LIGHT_GRAY);
AddLabel(ShowCurrentBar, "Cur Bar: " + CurVol + " ", (if CurVol >= AvgBars then Color.GREEN else Color.ORANGE));

AddLabel(yes, "rVol :" + Round(rVol, 2));
#AddLabel(yes, "ADV :" + ADV);
#AddLabel(yes, asPercent(rVol)); # remove "#" infront of Addlabels to select prefer choice
#AssignPriceColor(if rVol >= 1 then color.dark_red else if rVol <=.5 then Color.black else color.Gray);

#Pre, 1Hr RTH, AfterHours Volumes.
##if GetAggregationPeriod() >= AggregationPeriod.DAY then 0 else if PreMktVol then 1 else 0

input PrestartTime = 0400;
input PreendTime = 0929;

def PreMkt = SecondsFromTime(PrestartTime) >= 0 and SecondsTillTime(PreendTime) >= 0;
def PreVolMins = if PreMkt and !PreMkt[1] then volume
else if PreMkt then PreVolMins[1] + volume
else PreVolMins[1];
AddLabel(if GetAggregationPeriod() >= AggregationPeriod.DAY then 0 else if PreMktVol then 1 else 0, "PreMktVol = " + PreVolMins + " ", Color.Gray);
# End Volume PreMarket

input RTH1HrstartTime = 0930;
input RTH1HrendTime = 1029;

def RTH1Hr = SecondsFromTime(RTH1HrstartTime) >= 0 and SecondsTillTime(RTH1HrendTime) >= 0;
def RTH1HrMins = if RTH1Hr and !RTH1Hr[1] then volume
else if RTH1Hr then RTH1HrMins[1] + volume
else RTH1HrMins[1];
AddLabel(if GetAggregationPeriod() >= AggregationPeriod.DAY then 0 else if RTH1HrVol then 1 else 0, "RTH1HrVol = " + RTH1HrMins + " ", Color.Gray);
#End Volume RTH First 60 Mins

input PoststartTime = 1600;
input PostendTime = 1959;

def PostMkt = SecondsFromTime(PoststartTime) >= 0 and SecondsTillTime(PostendTime) >= 0;
def PostVolMins = if PostMkt and !PostMkt[1] then volume
else if PostMkt then PostVolMins[1] + volume
else PostVolMins[1];
AddLabel(if GetAggregationPeriod() >= AggregationPeriod.DAY then 0 else if PostMktVol then 1 else 0, "PostMktVol = " + PostVolMins + " ", Color.Gray);
# End Volume PostMarket
 
Last edited by a moderator:
Hi

Thank you.

I have this working in TOS.

Just need clarification.

What does RTH1Hr stand for?

What settings would you use for
1. Pre start time - 400 - what does this do?
2. Pre end Time - 929 - what does this do?
3. rt h1 hrstart time - 930 - what does this do?

Checked AMC ( 5628566 Nasdaq site vs 4348959 ) and Tap (1067573 vs 855918 )Fridays PM volume and have differences with what NASDAQ reports on there site - do I need to change the settings ?

Cheers
 
Last edited:
Hi

Thank you.

I have this working in TOS.

Just need clarification.

What does RTH1Hr stand for?

What settings would you use for
1. Pre start time - 400 - what does this do?
2. Pre end Time - 929 - what does this do?
3. rt h1 hrstart time - 930 - what does this do?

Checked AMC ( 5628566 Nasdaq site vs 4348959 ) and Tap (1067573 vs 855918 )Fridays PM volume and have differences with what NASDAQ reports on there site - do I need to change the settings ?

Cheers

I didn't change any setting . Pre market starts at 4 am to 9:29 am , after 9:30 am it's regular trading hours.
Pth = premarket trading hour volume
Rth1 = regular trading hour, and 1st hour after opening
Postmartvol = Volume after market closed at 4pm
You can turn on and off labels you don't want to see . I only use this for premarket volume. Hope this helps , happy trading.
 
Last edited:
Hey everyone! As I'm continuing to learn how to use ThinkScript to make my own basic technical indicators, I've hit a wall. TOS has a CumulativeOvernightVolume indicator which I've used as a guide to make my current script.
GOAL: I would like to add 2 more measures: the % change of today's Pre-Market volume as compared to the previous day's Pre-Market volume, and the % change of today's 1st Hour Volume as compared to the previous day's 1st Hour Volume, however My current script measures the total amount of volume traded today in the Pre-Market and the total amount of volume traded today in the 1st Hour of the Market and I'm having difficulty with capturing the previous day
Here's the script for today's Pre-Market volume:
Code:
INPUT Start = 0400;
INPUT End = 0929;

DEF VolumeFromStart = SecondsFromTime(Start) >= 0 and SecondsTillTime(End) > 0;
DEF VolumeAtEnd = SecondsFromTime(End) >= 0;
DEF VolumeRange = VolumeFromStart and !VolumeFromStart[1];
DEF VolumeInRange = if VolumeRange then volume else if VolumeFromStart then VolumeInRange[1] + volume else VolumeInRange[1];
DEF V = (VolumeAtEnd + VolumeInRange);


PLOT CumulativeVolume = if VolumeFromStart then VolumeInRange else Double.NaN;


AddLabel(Start, "Pre-Market: " + V, color=CumulativeVolume.takeValueColor());

My current problem: I've tried adding INPUT aggregationPeriod = AggregationPeriod.DAY; to then use volume(period = AggregationPeriod.DAY)[1]
but it didn't work... Can't seem to find a thread on this forum about a similar problem in the search function. Does anyone have any pointers on how I can capture yesterday's volume to then use to calculate the % change?
 
Congrats on putting the time/effort into learning this stuff. You've stumbled into a tricky case.

Using the DAY period, TOS has no way to differentiate between regular hours and extended hours. It'll always give you the combination of both. You'll have to rely solely on intraday timeframes to achieve your goal.

The next logical approach is to look back X number of periods, depending on the current timeframe, to find the relevant time of day on the previous trading day. 1H and above candles are partly in premarket and partly after the open, so you can't use those. You have to go smaller.

Bring up SPY on a 30m chart with extended hours enabled. Use the trend line drawing tool and look at its data box when you select the first extended hours candle of any day and then hover above the final extended hours candle of the same day. Remember what it says for how many hours and how many bars that is. Now do the same thing on a couple other days of the same chart. They aren't the same counts when I do this on the most recent couple of days for SPY. The reason is TOS doesn't provide data for periods that had no volume. Even on SPY, which is a very high volume symbol with lots of extended hours trading, this creates an inconsistency we have to deal with. Load a different symbol like XLK and you'll see there's much fewer extended hours candles. This can be different on every symbol and can be different on every day for a single symbol.

Without extended hours enabled this approach of looking back at previous days by using an appropriate multiple of the periods works fine. It's only when extended hours is enabled that this causes problems. And in your case you need extended hours enabled.

The easiest way I can think of to workaround this is to create additional variables to hold yesterday's data. Outside of your tracking time range, instead of Double.NaN, use CumulativeVolume[1] so the value remains fixed through the end of the day. You can have a different variable hold that and still have the plot show Double.NaN if you want. When the date changes, copy the persisted value to the new variable. The copy will happen as soon as that day has any volume, whether that's midnight or 4am or 9:30 or any time between.

Ruby:
def cumVol = if VolumeFromStart then VolumeInRange else cumVol[1];

def previousCumVol =
  if GetYYYYMMDD() != GetYYYYMMDD()[1]
  then cumVol[1]
  else previousCumVol[1]
;

Then you can do your math for % change, etc. And handle the first hour volume similarly.
 
Congrats on putting the time/effort into learning this stuff. You've stumbled into a tricky case.

Using the DAY period, TOS has no way to differentiate between regular hours and extended hours. It'll always give you the combination of both. You'll have to rely solely on intraday timeframes to achieve your goal.

The next logical approach is to look back X number of periods, depending on the current timeframe, to find the relevant time of day on the previous trading day. 1H and above candles are partly in premarket and partly after the open, so you can't use those. You have to go smaller.

Bring up SPY on a 30m chart with extended hours enabled. Use the trend line drawing tool and look at its data box when you select the first extended hours candle of any day and then hover above the final extended hours candle of the same day. Remember what it says for how many hours and how many bars that is. Now do the same thing on a couple other days of the same chart. They aren't the same counts when I do this on the most recent couple of days for SPY. The reason is TOS doesn't provide data for periods that had no volume. Even on SPY, which is a very high volume symbol with lots of extended hours trading, this creates an inconsistency we have to deal with. Load a different symbol like XLK and you'll see there's much fewer extended hours candles. This can be different on every symbol and can be different on every day for a single symbol.

Without extended hours enabled this approach of looking back at previous days by using an appropriate multiple of the periods works fine. It's only when extended hours is enabled that this causes problems. And in your case you need extended hours enabled.

The easiest way I can think of to workaround this is to create additional variables to hold yesterday's data. Outside of your tracking time range, instead of Double.NaN, use CumulativeVolume[1] so the value remains fixed through the end of the day. You can have a different variable hold that and still have the plot show Double.NaN if you want. When the date changes, copy the persisted value to the new variable. The copy will happen as soon as that day has any volume, whether that's midnight or 4am or 9:30 or any time between.

Ruby:
def cumVol = if VolumeFromStart then VolumeInRange else cumVol[1];

def previousCumVol =
  if GetYYYYMMDD() != GetYYYYMMDD()[1]
  then cumVol[1]
  else previousCumVol[1]
;

Then you can do your math for % change, etc. And handle the first hour volume similarly.
Thanks for taking a look at my script! Just to make sure I understood, what you're saying is: my AggregationPeriod.DAY doesn't work because TOS can't differentiate between extended hours and regular trading hours, so it'll give me both. The solution therefore, is to create a separate script to look at the Previous Day Specifically, and then specify this script to look at the Pre-Market volume only; With my current script, I can see what the Pre-Market Volume of the previous day already but it only displays Today's Pre-Market Volume as a label, so I would need to create a script to grab that the previous day pre-market volume as a separate label?

Edit #1: I gave it a shot and made the changes from what I understood: it successfully labeled the Pre-Market Volume of the previous day. Thank you!! Now I just need to make the calculation for the % change. Here's what the script now looks like:
Code:
input Start = 0400;
input End = 0929;
input ShowTodayOnly = yes;
def Today = if GetDay() == GetLastDay() then 1 else 0;

def VolumeFromStart = SecondsFromTime(Start) >= 0 and SecondsTillTime(End) > 0;
def VolumeAtEnd = SecondsFromTime(End) >= 0;
def VolumeRange = VolumeFromStart and !VolumeFromStart[1];
def VolumeInRange = if VolumeRange then volume else if VolumeFromStart then VolumeInRange[1] + volume else VolumeInRange[1];
def V = (VolumeAtEnd + VolumeInRange);

def Cumulativevolume = if VolumeFromStart then VolumeInRange else CumulativeVolume[1];

def PreviousDayPreMarketVolume =
  if ShowTodayOnly and !Today
  then CumulativeVolume[1]
  else PreviousDayPreMarketVolume[1];

plot PrevPreMVol = CumulativeVolume;

AddLabel(Start, "Yesterday Pre-Market Volume: " + PreviousDayPreMarketVolume, color = PrevPreMVol.TakeValueColor());

Edit #2: Actually, it looks kinda weird when I plot it on the graph... but the label is correct
 
Last edited:
Thanks for taking a look at my script! Just to make sure I understood, what you're saying is: my AggregationPeriod.DAY doesn't work because TOS can't differentiate between extended hours and regular trading hours, so it'll give me both.

Correct

The solution therefore, is to create a separate script to look at the Previous Day Specifically, and then specify this script to look at the Pre-Market volume only; With my current script, I can see what the Pre-Market Volume of the previous day already but it only displays Today's Pre-Market Volume as a label, so I would need to create a script to grab that the previous day pre-market volume as a separate label?

It can be all in one script. It's just that if you want to have both yesterday's data and today's data at the same time so you can do math on them then you need to maintain yesterday's data yourself in separate variables. In your current script, that data becomes Double.NaN at 9:30. If you look at the title bar of the study it will show N/A for that plot right now. So you either need to try looking back X periods to get the values, which has the problems I described earlier, or maintain those values some place else.
 
Correct



It can be all in one script. It's just that if you want to have both yesterday's data and today's data at the same time so you can do math on them then you need to maintain yesterday's data yourself in separate variables. In your current script, that data becomes Double.NaN at 9:30. If you look at the title bar of the study it will show N/A for that plot right now. So you either need to try looking back X periods to get the values, which has the problems I described earlier, or maintain those values some place else.
It works perfectly now!
I also tried adding a label for the %Change from yesterday and today, but it isn't working... if it's a positive% change then I'd like the label to be green, if it's a negative% change then I'd like the label to be red, but if there is no change then I'd want the label to just be white.
The problem: For example, if I changed it to "if POSITIVE then round((((V - PreviousDayPreMarketVolume) / PreviousDayPreMarketVolume)) * 100) and color.GREEN" then the script doesn't work and it returns "double expected". Do you have any advice?

Code:
input Start = 0400;
input End = 0929;
input ShowTodayOnly = yes;
def Today = if GetDay() == GetLastDay() then 1 else 0;

def VolumeFromStart = SecondsFromTime(Start) >= 0 and SecondsTillTime(End) > 0;
def VolumeAtEnd = SecondsFromTime(End) >= 0;
def VolumeRange = VolumeFromStart and !VolumeFromStart[1];
def VolumeInRange = if VolumeRange then volume else if VolumeFromStart then VolumeInRange[1] + volume else VolumeInRange[1];
def V = (VolumeAtEnd + VolumeInRange);
def Cumulativevolume = if VolumeFromStart then VolumeInRange else Cumulativevolume[1];

def PreviousDayPreMarketVolume = if ShowTodayOnly and !Today then Cumulativevolume[1] else PreviousDayPreMarketVolume[1];

plot PreMarketVolume = Cumulativevolume;

ADDLABEL(Start, "Yesterday's Pre-Market: " + PreviousDayPreMarketVolume, color = PreMarketVolume.TakeValueColor());

ADDLABEL(Start, "Today's Pre-Market: " + V, color = PreMarketVolume.TakeValueColor());

def POSITIVE = round((((V - PreviousDayPreMarketVolume) / PreviousDayPreMarketVolume)) * 100) > 0;
def NEGATIVE = round((((V - PreviousDayPreMarketVolume) / PreviousDayPreMarketVolume)) * 100) < 0;
def NEUTRAL = round((((V - PreviousDayPreMarketVolume) / PreviousDayPreMarketVolume)) * 100) == 0;

ADDLABEL(Start, "%Change: " + if POSITIVE then round((((V - PreviousDayPreMarketVolume) / PreviousDayPreMarketVolume)) * 100) else if BEARISH then round((((V - PreviousDayPreMarketVolume) / PreviousDayPreMarketVolume)) * 100) else if NEUTRAL then round((((V - PreviousDayPreMarketVolume) / PreviousDayPreMarketVolume)) * 100) else Double.NaN, Color.WHITE);

Edit: Fixed it by adding
Code:
def PercentChange = (((V - PreviousDayPreMarketVolume) / PreviousDayPreMarketVolume)) * 100;

AddLabel(Start, "%Change: " + Round(PercentChange), if PercentChange > 0 then Color.Green else if PercentChange < 0 then Color.Red else if PercentChange == 0 then color.WHITE else Color.Gray);
 
Last edited:
Is there any possibility of converting the indicator above "% change in premarket volume from previous day" aka "previous days premarket volume"
into a custom watchlist column? I am trying to figure out how to put only the green or red percentage change label number on the watchlist column. It would be much easier to see the percentage change positive or negative ahead of time on the watchlist instead of manually going to each chart to see the label. If any one has any ideas they are greatly appreciated. I have tried to make it already and all it does is make every column 1.0. Thank you for your help.
 
Is there any possibility of converting the indicator above into a custom watchlist column? I have tried to make it already and all it does is make every column 1.0

I did not test the code. I did not change the code. It produces percentages. Did not verify the veracity of the data.
I added the background coloring of the watchlist column.
Ruby:
input Start = 0400;
input End = 0929;
input ShowTodayOnly = yes;
def Today = if GetDay() == GetLastDay() then 1 else 0;

def VolumeFromStart = SecondsFromTime(Start) >= 0 and SecondsTillTime(End) > 0;
def VolumeAtEnd = SecondsFromTime(End) >= 0;
def VolumeRange = VolumeFromStart and !VolumeFromStart[1];
def VolumeInRange = if VolumeRange then volume else if VolumeFromStart then VolumeInRange[1] + volume else VolumeInRange[1];
def V = (VolumeAtEnd + VolumeInRange);
def Cumulativevolume = if VolumeFromStart then VolumeInRange else Cumulativevolume[1];

def PreviousDayPreMarketVolume = if ShowTodayOnly and !Today then Cumulativevolume[1] else PreviousDayPreMarketVolume[1];

plot PreMarketVolume = Cumulativevolume;

def PercentChange = (((V - PreviousDayPreMarketVolume) / PreviousDayPreMarketVolume)) * 100;

AddLabel(Start, + Round(PercentChange));

AssignBackgroundColor(
if PercentChange > 0 then Color.Green else
if PercentChange < 0 then Color.Red else
if PercentChange == 0 then color.WHITE else Color.Gray);

No one can say where you went astray.
In order to troubleshoot the issues. We need to be able to see what you are seeing. So we need you to post the following:
  1. What code did you copy&paste? Even if you think it is the same as the one on the forum. We need to see yours. Maybe the issue is that you missed part of the code when you created the study. Copy&Paste YOUR code here.
  2. Provide a screen grab of the wonky results. Make sure to grab the whole chart so we can see the aggregations, what stock, and all your settings so we can try to replicate your results and correct them.
After you post the above information, I am sure someone will be able to point you toward possible solutions.
Unsure of how to upload screenshots to the forum, Here are directions.
 
Thank you it would work great if I could get only todays data. what I mean is if I look at my "chart" with indicator on the "chart" the background matches the color of the premarket label perfectly. It works great on the "chart" itself not the "watchlist". In the "watchlist column" it has full data history as infinite units of data and all I see is green and 9 with many numbers behind it. On the "chart" the indicator itself gives the option to see only todays premarket data or more than todays premarket data. When I have it checked to everyday is when the massive number data appears on the "chart". When it is the standard indicator settings on the "chart" it matches the current days data and color only. In the "watchlist" there is no option to select only todays data. It should automatically be only todays data as written in the code but it is loading as if I had selected more than todays premarket data. If there is a way to make the "watchlist" register "today only premarket data" instead of the infinite amount of days prior it is currently showing. I know the code should work because it works on the "chart" changing its background no problem.
 
I figured it out thank you again for the addition to the code! You have to change the "aggregation" next to the watchlist column name to 5 min. The problem was it was getting an infinite aggregation from the day chart as that is the default watchlist column setting.
 
I am collecting historical premarket volume data. is there a way to get this in label for YESTERDAY`S PREMARKET VOLUME LABLE?

I have premarket volume label as below but couldn`t figure out how to change it for YESTERDAY`S PREMARKET VOLUME...

input startTime = 400;
input endTime = 929;
def startCounter = SecondsFromTime(startTime);
def endCounter = SecondsTillTime(endTime);
def targetPeriod = if startCounter >= 0 and endCounter >= 0 then 1 else 0;
rec volumeTotal = if targetPeriod and !targetPeriod[1] then volume else if targetPeriod then volumeTotal[1] + volume else volumeTotal[1];
AddLabel(yes, Concat("Premarket: ", volumeTotal), Color.GRAY);

Please help
 
I am collecting historical premarket volume data. is there a way to get this in label for YESTERDAY`S PREMARKET VOLUME LABLE?

I have premarket volume label as below but couldn`t figure out how to change it for YESTERDAY`S PREMARKET VOLUME...

input startTime = 400;
input endTime = 929;
def startCounter = SecondsFromTime(startTime);
def endCounter = SecondsTillTime(endTime);
def targetPeriod = if startCounter >= 0 and endCounter >= 0 then 1 else 0;
rec volumeTotal = if targetPeriod and !targetPeriod[1] then volume else if targetPeriod then volumeTotal[1] + volume else volumeTotal[1];
AddLabel(yes, Concat("Premarket: ", volumeTotal), Color.GRAY);

Please help

Try this.

Ruby:
input startTime  = 400;
input endTime    = 929;
def startCounter = SecondsFromTime(startTime);
def endCounter   = SecondsTillTime(endTime);
def targetPeriod = if startCounter >= 0 and endCounter >= 0 then 1 else 0;
rec volumeTotal  = if targetPeriod and !targetPeriod[1]
                   then volume
                   else if targetPeriod
                   then volumeTotal[1] + volume else volumeTotal[1];
AddLabel(yes, "Today's Premarket: " + volumeTotal, Color.GRAY);

def Save  = if targetPeriod == 1 and targetPeriod[-1] == 0
            then volumeTotal else GetValue(Save, 1);
def Save1 = if  Save != Save[1]
            then Save[1] else GetValue(Save1, 1);
AddLabel(1, "Yesterday's Premarket: " + Save1[1], Color.GRAY);
 
I realize this is an older thread, but as I'm digging deeper with thinkscript, I'm trying to review all the scripts I can get my hands on to ensure I understand everything. If anyone is still monitoring this thread, can someone please explain to me why 'VolumeAtEnd' is added into the below line of code? From what I understand, this only adds the value of 1 to all the results of 'V'. Perhaps this is added to ensure there is never a 0 assigned to V, in the event there is no premarket volume?

Code:
def V = (VolumeAtEnd + VolumeInRange);
 
I realize this is an older thread, but as I'm digging deeper with thinkscript, I'm trying to review all the scripts I can get my hands on to ensure I understand everything. If anyone is still monitoring this thread, can someone please explain to me why 'VolumeAtEnd' is added into the below line of code? From what I understand, this only adds the value of 1 to all the results of 'V'. Perhaps this is added to ensure there is never a 0 assigned to V, in the event there is no premarket volume?

Code:
def V = (VolumeAtEnd + VolumeInRange);
As @SleepyZ yes, it is to deal with the NaN values, as he explained:
to do math on them then you need to maintain yesterday's data yourself in separate variables. In your current script, that data becomes Double.NaN at 9:30. If you look at the title bar of the study it will show N/A for that plot right now. So you either need to try looking back X periods to get the values, which has the problems I described earlier, or maintain those values some place else.
 
Hello,

I have a Pre-Market Volume indicator (code below), but I would like one for Post-Market. I tried changing "PreMarketVol" to "PostMarketVol", but that didn't seem to work. Any help would be greatly appreciated!

Code:
# PreMarketForecast Volume
# TOS
def LabelTime = if SecondsFromTime(0400) > 0 and
                   SecondsTillTime(0930) >= 0
                then 1
                else 0;
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;
def PreMarketVol = if IsNaN(vol) then PreMarketVol[1] else vol;
AddLabel(LabelTime, "PreMarket Volume = " + PreMarketVol, Color.WHITE);
 
Here you go. @didineedaname


The code below is designed to show pre and post mkt volume on any chart 30m and below.


Ruby:
def PreMkt = RegularTradingStart (GetYYYYMMDD()) > GetTime();
def PreVol = if PreMkt and !PreMkt[1] then volume else if PreMkt then PreVol[1] + volume else PreVol[1];
AddLabel(if GetAggregationPeriod() > AggregationPeriod.THIRTY_MIN or !ShowPreMktVol then 0 else 1, "Pre = " + Round(PreVol * .000001, 3) + "M ", Color.YELLOW);

def PostMkt = RegularTradingEnd (GetYYYYMMDD()) < GetTime();
def PostVol = if PostMkt and !PostMkt[1] then volume else if PostMkt then PostVol[1] + volume else PostVol[1];
AddLabel(if GetAggregationPeriod() > AggregationPeriod.THIRTY_MIN or !ShowPostMktVol then 0 else 1, "Post = " + Round(PostVol * .000001, 3) + "M ", Color.YELLOW);
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
517 Online
Create Post

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