Help finding intraday breakouts with time of day volume

pluder

New member
I am working on a scan that would average volume of each bar during regular trading hours over a set period of days (currently set to 3) and compare it to the current bars volume. The intent is to use it on the 30 min period, though it could work on other intraday periods (except ones that do not divide evenly into a 6.5hr trading day). The scan would trigger when the current bars volume is greater than some multiple of the average (right now its set to 2 times). This is the scan as it currently is.
Code:
# 1. Define the RTH condition.
def isRTH = GetTime() >= RegularTradingStart(GetYYYYMMDD()) and GetTime() < RegularTradingEnd(GetYYYYMMDD());

# 2. Define the time condition by counting unique trading days.
def isNewDay = GetDay() != GetDay()[1];
def dayNumber = CompoundValue(1, if isNewDay then dayNumber[1] + 1 else dayNumber[1], 1);
def lastDayNumber = HighestAll(dayNumber);
def isWithin3Days = dayNumber > lastDayNumber - 3;

# 3. Combine the conditions to identify the target bars.
def finalCondition = isRTH and isWithin3Days;

# 4. Sum the volume of only the target bars.
def totalVolume = TotalSum(if finalCondition then volume else 0);
def numberOfBarsSummed = TotalSum(if finalCondition then 1 else 0);
def AvgVol = totalVolume/numberOfBarsSummed;

plot Scan = isRTH and volume > AvgVol * 2;

I also have a study with the same logic that I have been using to tune the scan and make sure it will function as desired.

Code:
# 1. Define the RTH condition.
def isRTH = GetTime() >= RegularTradingStart(GetYYYYMMDD()) and GetTime() < RegularTradingEnd(GetYYYYMMDD());

# 2. Define the time condition by counting unique trading days.
def isNewDay = GetDay() != GetDay()[1];
def dayNumber = CompoundValue(1, if isNewDay then dayNumber[1] + 1 else dayNumber[1], 1);
def lastDayNumber = HighestAll(dayNumber);
def isWithin3Days = dayNumber > lastDayNumber - 3;

# 3. Combine the conditions to identify the target bars.
def finalCondition = isRTH and isWithin3Days;

# 4. Sum the volume of only the target bars.
def totalVolume = TotalSum(if finalCondition then volume else 0);
def numberOfBarsSummed = TotalSum(if finalCondition then 1 else 0);
def AvgVol = totalVolume/numberOfBarsSummed;

#debug----

addLabel (yes,"number of bars " + numberOfBarsSummed,Color.white); 
addLabel (yes,"Avg Bar Volume " + AvgVol,Color.white); 
AddLabel(yes, "3-Day RTH Volume: " + totalVolume, Color.WHITE);

#output----

# B. Plot an arrow on each bar being included in the sum.
plot highBar_Arrow = isRTH and volume > AvgVol * 2;

highBar_Arrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
highBar_Arrow.SetDefaultColor(Color.WHITE);

Currently the study works as i desire, but the scan does not work consistently. The problem is that it does not always provide accurate results when compared to the study. My guess is that this issue is due to the scanners inability to pull all the data needed to accurately sum the volume though I'm not sure if that is the cause.

I would appreciate any advise on how to resolve the issue or change the script to accomplish the goal.
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
577 Online
Create Post

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