Find the Nth highest volume within 20 bar

pypl

New member
Hi,
hope you can help.

I am trying to determine if today volume is higher than the 5th highest volume within 20 bar.
In other words, if I rank volume in the last 20 day and pick the 5th highest volume. Then I compare today volume with that 5th highest value.

Clearly, this one give me the highest, how can I add this 5th position in the code?
def past_vol = Highest(Volume, 20);

Can you please help me with that?

Thank you,

HHC
 
Solution
Hi,
hope you can help.

I am trying to determine if today volume is higher than the 5th highest volume within 20 bar.
In other words, if I rank volume in the last 20 day and pick the 5th highest volume. Then I compare today volume with that 5th highest value.

Clearly, this one give me the highest, how can I add this 5th position in the code?
def past_vol = Highest(Volume, 20);

Can you please help me with that?

Thank you,

HHC

something here could be modified
https://usethinkscript.com/threads/rank-volume-1-10.9504/
Hi,
hope you can help.

I am trying to determine if today volume is higher than the 5th highest volume within 20 bar.
In other words, if I rank volume in the last 20 day and pick the 5th highest volume. Then I compare today volume with that 5th highest value.

Clearly, this one give me the highest, how can I add this 5th position in the code?
def past_vol = Highest(Volume, 20);

Can you please help me with that?

Thank you,

HHC

something here could be modified
https://usethinkscript.com/threads/rank-volume-1-10.9504/
 
Solution
I am trying to determine if today volume is higher than the 5th highest volume within 20 bar.
In other words, if I rank volume in the last 20 day and pick the 5th highest volume. Then I compare today volume with that 5th highest value.

compare current volume to the nth highest volume within x bars
(default , 5th highest of 20 bars)

lower study
show gray bubbles above the last x bars
color the nth bubble

label , the volume from the nth bar.
label , the volume from current bar. it is colored, depending on if the current volume is > than the nth volume.


Ruby:
# vol_nth_hi_within20_0

# started with this code
# https://usethinkscript.com/threads/rank-volume-1-10.9504/#post-86495
# Svanoy

declare lower;

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

input Look_Back = 20;
input highest_x_bar = 5;

# true if the last x bars on chart
def lastxbars = ( !isnan(close) and isnan(close[-look_back]));

plot v = volume;
v.setpaintingStrategy(paintingStrategy.HISTOGRAM);
plot zl = 0;

#Rank Last Bar;
#def rank = fold i=1 to Look_Back-1 with rankcounter=1 do if volume>GetValue(volume,i) then rankcounter+1 else rankcounter;
#addlabel(yes,"Ranking: " + rank ,color.white);

#Rolling Rank
def VBar = if !IsNaN(close) then HighestAll(Barnumber()) else VBar[1];

def FinalBar = fold b = 0 to VBar while !IsNaN(GetValue(close,-b)) do GetValue(BarNumber(),-b);

def rank2 = fold r = 0-(FinalBar-BarNumber()) to Look_Back-(FinalBar-BarNumber())
 with rcounter = 1
 do if volume > GetValue(volume,r) then rcounter+1 else rcounter;

def findrank = Look_Back - highest_x_bar;

def findrank_vol = if bn == 1 or !lastxbars then 0
 else if findrank == rank2 then volume
 else findrank_vol[1];


def vol_higher = if (findrank_vol > 0 and volume > findrank_vol) then 1 else 0;

input show_bubbles = yes;
AddChartBubble(show_bubbles and (FinalBar-BarNumber() < Look_Back)
, volume
, rank2
, ( if findrank_vol[1] == 0 and findrank_vol > 0 then color.yellow else color.gray), yes);

addlabel(1, highest_x_bar + " highest rank vol " + findrank_vol, color.yellow);
addlabel(1, "current vol " + volume, (if vol_higher then color.green else color.red));


input test2 = no;
addchartbubble(test2, volume, 
rank2 + "\n" +
findrank + "\n" +
findrank_vol
, color.yellow, no);
#

EMR 10Day 30min
CMPkSpJ.jpg



ref code,
https://usethinkscript.com/threads/rank-volume-1-10.9504/#post-86495
 
compare current volume to the nth highest volume within x bars
(default , 5th highest of 20 bars)

lower study
show gray bubbles above the last x bars
color the nth bubble

label , the volume from the nth bar.
label , the volume from current bar. it is colored, depending on if the current volume is > than the nth volume.


Ruby:
# vol_nth_hi_within20_0

# started with this code
# https://usethinkscript.com/threads/rank-volume-1-10.9504/#post-86495
# Svanoy

declare lower;

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

input Look_Back = 20;
input highest_x_bar = 5;

# true if the last x bars on chart
def lastxbars = ( !isnan(close) and isnan(close[-look_back]));

plot v = volume;
v.setpaintingStrategy(paintingStrategy.HISTOGRAM);
plot zl = 0;

#Rank Last Bar;
#def rank = fold i=1 to Look_Back-1 with rankcounter=1 do if volume>GetValue(volume,i) then rankcounter+1 else rankcounter;
#addlabel(yes,"Ranking: " + rank ,color.white);

#Rolling Rank
def VBar = if !IsNaN(close) then HighestAll(Barnumber()) else VBar[1];

def FinalBar = fold b = 0 to VBar while !IsNaN(GetValue(close,-b)) do GetValue(BarNumber(),-b);

def rank2 = fold r = 0-(FinalBar-BarNumber()) to Look_Back-(FinalBar-BarNumber())
 with rcounter = 1
 do if volume > GetValue(volume,r) then rcounter+1 else rcounter;

def findrank = Look_Back - highest_x_bar;

def findrank_vol = if bn == 1 or !lastxbars then 0
 else if findrank == rank2 then volume
 else findrank_vol[1];


def vol_higher = if (findrank_vol > 0 and volume > findrank_vol) then 1 else 0;

input show_bubbles = yes;
AddChartBubble(show_bubbles and (FinalBar-BarNumber() < Look_Back)
, volume
, rank2
, ( if findrank_vol[1] == 0 and findrank_vol > 0 then color.yellow else color.gray), yes);

addlabel(1, highest_x_bar + " highest rank vol " + findrank_vol, color.yellow);
addlabel(1, "current vol " + volume, (if vol_higher then color.green else color.red));


input test2 = no;
addchartbubble(test2, volume,
rank2 + "\n" +
findrank + "\n" +
findrank_vol
, color.yellow, no);
#

EMR 10Day 30min
CMPkSpJ.jpg



ref code,
https://usethinkscript.com/threads/rank-volume-1-10.9504/#post-86495
how to only see todays volume, trying to make highest volume vs current volume lable
 

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