Here you goHi
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
# 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
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
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());
def cumVol = if VolumeFromStart then VolumeInRange else cumVol[1];
def previousCumVol =
if GetYYYYMMDD() != GetYYYYMMDD()[1]
then cumVol[1]
else previousCumVol[1]
;
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?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.
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());
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?
It works perfectly now!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.
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);
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);
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
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);
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
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);
def V = (VolumeAtEnd + VolumeInRange);
As @SleepyZ yes, it is to deal with the NaN values, as he explained: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);
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.
# 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);
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);
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Start a new thread and receive assistance from our community.
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.
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.