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...

Similar threads

Top