Anybody know how to create a bar counter on ToS?

FreefallJM03

Member
VIP
Anybody know how to create a bar counter on ToS? I want something that I can count from a specific bar to another specific bar.
 
@ideallife2day Here you go, the average volume of a specified time frame: NOTE you have to chose how much you want to divide the volume by manually in the input field.

Example:

In the case below its from 9:30-10:30 (1hour). Chart set to 30 min time frame, so that's 2 bars in the first hour... so the "number to divide by" is 2. I can probably automate that part but it would take me longer to code.

Code:
declare lower;
#Volume at Specified Time Interval averaged by inputted amount
###Please Keep Code Intact if you share
### By XeoNoX via usethinkscript.com

input StartTime = 0930;
input Endtime = 1030;
##Set Time_Agreggration to match chart timeframe
input Number_to_Average_By = 2;
def na = Double.NaN;
def today=getday()==getlastDay();
def SelectedTime = if GetLastDay() == GetDay() and SecondsFromTime(StartTime) >= 0 and SecondsFromTime(Endtime) < 0 then 1 else 0;
def Selected_Volume = TotalSum(if SelectedTime  then volume else 0);
def avg = round((Selected_Volume/Number_to_Average_By),0);


AddLabel (yes,"Total Volume: " + Selected_Volume + "     " + Number_to_Average_By + "Bar Avg: " + avg);
 
@MerryDay Thanks for the encouragement and suggestions! I do try to understand the scripts and attempt to edit them to see if they produce a different result I was looking for. It's a slow process as my goal right now is to work on my trading of one pattern I like so now I can't stop seeing that pattern everywhere and I try to predict the actions of the pattern, the scripts are just tidbits of info that can hopefully add to my confirmations. I wasn't always interested in trading, he would talk to me about stocks when we were dating and I'd listen cuz it seemed to be something he's passionate about and have dedicated the last 20 years trying to perfect. Trading is hard, there're soooo many variables to consider that's conditioning you to react a different way. Every trade I get into leaves an impression of what I did right or wrong and reviewing my trades allows me to improve. I figure if I started to learn trading, I can relate to him....or at least be familiar with the terminology to have a conversation, haha. We still have a lot of different interests but at least trading is something we can share....plus, when I get better, I can help us make $$$ to pay bills :D
 
@ideallife2day There's always a work-around or minor change in logic... I'd just like to see more members learning to code and less requests for others to do the coding at their whims... I've honestly never seen a forum where so many feel it's ok to just keep asking of others and never learning to help themselves and I've belonged to quite a few forums over the years... Back when I had an open source project forum we'd help those willing to help themselves - unless someone was willing to pay for code... I made a lot of money coding custom modules for large web development projects for other developers and site owners back then... But I still enjoyed seeing members learn to code so they could help themselves... But I digress...
i did the very same thing...i came here wanting something, hoping coders would help me...in hindsight they helped me by interacting, responding within the scope of the project, and generally not being huge jerks...which gave me that extra little nudge to keep going...im able to do just a tiny bit more on my own thanx to you guys. For anyone in a similar position, no real background in coding or scripts, we will have to stand on our own two feet...man up and grow, learn, you can do it. Just keep things reasonable at first.
 
I am trying to create a simple fibonacci retracement indicator as an exercise. The first task is to find the prices of two points A and B which are determined by two consecutive price bar selections. The first mouse click on a price chart will be for point A then next click is for point B. I am new to thinkScript. I could not find a solution after googling and reading tutorials. Can anyone help?

Thanks!
 
I am trying to create a simple fibonacci retracement indicator as an exercise. The first task is to find the prices of two points A and B which are determined by two consecutive price bar selections. The first mouse click on a price chart will be for point A then next click is for point B. I am new to thinkScript. I could not find a solution after googling and reading tutorials. Can anyone help?

Thanks!
Any indicator or study you make will have value resulted from your study and can not be changed with a click of the mouse. There are drawing tools that you can point and click and get values. https://www.youtube.com/results?search_query=thinkorswim+drawing+tools
 
Thank you both for the reply. I probably did not make my question clear. I am not trying to read the price on a chart or modify any price. My goal is to write a script to draw Fibonacci retracement (or voodoo lines). ThinkOrSwim provided a Fibonacci retracement tool. With this tool you could select two price points with mouse clicks. I would like to recreate it in my own script. Is there anything to get a price like "def startingPrice = GetPrice(first mouse click); ..."?
 
Last edited:
@rad14733 Thank you for the suggestion. I have access to Fib tools in TOS. The exercise was trying to grab a price at the bar selected by a mouse click. If this were possible I could have coded tools like Voodoo lines.
 
@rad14733 Thank you for the suggestion. I have access to Fib tools in TOS. The exercise was trying to grab a price at the bar selected by a mouse click. If this were possible I could have coded tools like Voodoo lines.

We are unable to interactively feed mouse clicks into a study... Its either use a coded study or use Drawing Tools...
 
@geremyh

Thank you for sharing the Green/Red Candle study!

Is there a way to edit the code so it shows how many consecutive green/red candles there have been?

So, like if there was 3 consecutive red candles , it would say Red 3 Green 0, etc.

This is a custom study I found that shows Z-score volume. Ultimately what I am looking to do is have a chart label that shows me "Green 3 Red 0" based on how many consecutive green or red bars there are.

Code:
#Computes and plots the Zscore
#Provided courtesy of ThetaTrend.com
#Feel free to share the code with a link back to thetatrend.com

declare lower;

input price = close;
input length = 20;
input ZavgLength = 20;

#Initialize values
def oneSD = stdev(price,length);
def avgClose = simpleMovingAvg(price,length);
def ofoneSD = oneSD*price[1];
def Zscorevalue = ((price-avgClose)/oneSD);
def avgZv = average(Zscorevalue,20);

#Compute and plot Z-Score
plot Zscore = ((price-avgClose)/oneSD);
Zscore.setPaintingStrategy(paintingStrategy.HISTOGRAM);
Zscore.setLineWeight(2);
Zscore.assignValueColor(if Zscore > 0 then color.green else color.red);

plot avgZscore = average(Zscorevalue,ZavgLength);
avgZscore.setPaintingStrategy(paintingStrategy.LINE);

#This is an optional plot that will display the momentum of the Z-Score average
#plot momZAvg = (avgZv-avgZv[5]);

#Plot zero line and extreme bands
plot zero = 0;
plot two = 2;
plot negtwo = -2;
plot three = 3;
plot negthree = -3;

zero.setDefaultColor(color.black);
 
Last edited:
@ProfessorAR15 sure, you'd use if statement...I'm not a coder, i just tried really hard to understand just enough of what i wanted and barely got by...we may be able to do 'if last candle is red then start counting red' and vice versa, 'if green candle then start counting green'. then when it switches from the candle color you're counting it would start over. that's what i would use as the logic in the counter. guess this would improve my coding knowledge so i'll give it a shot if you promise to also try to learn more about this stuff
 
sure, you'd use if statement...im not a coder, i just tried really hard to understand just enough of what i wanted and barely got by...we may be able to do 'if last candle is red then start counting red' and vice versa, 'if green candle then start counting green'. then when it switches from the candle color you're counting it would start over. that's what i would use as the logic in the counter. guess this would improve my coding knowledge so i'll give it a shot if you promise to also try to learn more about this stuff
Yes, I try to figure it out before coming here. Heard from several other members here, not trying to look for a free handout. I donated to a food ****ry for help the last time, I am NOT looking for any free handouts.

I figured it would be an if statement. What I am trying to learn is what words/code are already built in to TOS ya know. Like obviously I cant just say, "Count sum of consecutive green candles". I am trying to make it as basic as possible. I have been in the editor looking at what words/phrases I can say.
 
Last edited:
Yes, I try to figure it out before coming here. Heard from several other members here, not trying to look for a free handout. I donated to a food ****ry for help the last time, I am NOT looking for any free handouts.

I figured it would be an if statement. What I am trying to learn is what words/code are already built in to TOS ya know. Like obviously I cant just say, "Count sum of consecutive green candles". I am trying to make it as basic as possible. I have been in the editor looking at what words/phrases I can say.
you can use this as a guide and should be able to accomplish what you are trying to do

https://usethinkscript.com/threads/...ive-patterns-on-chart-or-specified-time.5496/
 
Is there a way to make a script that will show percentage increase in volume over the previous bar? For example if the first bar shows 5000 volume and the next bar shows 7500 is there a way to make a bubble that shows it increased 50% over the previous bar and will continue rolling over from each successive bar? I do a lot of trading off volume and have to eyeball or factor in my head if something is increasing substantially. Also, having it match red/green respectively on the price/volume bars red for negative and green for positive obviously.
 
Is there a way to make a script that will show percentage increase in volume over the previous bar? For example if the first bar shows 5000 volume and the next bar shows 7500 is there a way to make a bubble that shows it increased 50% over the previous bar and will continue rolling over from each successive bar? I do a lot of trading off volume and have to eyeball or factor in my head if something is increasing substantially. Also, having it match red/green respectively on the price/volume bars red for negative and green for positive obviously.
Volume percent change from previous bar as label and chart bubble
Code:
declare lower;
#volume percent change from previous bar as label and chart bubble
#By XeoNoX via request via usethinkscript.com
input show_label = yes;
plot vol=  volume;
vol.SetPaintingStrategy( PaintingStrategy.HISTOGRAM );
def volchange = ((volume-volume[1])/volume[1])*100;
AddChartBubble(volchange, volume, round(volchange,2) +"%");
AddLabel (show_label, "Vol Change" +  round(volchange,2) + "%"  );
 
Last edited:

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