# volumefirstbar_xdays
# look at prev 20 days,
# read volume of 1st bar,
# add them up and calc an average,
# check if todays 1st bar vol > than the avg vol
#prev 20 days, exclude current day
input dayz = 20;
def bn = barnumber();
#---------------------------------------------
#firstbar , get from code in link below
#first last bar of day...
# volumefirstbar_xdays
# look at prev 20 days,
# read volume of 1st bar,
# add them up and calc an average,
# check if todays 1st bar vol > than the avg vol
#prev 20 days, exclude current day
input dayz = 20;
def bn = barnumber();
#---------------------------------------------
#firstbar , get from code in link below
#first last bar of day
#https://usethinkscript.com/threads/finding-the-first-and-last-bar-of-the-day-in-thinkorswim.526/
def nan = Double.NaN;
def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1];
def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD());
def afterEnd = GetTime() > RegularTradingEnd(GetYYYYMMDD());
def firstBarOfDay = if (beforeStart[1] == 1 and beforeStart == 0) or (isRollover and beforeStart == 0) then 1 else 0;
#---------------------------------------------
input agg = AggregationPeriod.DAY;
# dayz1st=if !isnan(close(period = agg[-(dayz+1)] ) and isnan(close(period = agg)[-(dayz+2)] ) then 1 else 0;
# enable for valid period of days
def dayzen =
if !isnan(close(period = agg)[-1] )
and
isnan(close(period = agg)[-(dayz+2)] )
then 1 else 0;
# vol of 1st bar
def vol1 = if bn == 1 then 0
else if (dayzen and firstBarOfDay) then volume else vol1[1];
# total vol in period
def vol1ttl = if bn == 1 then 0
else if ( dayzen and firstbarofday) then
vol1ttl[1] + volume
else vol1ttl[1];
def vol1avg = round(vol1ttl / dayz, 0);
def vol_ismore = ( vol1 > vol1avg);
addlabel(1,
"volume average of 1st bar, in " + dayz + " prev days, is " + vol1avg + ". todays 1st bar vol is " + vol1,
(if vol_ismore then color.green else color.red) );
#
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
is there a way to get a relative volume indicator that tells rel volume of a SPECIFIC candle compared to that same ci am away from my computer, just typing into a text editor on my phone....
i hope this works or is close enough to get you what you want.
Code:# look at prev 20 days, # read volume of 1st bar, # add them up and calc an average, # check if todays 1st bar vol > than the avg vol #prev 20 days, exclude current day input dayz = 20 #--------------------------------------------- #firstbar , get from code in link below #first last bar of day #https://usethinkscript.com/threads/finding-the-first-and-last-bar-of-the-day-in-thinkorswim.526/ def nan = Double.NaN; def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1]; def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD()); def afterEnd = GetTime() > RegularTradingEnd(GetYYYYMMDD()); def firstBarOfDay = if (beforeStart[1] == 1 and beforeStart == 0) or (isRollover and beforeStart == 0) then 1 else 0; #--------------------------------------------- input agg = AggregationPeriod.DAY; # dayz1st=if !isnan(close(period = agg[-(dayz+1)] ) and isnan(close(period = agg)[-(dayz+2)] ) then 1 else 0; # enable for valid period of days dayzen = if !isnan(close(period = agg)[-1] ) and isnan(close(period = agg)[-(dayz+2)] ) then 1 else 0; # vol of 1st bar vol1 = if bn == 1 then 0 else if (dayzen and firstBarOfDay) then volume else vol1[1]; # total vol in period vol1ttl = if bn == 1 then 0 else if ( dayzen and firstbarofday) then vol1ttl[1] + volume else vol1ttl[1]; volavg1 = round(vol1ttl / dayz, 0) def vol_ismore = ( vol1 > vol1avg); addlabel(1, "volume average of 1st bar, in " + dayz + " prev days, is " + volavg1 + ". todays 1st bar vol is " + vol1, (if vol_ismore then color.green else color.red) ); #
I'm not sure about 12 days, but I put this one together a while back:is there a way to get a relative volume indicator that tells rel volume of a SPECIFIC candle compared to that same c
andle for the last 12 days?
Would this be useful to determine if this was to be a trend day vs a range day, or to determine risk on vs risk off?I am trying to find a way to compare the volume of the first bar of today with the volume of the first bar on the last 20 days. Is that possible?
there is an error on line 7 and line 14i am away from my computer, just typing into a text editor on my phone....
i hope this works or is close enough to get you what you want.
Code:# look at prev 20 days, # read volume of 1st bar, # add them up and calc an average, # check if todays 1st bar vol > than the avg vol #prev 20 days, exclude current day input dayz = 20 #--------------------------------------------- #firstbar , get from code in link below #first last bar of day #https://usethinkscript.com/threads/finding-the-first-and-last-bar-of-the-day-in-thinkorswim.526/ def nan = Double.NaN; def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1]; def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD()); def afterEnd = GetTime() > RegularTradingEnd(GetYYYYMMDD()); def firstBarOfDay = if (beforeStart[1] == 1 and beforeStart == 0) or (isRollover and beforeStart == 0) then 1 else 0; #--------------------------------------------- input agg = AggregationPeriod.DAY; # dayz1st=if !isnan(close(period = agg[-(dayz+1)] ) and isnan(close(period = agg)[-(dayz+2)] ) then 1 else 0; # enable for valid period of days dayzen = if !isnan(close(period = agg)[-1] ) and isnan(close(period = agg)[-(dayz+2)] ) then 1 else 0; # vol of 1st bar vol1 = if bn == 1 then 0 else if (dayzen and firstBarOfDay) then volume else vol1[1]; # total vol in period vol1ttl = if bn == 1 then 0 else if ( dayzen and firstbarofday) then vol1ttl[1] + volume else vol1ttl[1]; volavg1 = round(vol1ttl / dayz, 0) def vol_ismore = ( vol1 > vol1avg); addlabel(1, "volume average of 1st bar, in " + dayz + " prev days, is " + volavg1 + ". todays 1st bar vol is " + vol1, (if vol_ismore then color.green else color.red) ); #
Many lines needed to be redone!there is an error on line 7 and line 14
thank you.Dang @halcyonguy, you can type that on your phone?!? respect! I work in a text editor a lot, but I don't try that on a phone.
i fixed my code in post #2I am trying to find a way to compare the volume of the first bar of today with the volume of the first bar on the last 20 days. Is that possible?
thanks this is what I was looking for. Very cool trying it out now.i am away from my computer, just typing into a text editor on my phone....
i hope this works or is close enough to get you what you want.
=== EDIT =====
well my original post had a few more errors than i thought. missing ; and def
here is the fixed code.
pick a time period with enough days to pull the data.
Code:# volumefirstbar_xdays # look at prev 20 days, # read volume of 1st bar, # add them up and calc an average, # check if todays 1st bar vol > than the avg vol #prev 20 days, exclude current day input dayz = 20; def bn = barnumber(); #--------------------------------------------- #firstbar , get from code in link below #first last bar of day #https://usethinkscript.com/threads/finding-the-first-and-last-bar-of-the-day-in-thinkorswim.526/ def nan = Double.NaN; def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1]; def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD()); def afterEnd = GetTime() > RegularTradingEnd(GetYYYYMMDD()); def firstBarOfDay = if (beforeStart[1] == 1 and beforeStart == 0) or (isRollover and beforeStart == 0) then 1 else 0; #--------------------------------------------- input agg = AggregationPeriod.DAY; # dayz1st=if !isnan(close(period = agg[-(dayz+1)] ) and isnan(close(period = agg)[-(dayz+2)] ) then 1 else 0; # enable for valid period of days def dayzen = if !isnan(close(period = agg)[-1] ) and isnan(close(period = agg)[-(dayz+2)] ) then 1 else 0; # vol of 1st bar def vol1 = if bn == 1 then 0 else if (dayzen and firstBarOfDay) then volume else vol1[1]; # total vol in period def vol1ttl = if bn == 1 then 0 else if ( dayzen and firstbarofday) then vol1ttl[1] + volume else vol1ttl[1]; def vol1avg = round(vol1ttl / dayz, 0); def vol_ismore = ( vol1 > vol1avg); addlabel(1, "volume average of 1st bar, in " + dayz + " prev days, is " + vol1avg + ". todays 1st bar vol is " + vol1, (if vol_ismore then color.green else color.red) ); #
If I am using premarket data to drive an ORB target and then get a big price move in the opening bar I want to know that the big price range is due to abnormal volume in hopes that it can be sustained for a few bars. This is in comparison to a huge swing in price but little to no relative volume and therefore the price immediately reverses.Would this be useful to determine if this was to be a trend day vs a range day, or to determine risk on vs risk off?
i don't think 2nd agg is allowed in scan scripts.@halcyonguy First I really appericate this. Thank you so much. Very cool and it helps me out a lot with the scripting in regards to timing and start of day. However, Why wouldn't I be able to put this in a scan? I replaced the label with a "plot scan = vol_ismore;" and it doesn't return anything. But I can use it as a strategy on the chart and it works like a charm.
Thanks again, Daniel
Your right.i don't think 2nd agg is allowed in scan scripts.
there is an error on line 7 and line 14
Hello,i am away from my computer, just typing into a text editor on my phone....
i hope this works or is close enough to get you what you want.
=== EDIT =====
well my original post had a few more errors than i thought. missing ; and def
here is the fixed code.
pick a time period with enough days to pull the data.
Code:# volumefirstbar_xdays # look at prev 20 days, # read volume of 1st bar, # add them up and calc an average, # check if todays 1st bar vol > than the avg vol #prev 20 days, exclude current day input dayz = 20; def bn = barnumber(); #--------------------------------------------- #firstbar , get from code in link below #first last bar of day #https://usethinkscript.com/threads/finding-the-first-and-last-bar-of-the-day-in-thinkorswim.526/ def nan = Double.NaN; def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1]; def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD()); def afterEnd = GetTime() > RegularTradingEnd(GetYYYYMMDD()); def firstBarOfDay = if (beforeStart[1] == 1 and beforeStart == 0) or (isRollover and beforeStart == 0) then 1 else 0; #--------------------------------------------- input agg = AggregationPeriod.DAY; # dayz1st=if !isnan(close(period = agg[-(dayz+1)] ) and isnan(close(period = agg)[-(dayz+2)] ) then 1 else 0; # enable for valid period of days def dayzen = if !isnan(close(period = agg)[-1] ) and isnan(close(period = agg)[-(dayz+2)] ) then 1 else 0; # vol of 1st bar def vol1 = if bn == 1 then 0 else if (dayzen and firstBarOfDay) then volume else vol1[1]; # total vol in period def vol1ttl = if bn == 1 then 0 else if ( dayzen and firstbarofday) then vol1ttl[1] + volume else vol1ttl[1]; def vol1avg = round(vol1ttl / dayz, 0); def vol_ismore = ( vol1 > vol1avg); addlabel(1, "volume average of 1st bar, in " + dayz + " prev days, is " + vol1avg + ". todays 1st bar vol is " + vol1, (if vol_ismore then color.green else color.red) ); #
It is not possible to say where you went astray from the image.Hello,
Thanks for this script .I added this but some how the script is not showing current bar volume
Say for example in this TSLA example on 15minute chart first one bar volume is actually 2,459,654 but Script is displaying
1,129,989.
Please look into this and let me know if iam missing anything here
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
C | Plot Horizontal Lines Relative to Open | Questions | 1 | |
S | scan help for relative volume | Questions | 0 | |
J | "Simple" Relative Performance Chart | Questions | 4 | |
A | Pin Bar Reversal + Relative Volume | Questions | 0 | |
using Relative Volume and Volume profiles | Questions | 2 |
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.