Opening Volume vs 30d Average Volume

C4men

Member
I seem to be stuck. My code works in that it does two things:
  • Calculates the average volume of the last 30 days
  • Grabs the volume from the current day (first 20 minutes) and compares it to the 30d average (as a label)
It works perfectly on my chart. However, I want to scan intraday for the tickers where that OpenVol is greater than 20%. Something like:
  • CF_OpenVolume()."OpenVol" is greater than or equal to 20
When I go to scan, it returns stocks that do not meet the criteria. It forces me to use 'D', otherwise giving me a secondary aggregation period error.

Is there any hope to edit the code to allow it to work on the chart (as it currently is) AND return results intraday for OpenVol > X?

Code:
## DEF Volume Data
def volLast30DayAvg = (volume(period = "DAY")[1] + volume(period = "DAY")[2] + volume(period = "DAY")[3] + volume(period = "DAY")[4] + volume(period = "DAY")[5] + volume(period = "DAY")[6] + volume(period = "DAY")[7] + volume(period = "DAY")[8] + volume(period = "DAY")[9] + volume(period = "DAY")[10] + volume(period = "DAY")[11] + volume(period = "DAY")[12] + volume(period = "DAY")[13] + volume(period = "DAY")[14] + volume(period = "DAY")[15] + volume(period = "DAY")[16] + volume(period = "DAY")[17] + volume(period = "DAY")[18] + volume(period = "DAY")[19] + volume(period = "DAY")[20] + volume(period = "DAY")[21] + volume(period = "DAY")[22] + volume(period = "DAY")[23] + volume(period = "DAY")[24] + volume(period = "DAY")[25] + volume(period = "DAY")[26] + volume(period = "DAY")[27] + volume(period = "DAY")[28] + volume(period = "DAY")[29] + volume(period = "DAY")[30]) / 30;
def today = volume(period = "DAY");
def percentOf30Day = Round((today / volLast30DayAvg) * 100, 0);

### NEW LINE ###
plot TodayPctVs30Day = percentOf30Day;


## OPENING X MIN VOLUME
input startTime1 = 0930;
input endTime1 = 0949;

def Active1 = SecondsFromTime(startTime1) >= 0 and SecondsTillTime(endTime1) >= 0;
def VolMins1 = if Active1 and !Active1[1] then volume
               else if Active1 then VolMins1[1] + volume
               else VolMins1[1];
plot OpenVol = Round((VolMins1 / volLast30DayAvg) * 100, 0);
#AddLabel(1, "OpenVol: " + VolMins1 + " :: [" + OpenVol + "%] ", Color.CYAN);
AddLabel(1, "OpenVol: " + "[" + OpenVol + "%] " + "/ " + "Pct30d: " + "[" + TodayPctVs30Day + "%] ", Color.CYAN);
 
Solution
so heres the good news... it got it working for you! here you go:
Keep in mind the time interval (value between starttime and endtime must be a multiple of your chart time/aggregation)
as noted, because of the aggregation limitation and error in TOS extended intraday data the daily average volume might have a margin of error by about 1% which is almost nothing because you are averaging anyways.

Cheers, Happy New Years!

Volume at Specified Time Interval Compared to Daily Average

1gUNz71.png


Code:
#Volume at Specified Time Interval Compared to Daily Average
###Please Keep Code Intact if you share
### By XeoNoX via usethinkscript.com
##Note time interval (value between starttime and endtime must be a multiple of your chart...

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

so heres the good news... it got it working for you! here you go:
Keep in mind the time interval (value between starttime and endtime must be a multiple of your chart time/aggregation)
as noted, because of the aggregation limitation and error in TOS extended intraday data the daily average volume might have a margin of error by about 1% which is almost nothing because you are averaging anyways.

Cheers, Happy New Years!

Volume at Specified Time Interval Compared to Daily Average

1gUNz71.png


Code:
#Volume at Specified Time Interval Compared to Daily Average
###Please Keep Code Intact if you share
### By XeoNoX via usethinkscript.com
##Note time interval (value between starttime and endtime must be a multiple of your chart time/aggregation)
input StartTime = 0930;
input Endtime = 940;
input Day_Average = 30;
def na = Double.NaN;
def today=getday()==getlastDay();
def SelectedTime = if GetLastDay() == GetDay() and SecondsFromTime(StartTime) >= 0 and SecondsFromTime(Endtime) < 0 then 1 else 0;
def Selected_Volume = TotalSum(if SelectedTime  then volume else 0);
def timedif = absValue(StartTime-endtime);
def total_min_vol_sum =totalsum(if today then (volume) else 0);
def avg30 = round(average(total_min_vol_sum,Day_Average),0);
def PCT_Open = (Selected_Volume / avg30);

AddLabel (yes, timedif + "Min Vol= " + Selected_Volume);
AddLabel (yes, Day_Average + "D Average= " + avg30);
AddLabel (yes, "Percentage Dif= " + aspercent(PCT_Open));
Found exactly what i was looking for! Thank you!
Any idea how i can take the average of just the first 30 mins bars for the last 5 days instead of the whole 5 days?? & how i can add the labels to upper part of the chart
 
Last edited:
@XeoNoX

Is there a way to create a scan out of this? I have tried myself but have failed. There is nothing for the scanner to plot so I can't get the 10 MIN volume, percent diff or even 30 average.

Also. Forgive me for adding extra work, but is there a way to add color so everything isn't red?

Your help would go a long way.
 
Last edited:
@XeoNoX

Is there a way to create a scan out of this? I have tried myself but have failed. There is nothing for the scanner to plot so I can't get the 10 MIN volume, percent diff or even 30 average.

Also. Forgive me for adding extra work, but is there a way to add color so everything isn't red?

Your help would go a long way.
Not sure what your question is.
It sounds like you are running up against a limitation of the ToS platform.
ToS does not provide for the use of multiple timeframes in Scans, Watchlists, Chart Alerts, Conditional Orders.
 
Last edited:
@XeoNoX

Is there a way to create a scan out of this? I have tried myself but have failed. There is nothing for the scanner to plot so I can't get the 10 MIN volume, percent diff or even 30 average.

Also. Forgive me for adding extra work, but is there a way to add color so everything isn't red?

Your help would go a long way.
there are a few scans posted, you never mentioned which scan you were referencing. you would aslo have to detail what exactly you are trying to scan for.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
379 Online
Create Post

Similar threads

Similar threads

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