How to create 20 day average volume column

Scotty123

New member
VIP
I added a column to display the 20 day average volume with the code "plot avg = round(average(volume, 20), 0);".

I want the values to be integers (no decimal points) and no scientific notation for numbers >= 10,000,000, but that is not currently the case.

Also, Ideally I would like each value to be comma separated, but having them sortable is more important.

Can anyone help?

Thanks!
 
Solution
@Scotty123 Unfortunately, you can't have everything you want... Thinkscript simply doesn't have the right Functions to display a number with comma's, no decimal points, and no dollar sign... The available Functions are AsDollars(), AsPercent(), AsPrice(), and AsText()... Those plus the Round() Function are pretty much all we have to work with, aside from Concat()... If you play around with those you should be able to come up with an acceptable solution... TOS doesn't have String Functions other than a few of the ones that I've mentioned...
@Scotty123 Unfortunately, you can't have everything you want... Thinkscript simply doesn't have the right Functions to display a number with comma's, no decimal points, and no dollar sign... The available Functions are AsDollars(), AsPercent(), AsPrice(), and AsText()... Those plus the Round() Function are pretty much all we have to work with, aside from Concat()... If you play around with those you should be able to come up with an acceptable solution... TOS doesn't have String Functions other than a few of the ones that I've mentioned...
 
Solution
Thanks, @rad14733

If I change the code as below, I get everything I want EXCEPT the sort is a string sort, not a numeric sort.

Not sure why AddLabel adds the commas, but it does.

def avgvol = Round(average(volume, 20), 0);
AddLabel(yes, avgvol);
plot out = avgvol;
 
Last edited:
Thanks, @rad14733

If I change the code as below, I get everything I want EXCEPT the sort is a string sort, not a numeric sort.

Not sure why AddLabel adds the commas, but it does.

def avgvol = Round(average(volume, 20), 0);
AddLabel(yes, avgvol);
plot out = avgvol;

Hey, give it a whirl and see how that simple solution works for you... Simpler is better... All we can do is experiment to get as close to what we want that also works reliably... I tested it and it seems to be a viable solution... (y)
 
Thanks, @rad14733

If I change the code as below, I get everything I want EXCEPT the sort is a string sort, not a numeric sort.

Not sure why AddLabel adds the commas, but it does.

def avgvol = Round(average(volume, 20), 0);
AddLabel(yes, avgvol);
plot out = avgvol;

you only need 1 output function in a column, plot or addlabel

a link to a couple studies that add characters in front of data, so text sorting works like number sorting
https://usethinkscript.com/threads/combine-plot-and-round.16694/#post-132761
 

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