Create vertical line at X hours ago that works on tick charts- is it possible?

Glefdar

Active member
I normally use a vertical line script to mark the point of 3 hours ago on my charts. I adjust the number of bars back that the vertical line will be painted, based on the aggregation of the candles.

(Eg. if wanting the line to mark one hour ago then it would be 60 bars ago on a 1min chart and 4 bars ago on a 15m chart. Although it might be 61 and 5, because the vertical line appears to the right of the current bar, not the left - I can’t remember offhand if the input for the script needs to be the time back +1 bar because of that, but you get the idea.)

I do this so that I can immediately spot which portion of each chart’s candles corresponds to the candles on the other charts using different periods, without needing to inspect the x-axis time labels of the chart cells. It’s helpful when using a lot of charts having different periods across different flexible grid cells.

However, using an adjustable bars back input or counter for drawing a vertical line X hours ago obviously won’t work on tick charts. Is there a way to do it on tick charts? I think probably so using “secondsfromtime” or something but it’s not clear to me how. Also I am not sure if some time functions might not work on tick charts since they can’t reference secondary periods but maybe that is irrelevant. I think that Welkin’s volume tick projection study draws bars at set time intervals on a tick chart, if I’m not remembering wrong, so an answer/ solution might partly lie there.

I would be very grateful if anyone has a solution for getting a time marker based on X hours ago to work on a tick chart.
 
I normally use a vertical line script to mark the point of 3 hours ago on my charts. I adjust the number of bars back that the vertical line will be painted, based on the aggregation of the candles.

(Eg. if wanting the line to mark one hour ago then it would be 60 bars ago on a 1min chart and 4 bars ago on a 15m chart. Although it might be 61 and 5, because the vertical line appears to the right of the current bar, not the left - I can’t remember offhand if the input for the script needs to be the time back +1 bar because of that, but you get the idea.)

I do this so that I can immediately spot which portion of each chart’s candles corresponds to the candles on the other charts using different periods, without needing to inspect the x-axis time labels of the chart cells. It’s helpful when using a lot of charts having different periods across different flexible grid cells.

However, using an adjustable bars back input or counter for drawing a vertical line X hours ago obviously won’t work on tick charts. Is there a way to do it on tick charts? I think probably so using “secondsfromtime” or something but it’s not clear to me how. Also I am not sure if some time functions might not work on tick charts since they can’t reference secondary periods but maybe that is irrelevant. I think that Welkin’s volume tick projection study draws bars at set time intervals on a tick chart, if I’m not remembering wrong, so an answer/ solution might partly lie there.

I would be very grateful if anyone has a solution for getting a time marker based on X hours ago to work on a tick chart.

To clarify this is the post with Welkin’s code that can access seconds on a tick chart, which is what made me think it’s possible to do what I’m wondering about:

https://usethinkscript.com/threads/accessing-seconds-from-1min-chart-thinkorswim.3516/#post-32655
 
To clarify this is the post with Welkin’s code that can access seconds on a tick chart, which is what made me think it’s possible to do what I’m wondering about:

https://usethinkscript.com/threads/accessing-seconds-from-1min-chart-thinkorswim.3516/#post-32655

This might work

Screenshot 2023-09-02 102906.png
Code:
#Vericalline_x_hoursback_TickChart_using_Gettime

input hoursback = 3;
input test = yes;
def hour   = 3600000;
def lastbartime = if !IsNaN(close) and IsNaN(close[-1]) then GetTime() else Double.NaN;

#Current Bar
AddVerticalLine(GetTime() >= HighestAll(lastbartime) and GetTime()[1] < HighestAll(lastbartime), " ", Color.WHITE);

#Bar x_hoursback from Current Bar
AddVerticalLine(GetTime()[1] < HighestAll(lastbartime - hour * hoursback) and GetTime() >= HighestAll(lastbartime - hour * hoursback), " ", Color.WHITE);

#Test
AddChartBubble(test and (GetTime() >= HighestAll(lastbartime) and GetTime()[1] < HighestAll(lastbartime) or GetTime()[1] < HighestAll(lastbartime - hour * hoursback) and GetTime() >= HighestAll(lastbartime - hour * hoursback)), high, GetTime());
 
This might work

Wanted to let you know that I just tried your solution and it works great, thank you!

I added "declare once_per_bar" to potentially improve the efficiency as well and have used it to replace my version which required manually counting back bars, since that would not always work correctly if bars were missing on a time chart for any reason such as low liquidity.
 
Last edited:
Wanted to let you know that I just tried your solution and it works great, thank you!

I added "declare once_per_bar" to potentially improve the efficiency as well and have used it to replace my version which required manually counting back bars, since that would not always work correctly if bars were missing on a time chart for any reason such as low liquidity.

"declare once_per_bar" is not a working ToS function
read more:
https://usethinkscript.com/threads/...in-real-time-in-thinkorswim.8794/#post-120999
 
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
443 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