color the 10 highest volume bars For ThinkOrSwim

halcyonguy

Moderator - Expert
VIP
Lifetime
this is a lower study, that will color the 10 highest volume bars.

if you want it to appear on the volume chart, disable the 'declare lower' line, and drag the name into the volume chart section.


Ruby:
# top10_vol_bars_01

# color the top 10 vol bars

declare lower;

def na = Double.NaN;
def bn = BarNumber();

def v = volume;
# use highestall x times

def v1 = highestall( v );
def v2 = highestall( if v < v1 then v else 0);
def v3 = highestall( if v < v2 then v else 0);
def v4 = highestall( if v < v3 then v else 0);
def v5 = highestall( if v < v4 then v else 0);
def v6 = highestall( if v < v5 then v else 0);
def v7 = highestall( if v < v6 then v else 0);
def v8 = highestall( if v < v7 then v else 0);
def v9 = highestall( if v < v8 then v else 0);
def v10 = highestall( if v < v9 then v else 0);

def x1 = if v == v1 then 1 else 0;
def x2 = if v == v2 then 1 else 0;
def x3 = if v == v3 then 1 else 0;
def x4 = if v == v4 then 1 else 0;
def x5 = if v == v5 then 1 else 0;
def x6 = if v == v6 then 1 else 0;
def x7 = if v == v7 then 1 else 0;
def x8 = if v == v8 then 1 else 0;
def x9 = if v == v9 then 1 else 0;
def x10 = if v == v10 then 1 else 0;

def bars = (x1 or x2 or x3 or x4 or x5 or x6 or x7 or x8 or x9 or x10);
 
plot z = v;
z.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
z.AssignValueColor(if bars then color.green else color.gray);
#


vphgT6M.jpg


https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Look---Feel/AssignValueColor

might be able to use the priceline code, with 1000 offset instead of highestall...
https://usethinkscript.com/threads/current-price-line-indicator-for-thinkorswim.8793/
 
Thank you for sharing @halcyonguy!! Not sure that its working as I am understanding it should? I'd like to see x number of highest volume bars within the last y number of bars. This code is only showing me 1 bar from yesterday on the 5 min /NQ chart. Appreciate any response/feedback greatly !!
 
this is a lower study, that will color the 10 highest volume bars.

if you want it to appear on the volume chart, disable the 'declare lower' line, and drag the name into the volume chart section.


Ruby:
# top10_vol_bars_01

# color the top 10 vol bars

declare lower;

def na = Double.NaN;
def bn = BarNumber();

def v = volume;
# use highestall x times

def v1 = highestall( v );
def v2 = highestall( if v < v1 then v else 0);
def v3 = highestall( if v < v2 then v else 0);
def v4 = highestall( if v < v3 then v else 0);
def v5 = highestall( if v < v4 then v else 0);
def v6 = highestall( if v < v5 then v else 0);
def v7 = highestall( if v < v6 then v else 0);
def v8 = highestall( if v < v7 then v else 0);
def v9 = highestall( if v < v8 then v else 0);
def v10 = highestall( if v < v9 then v else 0);

def x1 = if v == v1 then 1 else 0;
def x2 = if v == v2 then 1 else 0;
def x3 = if v == v3 then 1 else 0;
def x4 = if v == v4 then 1 else 0;
def x5 = if v == v5 then 1 else 0;
def x6 = if v == v6 then 1 else 0;
def x7 = if v == v7 then 1 else 0;
def x8 = if v == v8 then 1 else 0;
def x9 = if v == v9 then 1 else 0;
def x10 = if v == v10 then 1 else 0;

def bars = (x1 or x2 or x3 or x4 or x5 or x6 or x7 or x8 or x9 or x10);
 
plot z = v;
z.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
z.AssignValueColor(if bars then color.green else color.gray);
#


View attachment 13790

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Look---Feel/AssignValueColor

might be able to use the priceline code, with 1000 offset instead of highestall...
https://usethinkscript.com/threads/current-price-line-indicator-for-thinkorswim.8793/
Can you please include the code so that I can have a watchlist column that shows when one of my stocks just had one of its top ten daily volumes?
 
Is there a way I can just paint the candles with top 3 volume bars in purple color? Leave the Volume bar color as is and just paint the candle.
 
Is there a way I can just paint the candles with top 3 volume bars in purple color? Leave the Volume bar color as is and just paint the candle.

Code:
# x_highest_vol_color_bar

#https://usethinkscript.com/threads/color-the-10-highest-volume-bars-for-thinkorswim.10440/
#PAYtience  #4
#Is there a way I can just paint the candles with top 3 volume bars in purple color? Leave the Volume bar color as is and just paint the candle.

# top10_vol_bars_01
# color the top 10 vol bars
#declare lower;
def na = Double.NaN;
def bn = BarNumber();

def v = volume;
# use highestall x times

input qty = 3;

def v1 = HighestAll( v );
def v2 = HighestAll( if qty >= 2 and v < v1 then v else 0);
def v3 = HighestAll( if qty >= 3 and v < v2 then v else 0);
def v4 = HighestAll( if qty >= 4 and v < v3 then v else 0);
def v5 = HighestAll( if qty >= 5 and v < v4 then v else 0);
def v6 = HighestAll( if qty >= 6 and v < v5 then v else 0);
def v7 = HighestAll( if qty >= 7 and v < v6 then v else 0);
def v8 = HighestAll( if qty >= 8 and v < v7 then v else 0);
def v9 = HighestAll( if qty >= 9 and v < v8 then v else 0);
def v10 = HighestAll( if qty >= 10 and v < v9 then v else 0);

def x1 = if v == v1 then 1 else 0;
def x2 = if v == v2 then 1 else 0;
def x3 = if v == v3 then 1 else 0;
def x4 = if v == v4 then 1 else 0;
def x5 = if v == v5 then 1 else 0;
def x6 = if v == v6 then 1 else 0;
def x7 = if v == v7 then 1 else 0;
def x8 = if v == v8 then 1 else 0;
def x9 = if v == v9 then 1 else 0;
def x10 = if v == v10 then 1 else 0;

def bars = (x1 or x2 or x3 or x4 or x5 or x6 or x7 or x8 or x9 or x10);

#plot z = v;
#z.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
#z.AssignValueColor(if bars then Color.GREEN else Color.GRAY);

AssignPriceColor(if bars then color.violet else color.current);
#
 
Thanks for the script above, really helpful.

I need one more favor, can I put a time filter to show this only between 10:00 AM and 3:30 PM for the current trading day? Not sure if this is even possible.
 
Could you have the script plot lines on the high and low of the candles associated with the high volume similar to support and resistance, please
 
Could you have the script plot lines on the high and low of the candles associated with the high volume similar to support and resistance, please


this will draw horizontal lines, on up to 10 bars, that correspond to the 10 highest volume bars.
can choose how many pairs of lines to draw , 0 to 10.


Code:
#volbars_top10_upper_lines

#volbars_top10
#https://usethinkscript.com/threads/color-the-10-highest-volume-bars-for-thinkorswim.10440/
#Indicators Custom 
#color the 10 highest volume bars For ThinkOrSwim

# top10_vol_bars_01
# color the top 10 vol bars
#declare lower;

def na = Double.NaN;
def bn = BarNumber();

def v = volume;
# use highestall x times

input bar_lines = 10;

def v1 = highestall(v);
def v2 = highestall(if v < v1 then v else 0);
def v3 = highestall(if v < v2 then v else 0);
def v4 = highestall(if v < v3 then v else 0);
def v5 = highestall(if v < v4 then v else 0);
def v6 = highestall(if v < v5 then v else 0);
def v7 = highestall(if v < v6 then v else 0);
def v8 = highestall(if v < v7 then v else 0);
def v9 = highestall(if v < v8 then v else 0);
def v10 = highestall(if v < v9 then v else 0);

def x1 = if v == v1 then 1 else 0;
def x2 = if v == v2 then 1 else 0;
def x3 = if v == v3 then 1 else 0;
def x4 = if v == v4 then 1 else 0;
def x5 = if v == v5 then 1 else 0;
def x6 = if v == v6 then 1 else 0;
def x7 = if v == v7 then 1 else 0;
def x8 = if v == v8 then 1 else 0;
def x9 = if v == v9 then 1 else 0;
def x10 = if v == v10 then 1 else 0;

def bars = (x1 or x2 or x3 or x4 or x5 or x6 or x7 or x8 or x9 or x10);

#plot z = v;
#z.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
#z.AssignValueColor(if bars then color.green else color.gray);
#

#def big = 99999;
plot zhi01 = if bar_lines < 1 then na else highestall(if x1 then high else 0);
plot zlo01 = if bar_lines < 1 then na else highestall(if x1 then low else 0);

plot zhi02 = if bar_lines < 2 then na else highestall(if x2 then high else 0);
plot zlo02 = if bar_lines < 2 then na else highestall(if x2 then low else 0);

plot zhi03 = if bar_lines < 3 then na else highestall(if x3 then high else 0);
plot zlo03 = if bar_lines < 3 then na else highestall(if x3 then low else 0);

plot zhi04 = if bar_lines < 4 then na else highestall(if x4 then high else 0);
plot zlo04 = if bar_lines < 4 then na else highestall(if x4 then low else 0);

plot zhi05 = if bar_lines < 5 then na else highestall(if x5 then high else 0);
plot zlo05 = if bar_lines < 5 then na else highestall(if x5 then low else 0);

plot zhi06 = if bar_lines < 6 then na else highestall(if x6 then high else 0);
plot zlo06 = if bar_lines < 6 then na else highestall(if x6 then low else 0);

plot zhi07 = if bar_lines < 7 then na else highestall(if x7 then high else 0);
plot zlo07 = if bar_lines < 7 then na else highestall(if x7 then low else 0);

plot zhi08 = if bar_lines < 8 then na else highestall(if x7 then high else 0);
plot zlo08 = if bar_lines < 8 then na else highestall(if x7 then low else 0);

plot zhi09 = if bar_lines < 9 then na else highestall(if x7 then high else 0);
plot zlo09 = if bar_lines < 9 then na else highestall(if x7 then low else 0);

plot zhi10 = if bar_lines < 10 then na else highestall(if x7 then high else 0);
plot zlo10 = if bar_lines < 10 then na else highestall(if x7 then low else 0);

zhi01.SetDefaultColor(getcolor(0));
zhi01.setlineweight(1);
zhi01.hidebubble();
zlo01.SetDefaultColor(getcolor(0));
zlo01.setlineweight(1);
zlo01.hidebubble();

zhi02.SetDefaultColor(getcolor(1));
zhi02.setlineweight(1);
zhi02.hidebubble();
zlo02.SetDefaultColor(getcolor(1));
zlo02.setlineweight(1);
zlo02.hidebubble();

zhi03.SetDefaultColor(getcolor(2));
zhi03.setlineweight(1);
zhi03.hidebubble();
zlo03.SetDefaultColor(getcolor(2));
zlo03.setlineweight(1);
zlo03.hidebubble();

zhi04.SetDefaultColor(getcolor(3));
zhi04.setlineweight(1);
zhi04.hidebubble();
zlo04.SetDefaultColor(getcolor(3));
zlo04.setlineweight(1);
zlo04.hidebubble();

zhi05.SetDefaultColor(getcolor(4));
zhi05.setlineweight(1);
zhi05.hidebubble();
zlo05.SetDefaultColor(getcolor(4));
zlo05.setlineweight(1);
zlo05.hidebubble();

zhi06.SetDefaultColor(getcolor(5));
zhi06.setlineweight(1);
zhi06.hidebubble();
zlo06.SetDefaultColor(getcolor(5));
zlo06.setlineweight(1);
zlo06.hidebubble();

zhi07.SetDefaultColor(getcolor(6));
zhi07.setlineweight(1);
zhi07.hidebubble();
zlo07.SetDefaultColor(getcolor(6));
zlo07.setlineweight(1);
zlo07.hidebubble();

zhi08.SetDefaultColor(getcolor(7));
zhi08.setlineweight(1);
zhi08.hidebubble();
zlo08.SetDefaultColor(getcolor(7));
zlo08.setlineweight(1);
zlo08.hidebubble();

zhi09.SetDefaultColor(getcolor(8));
zhi09.setlineweight(1);
zhi09.hidebubble();
zlo09.SetDefaultColor(getcolor(8));
zlo09.setlineweight(1);
zlo09.hidebubble();

zhi10.SetDefaultColor(getcolor(9));
zhi10.setlineweight(1);
zhi10.hidebubble();
zlo10.SetDefaultColor(getcolor(9));
zlo10.setlineweight(1);
zlo10.hidebubble();
#
 

Attachments

  • img1-upper.JPG
    img1-upper.JPG
    161 KB · Views: 90
Thanks for the script above, really helpful.

I need one more favor, can I put a time filter to show this only between 10:00 AM and 3:30 PM for the current trading day? Not sure if this is even possible.

this allows user to pick a time period to enable calculating highest volume bars
default,
input start = 1000;
input end = 1530;
period may be off an hour or 2,... depending on time zone, and it's late and i'm tired....

Code:
#volbars_top10_period

#PAYtience
#6
#Thanks for the script above, really helpful.

#I need one more favor, can I put a time filter to show this only between 10:00 AM and 3:30 PM for the current trading day? Not sure if this is even possible.

#volbars_top10
#https://usethinkscript.com/threads/color-the-10-highest-volume-bars-for-thinkorswim.10440/

# top10_vol_bars_01
# color the top 10 vol bars

declare lower;

def na = Double.NaN;
def bn = BarNumber();
def v = volume;
# use highestall x times

input start = 1000;
input end = 1530;
def period = (secondsfromtime(start) >= 0 and secondstilltime(end) > 0);


def v1 = highestall( v );
def v2 = highestall( if v < v1 and period then v else 0);
def v3 = highestall( if v < v2 and period then v else 0);
def v4 = highestall( if v < v3 and period then v else 0);
def v5 = highestall( if v < v4 and period then v else 0);
def v6 = highestall( if v < v5 and period then v else 0);
def v7 = highestall( if v < v6 and period then v else 0);
def v8 = highestall( if v < v7 and period then v else 0);
def v9 = highestall( if v < v8 and period then v else 0);
def v10 = highestall( if v < v9 and period then v else 0);

def x1 = if v == v1 then 1 else 0;
def x2 = if v == v2 then 1 else 0;
def x3 = if v == v3 then 1 else 0;
def x4 = if v == v4 then 1 else 0;
def x5 = if v == v5 then 1 else 0;
def x6 = if v == v6 then 1 else 0;
def x7 = if v == v7 then 1 else 0;
def x8 = if v == v8 then 1 else 0;
def x9 = if v == v9 then 1 else 0;
def x10 = if v == v10 then 1 else 0;

def bars = (x1 or x2 or x3 or x4 or x5 or x6 or x7 or x8 or x9 or x10);
 
plot z = v;
z.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
z.AssignValueColor(if bars then color.green else color.gray);
#

top , normal study in post #1
bottom , modified to find highest bars within a time period
 

Attachments

  • post6-period-img1.JPG
    post6-period-img1.JPG
    41.2 KB · Views: 67
I've modified the code to change the top volume candles to be red or green depending of bear or bullish.
This is with Equivolume candles on to make it so you can see the volume better.







Code:
def na = Double.NaN;
def bn = BarNumber();

def v = volume;

# Highest volume bars
def v1 = highestall(v);
def v2 = highestall(if v < v1 then v else 0);
def v3 = highestall(if v < v2 then v else 0);
def v4 = highestall(if v < v3 then v else 0);
def v5 = highestall(if v < v4 then v else 0);
def v6 = highestall(if v < v5 then v else 0);
def v7 = highestall(if v < v6 then v else 0);
def v8 = highestall(if v < v7 then v else 0);
def v9 = highestall(if v < v8 then v else 0);
def v10 = highestall(if v < v9 then v else 0);

def x1 = if v == v1 then 1 else 0;
def x2 = if v == v2 then 1 else 0;
def x3 = if v == v3 then 1 else 0;
def x4 = if v == v4 then 1 else 0;
def x5 = if v == v5 then 1 else 0;
def x6 = if v == v6 then 1 else 0;
def x7 = if v == v7 then 1 else 0;
def x8 = if v == v8 then 1 else 0;
def x9 = if v == v9 then 1 else 0;
def x10 = if v == v10 then 1 else 0;

def bars = x1 or x2 or x3 or x4 or x5 or x6 or x7 or x8 or x9 or x10;

# Market direction
def bullish = close > open;
def bearish = close < open;

# Assign color based on condition
plot z = v;
z.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

# Due to the script's restrictions, we'll adjust the color assignment logic
z.AssignValueColor(if bars then if bullish then Color.GREEN else Color.RED else Color.GRAY);
 

Attachments

  • xvcvcxv.png
    xvcvcxv.png
    149.2 KB · Views: 64

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