# 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

-mashume

Thanks Mashume!

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

All I need is GetTime () or another similar function, counting seconds in real time, that's it.

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

@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
You can, btw, also find me on Discord -- both in the UseThinkScript channels and the B4 channels.

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

-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,
Sound.Ding you can guess at ;-)

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

Mashume[/code]

oops, sorry about that.. did my image not appear correctly?

thanks for that @rad14733 , hope it works now.

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

Thanks Mashume!
Does this work for you? I'm using bar chart and it always show `60,000`. Nothing in real time. Just like you, I really want to access elapsed time on current candle. Please share the code if you can. Much appreciate it. Thanks!

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.

87k+ Posts
328 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?