Time Difference Between Current and Last Candle (500 Tick Candles) - GetTime()

frednam5

New member
Hi Guys,

How do you plot time difference (ideally in milliseconds) between current and last candle?
I'm using Tick Chart (500 ticks)

There is GetTime() but I don't know how to code it.

Thank you,

Fred
 
One option for you:
This one is really raw, and gives you the time delta since the last candle.
Code:
declare lower;

def t = getTime();

plot delta_t = t - t[1];

hope that helps

Happy Trading,
-mashume
 

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

That code shows that difference but it doesn't update until current bar close...

How can we GetTime() difference between current and last bar in 'real time'?
 
That code shows that difference but it doesn't update until current bar close...

How can we GetTime() difference between current and last bar in 'real time'?
I am aware of being able to do something like declare once_per_bar; but I am unaware of any such declaration to make it constantly update. My guess is that there isn't really a way for us to do that through ToS. I may very well be mistaken, but I'm not sure that what you're after can be done. Most of ToS (and any trading thing for that matter) is built on the idea of a block of some aggregation period, whether in time or trades or range. I am unsure that ToS will allow shorter aggregations on a longer chart (no access to 1m data on 5m chart), but the other way works (5m data on 1m chart). I believe what you're looking for is in a similar boat.

Not the answer you wanted, but we work with what we have
Happy Trading,
mashume
 
It's a shame, cuz that simple tool would allow you to track the frequency or intensity of any indicator measured in seconds, without waiting for the bar close to confirm signals. Just by frequency comparison with the previous bar.
 
I am aware of being able to do something like declare once_per_bar; but I am unaware of any such declaration to make it constantly update. My guess is that there isn't really a way for us to do that through ToS. I may very well be mistaken, but I'm not sure that what you're after can be done. Most of ToS (and any trading thing for that matter) is built on the idea of a block of some aggregation period, whether in time or trades or range. I am unsure that ToS will allow shorter aggregations on a longer chart (no access to 1m data on 5m chart), but the other way works (5m data on 1m chart). I believe what you're looking for is in a similar boat.

Not the answer you wanted, but we work with what we have
Happy Trading,
mashume

@mashume - Completely non-contextual, but just wanted to find a way to msg you to tell you that everything you've created is gold. Pure gold.

Thank you
 
agree with @maxtrader , @mashume code below is brilliant in its sheer simplicity! highly useful.

say, on a side note, speaking of tickcharts - is there a way to set an alert on ToS to sound off when a tickchart candle completes?

One option for you:
This one is really raw, and gives you the time delta since the last candle.
Code:
declare lower;

def t = getTime();

plot delta_t = t - t[1];

hope that helps

Happy Trading,
-mashume
 
agree with @maxtrader , @mashume code below is brilliant in its sheer simplicity! highly useful.

say, on a side note, speaking of tickcharts - is there a way to set an alert on ToS to sound off when a tickchart candle completes?
Perhaps...

If you had some study along the lines of:
Code:
Alert(OPEN >= 0 , Alert.BAR, Sound.Ding);
Open >= 0 should always be true,
Alert.BAR says the alert can sound once per bar,
Sound.Ding you can guess at ;-)

I don't know if that will work, or do anything not annoying.

Happy Trading,
Mashume[/code]
 
thanks for that @rad14733 , hope it works now.

@mashume , any way to resolve the error returned?:

eRX88MA.png
 
To answer the questions about getting the elapsed time, TOS records the bar close time (which is not the same as some other platforms). Because that value is not set in stone until the bar closes, I don't believe it's possible to get elapsed time as the value of GetTime() is essentially like the value of close on the last bar... which is NaN.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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