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.
 

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

Thanks Ben, those are good for other purposes, but I think what I'd like is not possible in ToS. I want to be able to click on a specific tick/bar then click on another bar to get the count of bars between the two points. When I identify a reversal I like to count the bars between the previous peaks and troughs to get a determination of the time value involved for average of how long it takes it to make it near the previous peaks. To let you know how bad I am ToS coding I tried to just put the 9-EMA code from one of your other moving averages codes into its own separate code/label and it botched it up. I can shoot, move, & communicate, but I can't code worth a crap.
 
Something like this?

LQ35M23.png


You select a starting point and an ending point, it will then count how many bars.

I did it through the Trendline drawing tool in ToS

Qy7Va9q.png
 
That will work as a work around. I used to use Esignal and you could just click on the starting point and as you moved your mouse left or right it would count the bars. Still trying to figure out code for putting the 9-EMA in a label with the color green. I tried extracting it out of one of your other codes, but when I did it, it had errors and didn't work.
 
i am trying to create a code that would start back a certain number(whatever number i choose) of bars from the current bar, would anyone be so kind to know how to write that?
 
Is there a quick way to measure the percentage change between 2 price points on a chart.
Example: Price 1= $10, Price 2= $11;
Can we draw a %age line betweeen the 2 points and TOS should show the %age difference (gain) to be 10%.
 
BenTen - Thanks for the info.

It works when the starting point is away from the left edge. When the starting point is very close to left edge of the chart and you are moving higher, the INFO-BOX disappears.
 
Yes, that would work.

I was running a simple BackTest using basic MA strategy. Wanted to determine to %age gain with BUY-&_HOLD vs the strategy. 1st BUY signal was generated in the 1st few bars.
Is there something similar to EXPANSION AREA for the left side of the chart ?
 
Code:
declare upper;
def GreenCandle = Close>Open;
def RedCandle = Close<Open;
def GreenCount = TOTALSUM(GreenCandle);
def RedCount = TOTALSUM(RedCandle);
AddLabel(yes, "GreenCandle: " + GreenCount, color.GREEN);
AddLabel(yes, "RedCandle: " + RedCount, color.RED);

@germanburrito you can tell it to count a certain amount of bars using SUM, this one only counts back 200 bars

Code:
declare upper;
def GreenCandle = Close>Open;
def RedCandle = Close<Open;
def GreenCount = SUM(GreenCandle,200);
def RedCount = SUM(RedCandle,200);
AddLabel(yes, "GreenCandle: " + GreenCount, color.GREEN);
AddLabel(yes, "RedCandle: " + RedCount, color.RED);
 
I'm new to scripts, not much coding experience... so when I edited it for the total of the red and green candles in a new label, it added it up, however when I manually compare the minutes from the open to what the script populated, it was off by 13. I checked also with the trendline tool and the script is again off by 13 minutes. Is there a way to have a script count how many minutes (bars) it's been since the open? I wanted a quick way to tell how many bars its been since open so when I use the volume scanner to compare current volume to a specific bar ago....I actually wish I could figure out a way to find the average opening hour volume and scan for stocks that is a high percentage above that average volume to see if I can detect where the current action is happening. Any help would be appreciated :)
 
@ideallife2day TOS is very limited with regards to time-based calculations, mainly because time shouldn't be that critical of a component within studies and strategies - price action should be... This causes me to wonder why so many members have such time-based fixations... If time was as important as people think it is, wouldn't you think TOS would have these features built in already...??? It's not like TOS is a new trading platform... Don't take it personal - I just needed to vent because I see way too many requests for counters and timing from members who no little to nothing about programming...
 
@rad14733 I understand price is king but volume helps support and confirm the price action. My thinking wasn't necessarily wanting to see what an average volume is for a particular # of days but more of what's happening during today and that the first hour of trading is usually the heaviest volume of the day. Sometimes you see a spike later on and thought that if I can scan for stocks that has volume that is equal to or greater than the average first hour of the trading day, I may be able to see the stocks where interest is coming back. I was just curious to see if it's a viable concept. The scanner only lets you choose average volume that is greater than # of bars ago. I thought using an average of that time period would be better than randomly choosing a bar that may or may not have adequate representation of the traffic that's showing up in the morning. I'll figure it out at some point.
 
@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...
 
@rad14733 I understand price is king but volume helps support and confirm the price action. My thinking wasn't necessarily wanting to see what an average volume is for a particular # of days but more of what's happening during today and that the first hour of trading is usually the heaviest volume of the day. Sometimes you see a spike later on and thought that if I can scan for stocks that has volume that is equal to or greater than the average first hour of the trading day, I may be able to see the stocks where interest is coming back. I was just curious to see if it's a viable concept. The scanner only lets you choose average volume that is greater than # of bars ago. I thought using an average of that time period would be better than randomly choosing a bar that may or may not have adequate representation of the traffic that's showing up in the morning. I'll figure it out at some point.
i did something like that for someone on here a few days ago. its in this post https://usethinkscript.com/threads/opening-volume-vs-30d-average-volume.4973/page-2
 
@rad14733 no, I get what you're saying... I'm not trying to freeload on anyone else's expertise and ability to grasp this stuff. I didn't just show up today to ask for help, I've been lurking for some time trying to piece stuff together myself by looking through other people's contributions that may be related to what I'm trying to do. BTW @XeoNoX Thanks for the suggestion, I have read that post several times prior and looked over your code trying to figure it out and make it work for what I want, no luck yet. I literally sit here and stare at the screen in a fog like state, coding frustrates me, I can't seem to wrap my head around it. I can think of concepts and ideas of what I want that may improve my odds in trading but thinking of it and translating it into tos code language are two totally different things. Even my husband who's a computer programmer writes his own market analysis program for his own use and doesn't mess with the thinkscripts. But he's a swing trader and doesn't pull intraday data and I'm learning to daytrade. He tries to help me make sense of it but he's got his own ideas he's working on and isn't as familiar as I am using the tos platform, it's mind blowing how many lines of code he writes and tweaks and backtests and it's all time consuming. Working around the tos' limited studies and scanners is forcing me to find other creative ways of doing things. Earlier I downloaded a countup/countdown timer app on my phone to see quickly how many minutes it's been since market open (or other random time) so I can manually input that number into the "bars ago" field in the volume change scan. Every time I run the scan, I have to change the number of bars, hahaha. It's comical and a bit pathetic but it's a kind of workaround as I save that scan and limit the output to 30 to fit into my 30 grid flexible grid. I'm a visual learner so glossing over all the charts allows me to find more decent setups. But it still is random and doesn't solve the problem that I may choose a time bar that isn't representative of the true avg. Maybe I've got nothing here but it just seem like it should be a simple task of calculating the average volume from 9:30 to 10:30 (60m is 30 2m bars) and say from 12:30-2:30 when things seem slow, there must still be some stock with some action because of news or a tweet or report, etc that would spike the volume a bit to mimic the interest of opening hour volume. I want to look for patterns in candidates that have potentially better odds because that's where the action is and I can continue practicing throughout the day. Anyway, thanks for your replies :)
 
@ideallife2day Hang in there. I have learned many TOS error messages on my ThinkScript journey. This forum saved me. And while I still spend large quantities of time staring "at the screen in a fog state"; it does get better.

Learning to trade, learning to code, and trying to develop a strong strategy is a really tall order; you could be setting yourself up for failure. On top of this, bar counting scripts are not beginner scripts. Perhaps using some of the scalping strategies that you can search for in this forum; watch what they do, get to understand how the script functions work. I envy that this is something you can share w/ your spouse. My better half's eyes start to glaze over when I starting waxing on about oscillators :)
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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