highest daily volume over custom date range

TraderRob

New member
Hello All. New member here and beginner thinkscript user.
Script for identifying highest daily volume over custom date range

I would like to create a basic scan that looks at the most recent "X" days volume (excluding current day) and comparing it to the daily high volume over the previous "Y" days/bars (excluding current day and most recent "X" number of days. Ultimate use is to create a scan based on price range, minimum volume, perhaps market cap and then meeting the criteria where the most recent X days daily volume are greater than the previous Y days highest day.

I've been able to use the basic Volume[] script to get previous days volume. See below.

def D1 = volume[1] ;
def D2 = volume[2] ;
def D3 = volume[3] ;

Then I suppose I need a way to find the previous daily high. In a somewhat human readable format: PreviousHigh = HighestDailyVolume between D4 through D180. I know this nowhere near actual thinkscript.

Once I have the PreviousHigh, let's call it PH, then I would like to add conditions where D1>PH and D2>PH and D3>PH.

All the scripts I've found that identify the PH use a length that include the current day...or the previous day at best. Below is the closest one I could find and somewhat (actually not really) understand. Hoping there is an easier way. Appreciate any insight more experienced users may have.

def IsDaily = GetAggregationPeriod() == AggregationPeriod.DAY ;
#def IsWeekly = GetAggregationPeriod() == AggregationPeriod.WEEK;
#def Ismonthly = GetAggregationPeriod() == AggregationPeriod.MONTH ;
def length = 4 ;
#else if IsWeekly then 52 else if Ismonthly then 12 else Double.NaN;

def LastBar = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) then BarNumber() else Double.NaN);
def BarCD = LastBar - BarNumber() <= length;
def HighVol = HighestAll(if BarCD then volume else Double.NaN);
#def highvol = HighestAll(volume);
plot VolLine = if BarCD then HighVol else Double.NaN;

plot top = if volume == HighVol then volume else Double.NaN;
top.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
top.SetDefaultColor(Color.WHITE);
top.SetLineWeight(5);
 
Last edited by a moderator:
Solution
Hello All. New member here and beginner thinkscript user.
Script for identifying highest daily volume over custom date range

I would like to create a basic scan that looks at the most recent "X" days volume (excluding current day) and comparing it to the daily high volume over the previous "Y" days/bars (excluding current day and most recent "X" number of days. Ultimate use is to create a scan based on price range, minimum volume, perhaps market cap and then meeting the criteria where the most recent X days daily volume are greater than the previous Y days highest day.

I've been able to use the basic Volume[] script to get previous days volume. See below.

def D1 = volume[1] ;
def D2 = volume[2] ;
def D3 = volume[3] ;

Then I...
Hello All. New member here and beginner thinkscript user.
Script for identifying highest daily volume over custom date range

I would like to create a basic scan that looks at the most recent "X" days volume (excluding current day) and comparing it to the daily high volume over the previous "Y" days/bars (excluding current day and most recent "X" number of days. Ultimate use is to create a scan based on price range, minimum volume, perhaps market cap and then meeting the criteria where the most recent X days daily volume are greater than the previous Y days highest day.

I've been able to use the basic Volume[] script to get previous days volume. See below.

def D1 = volume[1] ;
def D2 = volume[2] ;
def D3 = volume[3] ;

Then I suppose I need a way to find the previous daily high. In a somewhat human readable format: PreviousHigh = HighestDailyVolume between D4 through D180. I know this nowhere near actual thinkscript.

Once I have the PreviousHigh, let's call it PH, then I would like to add conditions where D1>PH and D2>PH and D3>PH.

All the scripts I've found that identify the PH use a length that include the current day...or the previous day at best. Below is the closest one I could find and somewhat (actually not really) understand. Hoping there is an easier way. Appreciate any insight more experienced users may have.

def IsDaily = GetAggregationPeriod() == AggregationPeriod.DAY ;
#def IsWeekly = GetAggregationPeriod() == AggregationPeriod.WEEK;
#def Ismonthly = GetAggregationPeriod() == AggregationPeriod.MONTH ;
def length = 4 ;
#else if IsWeekly then 52 else if Ismonthly then 12 else Double.NaN;

def LastBar = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) then BarNumber() else Double.NaN);
def BarCD = LastBar - BarNumber() <= length;
def HighVol = HighestAll(if BarCD then volume else Double.NaN);
#def highvol = HighestAll(volume);
plot VolLine = if BarCD then HighVol else Double.NaN;

plot top = if volume == HighVol then volume else Double.NaN;
top.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
top.SetDefaultColor(Color.WHITE);
top.SetLineWeight(5);

sorry i don't understand what you are asking for.
do you want to find the max volume , during some group of previous bars?

you say date range , then use bars and lengths in the code.
you say scan, what do you want to scan for? volume is a number, not a true/false value.

-------------------------

here is something that may be part of what you want?

Code:
def na = double.nan;
def bn = barnumber();

input recent_days_offset = 5;
input days_range = 8;

def rng_start = !isnan(close[-(recent_days_offset + days_range - 1)]) and isnan(close[-(recent_days_offset + days_range+0)]);
def rng_end = !isnan(close[-(recent_days_offset)]) and isnan(close[-(recent_days_offset+1)]);

def rng = if bn == 1 then 0
 else if rng_start then 1
 else if rng_end[1] then 0
 else rng[1];

def hivol = if bn == 1 then 0
 else if rng_start then highest(volume[-days_range], days_range) 
 else hivol[1];

plot z1 = if rng then hivol else na;
z1.SetDefaultColor(Color.yellow);

input test_lines = no;
addverticalline(test_lines and rng_start, "-");
addverticalline(test_lines and rng_end[1], "-");

addlabel(1,
"highest volume: " + hivol + ". over " + days_range + " days, " + recent_days_offset + " days back"
, color.yellow);
#
 

Attachments

  • Capture.JPG
    Capture.JPG
    61.1 KB · Views: 75
Solution

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
412 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