Use GetValue() to reference Barnumber based on Date/Time?

RustyKayaker

New member
VIP
For a multi-day, intra-day chart, such as 5-90 day, 5-min to 4-hour chart, I want to start a trendline at a certain Date/Time (associated with a bar start time) and end at another Date/Time.

I’ve done trendlines like this for a single day, such as a 5-min chart. I can control which day (out of the last X days) and which time the plot begins and ends. By referencing the Day and the Session Start time, I convert times to a bar count and count bars based on GetAggregationPeriod(). So, this works whatever bar time increment (aggregation) I choose. The attached chart has a curving trendline on 6/18/26.

I’ve also written code like this for daily charts to increment* the trendline based on calendar days, starting on a particular date, but that results in a big jump on Mondays (and even more on 3-day weekends). This is not good. I am aware of CountTradingDays(fromDate, toDate), but I had trouble calculating a toDate (an input toDate worked, but not a calculated value, even using GetYYYYMMDD()). But, this is not necessary if barnumbers are used.

(*The values are actually a ratio times the beginning value.)

For multi-day, intra-day charts, it seems the best way is to use barnumbers. Then I can calculate an incremental* change per bar and I won’t have to worry about holidays either. I’ve been able to plot simple barnumber() on a lower chart. But, I need to set the start of the trendline to a barnumber to equate to zero for calculation purposes. Conceptually this is easily done by identifying the barnumber of the start Date/Time. But, how to do that?

I have found an example of using GetValue(barnumber(), offset) in
https://usethinkscript.com/threads/xstream-regime-bands-for-thinkorswim.22196/
and an example of GetValue(len[gth]), i) and GetValue(GetTime(), i) in
https://usethinkscript.com/threads/...-relative-volume-indicator.20284/#post-149345

I’m not sure how to create an offset (to find the barnumber) based on an input Date/Time for starting and ending the trendline. So, I need help here. I appreciate anything you can provide. I don’t need the whole code, just the snippet of how to reference the barnumber for a certain date/time similar to those referenced above.
And, this needs to work if I change the chart interval from 90 days to 30 days, which will cause the barnumbers to change, but not the begin and end date/time.

In the attached chart, my end-of-day time is 1400 because I’m in the Mountain Time zone.
TOS_CHART, NDX 5min, 260618.png
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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