didineedaname
New member
Thank you for the prompt reply, @SuryaKiranC! I can't seem to get it to work. I have attached screenshots below of what it shows when I try to create a new study.
Last edited by a moderator:
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
This is part of my larger script, you are missing that ShowPreMktVol and ShowPostMktVol variables on the top. you can remove them, or simply define them.Thank you for the prompt reply, @SuryaKiranC! I can't seem to get it to work. I have attached screenshots below of what it shows when I try to create a new study.
input ShowPreMktVol = Yes;
input ShowPostMktVol = Yes;
Tracks the price difference from afterhours volume relative to yesterday's close. This was created to visually confirm if certain stock prices were primarily driven from afterhours movements over longer periods of time.
# AfterHoursRelativePriceMovement tracks the price difference from afterhour volume relative to yesterday's close
# This was created so I could eyeball if certain stock prices were primarily driven from afterhour movements over longer periods of time
# Can be overlaid with AddMarketHoursUTC to visually see correlation from international market open/closes
# Inputting Market Hours is required due to thinkscript's date function limitations
input marketOpen = 0930;
input marketClose = 1600;
# AFAIK there is no better way to do this due to SecondsTillTime rolling over after midnight, lack of real date math, and the mish-mash of UTC/EST time handling from thinkscript
def isClosedMorning = if SecondsTillTime(marketOpen) > 0 then yes else no;
def isClosedNight = if SecondsTillTime(marketClose) < 0 then yes else no;
def change = if !isClosedMorning AND !isClosedNight then 0 else change[1] + (hl2 - hl2[1]);
plot yesterdayPrice = 0;
plot priceDifference = if change != 0 then change else Double.NaN;
priceDifference.AssignValueColor(if priceDifference > 0 then Color.UPTICK else if priceDifference < 0 then Color.DOWNTICK else Color.GRAY);
# This is to visually encapsulate a week because weekend price movements can be funky
def isStartOfWeek = if GetDayOfWeek(GetYYYYMMDD()) == 1 then yes else no;
def isEndOfWeek = if GetDayOfWeek(GetYYYYMMDD()) == 5 then yes else no;
AddVerticalLine(isStartOfWeek AND SecondsTillTime(marketOpen) == 0, "Monday Open", Color.GREEN);
AddVerticalLine(isEndOfWeek AND SecondsTillTime(marketClose) == 0, "Friday Close", Color.RED);
# PreMarket Volume, High, Low Label
# TOS
# Mobius
input beginLabel = 0600;
input endLabel = 1030;
def LabelTime = if SecondsFromTime(beginLabel) > 0 and
SecondsTillTime(endLabel) >= 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;
def PreMarketHigh = if isRollover and beforeStart
then High
else if beforeStart and high > PreMarketHigh[1]
then high
else PreMarketHigh[1];
def PreMarketLow = if isRollover and beforeStart
then Low
else if beforeStart and low < PreMarketLow[1]
then low
else PreMarketLow[1];
def r = PreMarketHigh - PreMarketLow;
def v = if secondsTillTime(0930) == 0 and
secondsFromTime(0930) == 0
then v[1] + preMarketVol
else v[1];
def t = if secondsTillTime(0000) == 0
then t[1] + 1
else t[1];
def AvgV = v / t;
AddLabel(LabelTime, "PreMarket Volume = " + PreMarketVol +
" Avg PreMarket over " + t + " days = " + Round(AvgV, 0) +
" PreMarket High = " + AsDollars(PreMarketHigh) +
" PreMarket Low = " + AsDollars(PreMarketLow) +
" Range = " + AsDollars(r), Color.WHITE);
# End Label PreMarket Volume, High, Low
# TOS
# Mobius
input beginLabel = 0400;
input endLabel = 1000;
def LabelTime = if SecondsFromTime(beginLabel) > 0 and
SecondsTillTime(endLabel) >= 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;
def v = if secondsTillTime(0930) == 0 and
secondsFromTime(0930) == 0
then v[1] + preMarketVol
else v[1];
def PMVF = PremarketVol;
AddLabel(LabelTime, "PM: " + RoundUp(PMVF*0.000001, 2) + "m",(if PMVF <= 20 then Color.GREEN else if PMVF >= 100 then Color.ORANGE else Color.WHITE) );
Declare lower;
input ShowPreMktVol = Yes;
input ShowPostMktVol = Yes;
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.ORANGE);
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.ORANGE);
###
def PreDV = (hl2 * PreVol) / 1000000;
AddLabel(yes, "$ " + Round(PreDV, 1) + "m" + " PreDV" , Color.CYAN);
def PostDV = (hl2 * PostVol) / 1000000;
AddLabel(yes, "$ " + Round(PostDV, 1) + "m" + " PostDV" , Color.CYAN);
Having the same problem, report back if you figure it out firstI got this Mobius Premarket script from this thread.
I only wanted the Premarket Volume portion of the script so I stripped it down to the following code.Code:# PreMarket Volume, High, Low Label # TOS # Mobius input beginLabel = 0600; input endLabel = 1030; def LabelTime = if SecondsFromTime(beginLabel) > 0 and SecondsTillTime(endLabel) >= 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; def PreMarketHigh = if isRollover and beforeStart then High else if beforeStart and high > PreMarketHigh[1] then high else PreMarketHigh[1]; def PreMarketLow = if isRollover and beforeStart then Low else if beforeStart and low < PreMarketLow[1] then low else PreMarketLow[1]; def r = PreMarketHigh - PreMarketLow; def v = if secondsTillTime(0930) == 0 and secondsFromTime(0930) == 0 then v[1] + preMarketVol else v[1]; def t = if secondsTillTime(0000) == 0 then t[1] + 1 else t[1]; def AvgV = v / t; AddLabel(LabelTime, "PreMarket Volume = " + PreMarketVol + " Avg PreMarket over " + t + " days = " + Round(AvgV, 0) + " PreMarket High = " + AsDollars(PreMarketHigh) + " PreMarket Low = " + AsDollars(PreMarketLow) + " Range = " + AsDollars(r), Color.WHITE); # End Label PreMarket Volume, High, Low
Everything seemed to be working fine but then I compared the Premarket Value to the 'Volume' Column of my morning watchlist and saw a significant difference. What is going wrong here?Code:# TOS # Mobius input beginLabel = 0400; input endLabel = 1000; def LabelTime = if SecondsFromTime(beginLabel) > 0 and SecondsTillTime(endLabel) >= 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; def v = if secondsTillTime(0930) == 0 and secondsFromTime(0930) == 0 then v[1] + preMarketVol else v[1]; def PMVF = PremarketVol; AddLabel(LabelTime, "PM: " + RoundUp(PMVF*0.000001, 2) + "m",(if PMVF <= 20 then Color.GREEN else if PMVF >= 100 then Color.ORANGE else Color.WHITE) );
# ToS Volume
input Xdays = 50 ;
plot plotavgVolume = average(volume,Xdays);
# PreMarket Volume
# Mobius
input beginLabel = 0600;
input endLabel = 1030;
def LabelTime = if SecondsFromTime(beginLabel) > 0 and
SecondsTillTime(endLabel) >= 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;
plot PreMarketVolume = PreMarketVol ;
# % change Volume vs PreMarket Volume
input beginLabel = 0600;
input endLabel = 1030;
def LabelTime = if SecondsFromTime(beginLabel) > 0 and
SecondsTillTime(endLabel) >= 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;
def PMV = PreMarketVol;
input Xdays = 50 ;
def avgVolume = average(volume,Xdays);
plot pct = round((avgVolume-PMV)/PMV*100,2);
This is really a nice idea and awesome for pre-market, just wondering if there is a way to roll this concept in to regular hours trading and put that percentage over a 50-day average? that would really help gauge a move on breakouts and breakdownsThanks 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
I just wanted to point out a small mistake here for ya, these need to be the same of course.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);
So this is 3 stocks with over 1M volume right now (PM Volume column is yours), how do these numbers make sense? And again, the standard scanner for 1M volume ($20-$500) did find them, so ToS knows they have 1M PM volume. I didn't use your scanner since a standard scan for 1M volume finds them just fine.This works like a charm.....
Code:def PremarketVolume = if getday() != Getlastday() then 0 else if PremarketVolume[1] == 0 then volume else if secondsFromtime(0400) >= 0 and secondsFromTime(0930) < 0 then volume+PremarketVolume[1] else PremarketVolume[1]; Plot PremarketV = PremarketVolume;
def PremarketVolume = if getday() != Getlastday() then 0 else if PremarketVolume[1] == 0 then volume else if secondsFromtime(0400) >= 0 and secondsFromTime(0930) < 0 then volume+PremarketVolume[1] else PremarketVolume[1];
Plot PremarketV = PremarketVolume;
Def requiredVolume = 100000;
def premarketStart = 0400;
def premarketEnd = 0930;
def premarketVolume = if getday() != Getlastday() then 0 else if PremarketVolume[1] == 0 then volume else if secondsFromtime(premarketStart) >= 0 and secondsFromTime(premarketEnd) < 0 then volume+premarketVolume[1] else PremarketVolume[1];
Plot PremarketV = if premarketVolume >=requiredVolume then 1 else 0;
So this is 3 stocks with over 1M volume right now (PM Volume column is yours), how do these numbers make sense? And again, the standard scanner for 1M volume ($20-$500) did find them, so ToS knows they have 1M PM volume. I didn't use your scanner since a standard scan for 1M volume finds them just fine.This works like a charm.....
Code:def PremarketVolume = if getday() != Getlastday() then 0 else if PremarketVolume[1] == 0 then volume else if secondsFromtime(0400) >= 0 and secondsFromTime(0930) < 0 then volume+PremarketVolume[1] else PremarketVolume[1]; Plot PremarketV = PremarketVolume;
def PremarketVolume = if getday() != Getlastday() then 0 else If secondsFromTime(0400) >= 0 and SecondsFromTime(0930) < 0 then volume+PremarketVolume[1] else PremarketVolume[1];
def VolumeR = If SecondsFromTime(0400) >= 0 and SecondsFromTime(0930) < 0 then Volumer[1]+Volume else 0;
Plot PremarketV = If secondsFromTime(0400) >= 0 and SecondsFromTime(0930) < 0 then VolumeR else PremarketVolume;
TSLA this morning has just over 1mil volume, this is what it says:Updated Code at 6:44 PM EST
Make sure you have the watchlist column on 1 minute and extended hours box checked (as I know that works). Another reason it could have been wrong is because if there is no premarket volume on the current day, it would have showed you yesterdays premarket volume (or whatever day previously had premarket volume). That's never an issue for me because I also have the default volume column next to my premarket volume and if they are different (during premarket only), I know it's showing the previous day's data. I did modify it so it should now show 0 if there is no premarket volume.
Code:def PremarketVolume = if getday() != Getlastday() then 0 else If secondsFromTime(0400) >= 0 and SecondsFromTime(0930) < 0 then volume+PremarketVolume[1] else PremarketVolume[1]; def VolumeR = If SecondsFromTime(0400) >= 0 and SecondsFromTime(0930) < 0 then Volumer[1]+Volume else 0; Plot PremarketV = If secondsFromTime(0400) >= 0 and SecondsFromTime(0930) < 0 then VolumeR else PremarketVolume;
I'm not sure you were looking at the TSLA chart when you checked. This only pulls in premarket data. Maybe you were looking at yesterday's post market and today's premarket cumulatively? The total premarket volume for Tsla today was 795,403 and when you took that screenshot, it was 533,412. Take a look:TSLA this morning has just over 1mil volume, this is what it says:
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.